1. Given the base class header file point.h
// Point Class Header File
// Filename: point.h
#ifndef POINT_H
#define POINT_H
class point
{
public:
point(double init_x = 0.0, double init_y = 0.0); // sets x to init_x and y to init_y
// or uses the default values
void setPoint(double init_x, double init_y); // sets x to init_x and y to init_y
void print() const; // prints a point in the form (x, y) with a precision of 1
double getX() const; // returns the value of x
double getY() const; // returns the value of y
private:
double x;
double y;
};
#endif
2. Write the corresponding implementation file point.cpp
3. The derived class circle will inherit from the point class. You are given the header file circle.h
// Class Circle Header File
// Filename: circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include "point.h"
class circle: public point
{
public:
circle(double init_x = 0.0, double init_y = 0.0, double r = 0.0);
// uses default parameters to set x to init_x, y to init_y and radius to r
void print() const;
// prints the following information about a circle:
// center point, radius, circumference, area with a precision of 1
void setRadius(double r);
// sets radius to r
double getRadius() const;
// returns radius
double getCircumference() const;
// returns circumference (2 * radius * 3.14159)
double getArea() const;
// returns area (3.14159 * radius2)
private:
double radius;
};
#endif
4. Write the corresponding implementation file circle.cpp
5. Write the driver program lastname7.cpp to accomplish the following:
Create object circle1 using the constructor with three parameters, setting x to 1, y to 2, and radius to 3
Create object circle2 using the default constructor
Print circle1 Set circle2 as follows: x to 4, y to 5 and radius to 6 (this will require two set functions)
Print circle2
I have the two header files complete along with their implementation files. The driver program is working within reason. My issue is the last two lines I've bolded and italicized in the quoted text. I cannot get the radius to output for circle2. The point outputs, but how do I get circle2 to accept the radius of six? Any tips?
#include <iostream>
#include "point.h"
#include "circle.h"
usingnamespace std;
int main()
{
circle circle1(1, 2, 3);
circle circle2;
cout << "Circle 1 should be (1, 2) and have a radius of 3. Circle 1 is as follows: " << endl;
circle1.print();
cout << endl;
circle2.setPoint(4, 5);
circle2.setRadius(6);
cout << "Circle 2 should be (4, 5) and have a radius of 6. Circle 2 is as follows: " << endl;
circle2.print();
cout << endl;
return(0);
}
My output:
Circle 1 should be (1, 2) and have a radius of 3. Circle 1 is as follows:
The center point is (1.0, 2.0)
The radius is: 3.0
The circumference is: 18.8
The area is: 28.3
Circle 2 should be (4, 5) and have a radius of 6. Circle 2 is as follows:
The center point is (4.0, 5.0)
The radius is: 0.0
The circumference is: 0.0
The area is: 0.0
Press any key to continue . . .
I understand - I didn't want to fill up with a bunch of code so I tested the waters to see if anyone could decipher anything from that. I assumed more would be needed but I was waiting heh... :-)
I'm going to include here the circle.cpp file (which has the setRadius function and coincides with circle.h) and the point.cpp file (as a back up).