I am confused of what this means class circle { private: double xCoordinate; dou
ID: 3684049 • Letter: I
Question
I am confused of what this means
class circle
{
private:
double xCoordinate;
double yCoordinate;
double radius;
public:
circle();
circle(double, double, double);
void printInfo() const;
double area();
};
class cylinder:public circle
{
private:
double height;
public:
cylinder();
cylinder(double, double, double, double);
void printInfo() const;
double area();
double volume();
};
What are the headers of the default constructor of the circle and cylinder classes?
What are the headers of the constructor with parameters of circle and cylinder classes?
Which member functions of cylinder class overrides base circle classes member functions?
Write implementation two constructors and two member functions of the circle class given above.
Write implementation two constructors and three member functions of the cylinder class given above.
In your main program, create two objects of circle class called c1 and c2 and two objects of cylinder class called cy1 and cy2, as below. Print info for c1, c2, cy1, and cy2.
class circle
{
private:
double xCoordinate;
double yCoordinate;
double radius;
public:
circle();
circle(double, double, double);
void printInfo() const;
double area();
};
class cylinder:public circle
{
private:
double height;
public:
cylinder();
cylinder(double, double, double, double);
void printInfo() const;
double area();
double volume();
};
Explanation / Answer
What are the headers of the default constructor of the circle and cylinder classes?
Headers for Circle default constructor:
circle();
This is default constructor of Circle class
cylinder();
This is default constructor of Cylinder class
What are the headers of the constructor with parameters of circle and cylinder classes?
circle(double, double, double);
this is header of costructor of circle class with parameters
cylinder(double, double, double, double);
this is header of costructor of cylinder class with parameters
Which member functions of cylinder class overrides base circle classes member functions?
void printInfo() const;
double area();
These functions are also present in base class with same name and signature. So child class will over rite
Write implementation two constructors and two member functions of the circle class given above.
circle()
{
double xCoordinate=0.0;
double yCoordinate=0.0;
double radius=0.0;
}
circle(double x, double y, double z)
{
double xCoordinate=x;
double yCoordinate=y;
double radius=z;
}
void printInfo() const
{
System.our.println("XCoordinate "+xCoordinate+" YCoordicate "+yCoordinate+" Radius"+radius);
}
double area()
{
return 3.14*radius*radius;
}
Write implementation two constructors and three member functions of the cylinder class given above.
cylinder()
{
double xCoordinate=0.0;
double yCoordinate=0.0;
double radius=0.0;
double height=0.0;
}
cylinder(double x, double y, double z,double h)
{
double xCoordinate=x;
double yCoordinate=y;
double radius=z;
double height=h;
}
void printInfo() const
{
System.our.println("XCoordinate "+xCoordinate+" YCoordicate "+yCoordinate+" Radius"+radius+"Height "+height);
}
double area() //2r2 + 2rh
{
return (2*3.14*radius*radius+2*3.14*radius*height);
}
double volume() //r2h
{
return 3.14*radius*radius*h;
}
In your main program, create two objects of circle class called c1 and c2 and two objects of cylinder class called cy1 and cy2, as below. Print info for c1, c2, cy1, and cy2.
public static void main(String[] args)
{
circle c1=new circle();
circle c2 = new circle(10,20,2);
cylinder cy1 = new cylinder (10,20,2,2);
cylinder cy2 = new cylinder ();
c1.printInfo();
c2.printInfo();
cy1.printInfo();
cy2.printInfo();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.