Link to home
Start Free TrialLog in
Avatar of OCU
OCU

asked on

iNHERITANCE

Need help with this lab,
here is my code
i am getting this error message
when i use this piece of code

dim circle as new CCircle

Error      1      Argument not specified for parameter 'Rad_val' of 'Public Sub New(X_val As Integer, Y_val As Integer, Rad_val As Integer)'.      

Error      2      Argument not specified for parameter 'X_val' of 'Public Sub New(X_val As Integer, Y_val As Integer, Rad_val As Integer)'.

Error      3      Argument not specified for parameter 'Y_val' of 'Public Sub New(X_val As Integer, Y_val As Integer, Rad_val As Integer)'.

I am new in this oop . any help will be appreciated.
my teacher told me  to test both clasess.
what changes Do I need to make in order to make this lab to work...
thanks



'Create a class called CPoint that includes the following:
Public Class CPoint
#Region "Instance Variables"
    '"    Private integers mX and mY
    Private_X As Integer
   Private _Y As Integer
#End Region
 
#Region "Constructors"
    '    A default constructor that sets mX and mY to zero
    Public Sub New()
        _X = 0
        _Y = 0
    End Sub
    '"    A constructor that allows input for mX and mY
    Public Sub New(ByVal X_value As Integer, _
         ByVal Y_value As Integer)
 
        _X = X_value
        _Y = Y_value
    End Sub
#End Region
 
#Region "Properties"
    '    Public properties X   that returns mX
    Public Property X() As Integer
        Get
            Return _X
        End Get
 
        Set(ByVal Value As Integer)
            _X = Value
        End Set
    End Property
    'Public properties Y  that returns mY
    Public Property Y() As Integer
        Get
            Return _Y
        End Get
 
        Set(ByVal Value As Integer)
            _Y = Value
        End Set
    End Property
    'A Public Overridable ReadOnly Property Area that return 0 as a double
    Public ReadOnly Property Area() As Double
        Get
            Return 0
        End Get
    End Property
    '"    A Public ReadOnly Property Diameter that returns 0 as a double
    Public ReadOnly Property Diameter() As Double
        Get
            Return 0
        End Get
    End Property
 
#End Region
 
 
 
End Class
 
  this is the child class
 
'Create a class called CCircle that inherits CPoint that includes the following
Public Class CCircle
    Inherits CPoint
 
#Region "Instance Variables"
    '    Private double mRadius
    Private _Radius As Double
    Private _Area As Double
    Private _Circunference As Double
    Private _Diameter As Double
#End Region
 
#Region "Constructors"
    '    A constructor that accepts an X, Y and radius Value
    Public Sub New(ByVal X_val As Integer, ByVal Y_val As Integer, _
         ByVal Rad_val As Integer)
        X_val = _X
        Rad_val = _Radius
        Y_val = _Y
    End Sub
#End Region
 
 
 
#Region "Properties"
    '    A Radius Property
    Public Property Radius() As Double
        Get
            Return _Radius
        End Get
 
        Set(ByVal Value As Double)
            _Radius = Value
        End Set
    End Property
 
    '    Create Area, Circumference and Diameter Properties
 
    Public Overloads Property Area() As Double
        Get
            Return _Area
        End Get
 
        Set(ByVal Value As Double)
            _Area = Value
        End Set
    End Property
 
 
    Public Property circunference() As Double
        Get
            Return _Circunference
        End Get
 
        Set(ByVal Value As Double)
            _Circunference = Value
        End Set
    End Property
    Public Overloads Property Diameter() As Double
        Get
            Return _Diameter
        End Get
        Set(ByVal value As Double)
            _Diameter = value
        End Set
    End Property
#End Region
    '    Ovveride the ToString Function to return something that looks like Center = [10, 10]; Radius = 20
 
 
#Region "Functions"
    Public Function CalculateDiameter() As Double
        Return Radius * 2
    End Function
 
    Public Function CalculateCircmuference() As Double
        Return CalculateDiameter() * Math.PI
    End Function
 
    Public Function CalculateArea() As Double
        Return Radius * Radius * Math.PI
    End Function
#End Region
 
 
 
 
 
 
    Public Overrides Function ToString() As String
        Return Convert.ToString(X) & ", " & Convert.ToString(Y) & _
         vbNewLine & "Radius = " & _Radius
    End Function
End Class

Open in new window

Avatar of inthecurve
inthecurve
Flag of United States of America image

In the constructor of CCircle, the _X and _Y variables are not accessible in this context because they are 'Private'.  That's the only issue with this code.  Their scope would need to be 'Protected Friend'.
ASKER CERTIFIED SOLUTION
Avatar of jindalankush
jindalankush
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dim circle as new CCircle() should be fine as there is a default constructor which requires no parameters:
Public Sub New()
        _X = 0
        _Y = 0
End Sub
Public Sub New(ByVal X_value As Integer, _
         ByVal Y_value As Integer)
 
        _X = X_value
        _Y = Y_value
End Sub

The errors seems to be coming from the issue that I noted regarding the scope of the variables _X and _Y.
My mistake, jindalankush is correct and not me.  I overlooked the constructor in the CCircle class.