I have created a base class point and a derived class circle. I am to test all the functions in a driver program to make sure everything works then create another derived class cylinder. Before I create cylinder I need to make sure all of my class functions work. I have done that to the exclusion of my get functions. I can't figure out how to call that from main. I can find all kinds of examples on the prototype and definiton, but nothing on the use.
Can anyone help me on this?
pointClass.h
Code:
#ifndef H_point
#define H_point
#include <iostream>
using namespace std;
class pointType
{
public:
pointType();
//default constructor
pointType(int xCoord, int yCoord);
//constructor
void setPoint(int xCoord, int yCoord);
//stores the values of xCoord into x, and yCoord into y
void setX(int xCoord);
//stores the value of xCoord into x and y remains unchanged
void setY(int yCoord);
//x remains unchanged and stores the value of yCoord into y
void getPoint(int & xCoord, int & yCoord);
//returns the value of x into xCoord and y into yCoord
void getX(int & xCoord);
//returns just the value of x into xCoord
void getY(int & xCoord);
//returns just the value of y into yCoord
void printPoint() const;
//prints (x, y)
void printX()const;
//prints just x
void printY()const;
//prints just y
private:
int x;
int y;
};
#endif
pointClass.cpp
Code:
#include "pointClass.h"
pointType::pointType()
{
setPoint(0, 0);
}
pointType::pointType(int xCoord, int yCoord)
{
setPoint(xCoord, yCoord);
}
void pointType::setPoint(int xCoord, int yCoord)
{
x = xCoord;
y = yCoord;
}
void pointType::setX(int xCoord)
{
x = xCoord;
}
void pointType::setY(int yCoord)
{
y = yCoord;
}
void pointType::getPoint(int & xCoord, int & yCoord)
{
xCoord = x;
yCoord = y;
}
void pointType::getX(int & xCoord)
{
xCoord = x;
}
void pointType::getY(int & yCoord)
{
yCoord = y;
}
void pointType::printPoint() const
{
cout << "(" << x << ", " << y << ")" << endl;
}
void pointType::printX() const
{
cout << "The value of x is: " << x << endl;
}
void pointType::printY() const
{
cout << "The value of y is: " << y << endl;
}
circleClass.h
Code:
#ifndef H_circle
#define H_circle
#include <iostream>
//#include <string>
#include <cmath>
#include "pointClass.h"
const double PI = 3.14159;
class circleType: public pointType
{
public:
circleType();
circleType(int xCoord, int yCoord, int radius);
void setRadius(int radius);
void setPointRadius(int xCoord, int yCoord, int radius);
void getRadius(int & radius);
void getPointRadius(int & xCoord, int & yCoord, int & radius);
double calcArea();
double calcCircum();
string WhereAmI(int & xCoord, int & yCoord);
void printRadius() const;
void printArea();
void printCircum();
void printPointRadius() const;
private:
int r;
};
#endif
circleClass.cpp
Code:
#include "pointClass.h"
#include "circleClass.h"
circleType::circleType()
: pointType()
{
r = 0;
}
circleType::circleType(int xCoord, int yCoord, int radius)
: pointType(xCoord, yCoord)
{
r = radius;
}
void circleType::setRadius(int radius)
{
r = radius;
}
void circleType::setPointRadius(int xCoord, int yCoord, int radius)
{
setPoint(xCoord, yCoord);
r = radius;
}
void circleType::getRadius(int & radius)
{
radius = r;
}
void circleType::getPointRadius(int & xCoord, int & yCoord, int & radius)
{
getPoint(xCoord, yCoord);
radius = r;
}
double circleType::calcArea()
{
return (PI * pow(r, 2));
}
double circleType::calcCircum()
{
return (2 * PI * r);
}
void circleType::printRadius() const
{
cout << "The current value of radius is: " << r << endl;
}
void circleType::printArea()
{
cout << "The area of a circle with a radius of "
<< r << " is " << calcArea() << endl;
}
void circleType::printCircum()
{
cout << "The circumference of a circle with a radius of "
<< r << " is " << calcCircum() << endl;
}
void circleType::printPointRadius() const
{
pointType::printPoint();
cout << " and the radius of the circle is " << r << "." << endl;
}
string circleType::WhereAmI(int & xCoord, int & yCoord)
{
getPoint( xCoord, yCoord);
if (xCoord > 0 && yCoord > 0)
return "My Center is in the first quadrant of the cartesian plane.";
else if (xCoord > 0 && yCoord < 0)
return "My Center is in the second quadrant of the cartesian plane.";
else if (xCoord < 0 && yCoord < 0)
return "My Center is in the third quadrant of the cartesian plane.";
else
return "My Center is in the fourth quadrant of the cartesian plane.";
}
and finally my driver program: which is where my hang up seems to be.
Code:
#include "pointClass.h"
#include "circleClass.h"
//to test the pointClass prior to building the circleClass
int main()
{
//operation calls to check the point class
pointType cindyPoint;
cout << "The x and y default values of cindyPoint are: ";
cindyPoint.printPoint();
cindyPoint.setX(19);
cindyPoint.printX();
cout << "The new x and y values of cindyPoint are: ";
cindyPoint.printPoint();
cindyPoint.setY(57);
cindyPoint.printY();
cout << "The x and new y values of cindyPoint are: ";
cindyPoint.printPoint();
cindyPoint.setPoint(20, 07);
cout << "The cindyPoint has been reset to x and y values of: ";
cindyPoint.printPoint();
pointType badPoint;
cout << "A new point in town - badPoint - with x and y default values of: ";
badPoint.printPoint();
badPoint.setX(32);
badPoint.setY(23);
badPoint.printX();
badPoint.printY();
cout << "The new x and y values of badPoint are: ";
badPoint.printPoint();
badPoint.setPoint(-62, -78);
cout << "And again, the x and y values of badPoint are: ";
badPoint.printPoint();
//operation calls to check the circle class
circleType cindyCircle;
cout << "cindyPoint has a new friend in town - cindyCircle.";
cout << "\ncindyCircle has default x and y values of: ";
cindyCircle.printPointRadius();
cindyCircle.setPointRadius(3, 3, 3);
cout << "cindyCircle has reset her values to: ";
cindyCircle.printPointRadius();
cout << "cindyCircle called in some calculating friends to find a size." << endl;
cindyCircle.calcArea();
cindyCircle.printArea();
cindyCircle.calcCircum();
cindyCircle.printCircum();
cindyCircle.WhereAmI();
//cindyCircle.WhereAmI(-3, 3);
//cindyCircle.WhereAmI(-3, -3);
//cindyCircle.WhereAmI(3, -3);
}
Thanks for any input.