I have a 2 part problem.
1) In circleTypeImp.cpp I am being returned incorrect values for circum and area variables. I have tried using both float and double variable type with no luck. Any pointers?
2) I have read over how to derive a class a number of times and tried a bunch of code changes, but I must still be missing something. I want to "derive the class circleType from the class pointType". What I want to accomplish is to call inputPoint (found in pointTypeImp.cpp) from within circleTypeImp.cpp. Can someone show me how to do this? Once I can get one working I can finish implementing the rest of my code.
pointType.h code:
class pointType
{
#ifndef point_test
#define point_test
public:
pointType();
// Default constructor
int inputPoint();
// Input X & Y coordinates for a point
void printXCoordinate(int x);
// Print X coordinate
void printYCoordinate(int Y);
// Print Y coordinate
void printCoordinates(int x, int y);
// Display X & Y coordinates
int x; // Store X coordinate
int y; // Store Y coordinate
private:
int display; // Display method selection
#endif
};
pointTypeImp.cpp code:
#include <iostream>
#include "pointType.h"
using namespace std;
int pointType::inputPoint()
{
cout<<endl<<"Enter the X coordinate: ";
cin>>x;
cout<<endl<<"Enter the Y coordinate: ";
cin>>y;
return x,y;
}
void pointType::printXCoordinate(int x)
{
cout<<endl<<"The X coordinate is: "<<x;
}
void pointType::printYCoordinate(int y)
{
cout<<endl<<"The Y coordinate is: "<<y;
}
void pointType::printCoordinates(int x, int y)
{
cout<<endl<<"The coordinates of the point are: ("<<x<<","<<y<<").";
}
pointType::pointType()
{
}
int main()
{
int display;
pointType myPoint;
myPoint.inputPoint();
cout<<endl<<"Select the method of display.";
cout<<endl<<" 1) Display X coordinate";
cout<<endl<<" 2) Display Y coordinate";
cout<<endl<<" 3) Display BOTH coordinates";
cout<<endl;
cout<<endl<<"Enter your choice of display: ";
cin>>display;
switch(display)
{
case 1: myPoint.printXCoordinate(myPoint.x);
break;
case 2: myPoint.printYCoordinate(myPoint.y);
break;
case 3: myPoint.printCoordinates(myPoint.x,myPoint.y);
break;
default: cout<<endl<<"You must enter either a '1', '2' or a '3'..."<<endl;
}
}
circleType.h code:
class circleType
//class circleType: public pointType
{
public:
circleType();
// Default constructor
int inputRadius();
// Input radius of a circle
float calculateArea(float pi, int radius);
// Calculate circle area
float calculateCircumference(float pi, int radius);
// Calculate circle circumference
void printRadius(int radius);
// Display radius
void printArea(float area);
// Display circle area
void printCircumference(float circum);
//Display circle circumference
int radius; // Store circle radius
float area; // Store circle area
float circum; // Store circle circumference
float pi; // Store Pi
private:
int display; // Display method selection
};
circleTypeImp.cpp code:
#include <iostream>
#include "pointType.h"
#include "circleType.h"
using namespace std;
int circleType::inputRadius()
{
cout<<endl<<"Enter the circle RADIUS: ";
cin>>radius;
return radius;
}
float circleType::calculateArea(float pi, int radius)
{
area = pi * 2 * radius;
return area;
}
float circleType::calculateCircumference(float pi, int radius)
{
circum = pi * radius * radius;
return circum;
}
void circleType::printRadius(int radius)
{
cout<<endl<<"The radius of the circle is: "<<radius;
}
void circleType::printArea(float area)
{
cout<<endl<<"The area of the circle is: "<<area;
}
void circleType::printCircumference(float circum)
{
cout<<endl<<"The circumference of the circle is: "<<circum;
}
circleType::circleType()
{
}
int main()
{
float pi = 3.14;
cout<<pi;
int display;
circleType myCircle;
myCircle.inputRadius();
cout<<endl<<"Select the method of display.";
cout<<endl<<" 1) Display circle RADIUS";
cout<<endl<<" 2) Display circle AREA";
cout<<endl<<" 3) Display circle CIRCUMFERENCE";
cout<<endl;
cout<<endl<<"Enter your choice of display: ";
cin>>display;
switch(display)
{
case 1: myCircle.printRadius(myCircle.radius);
break;
case 2: myCircle.calculateArea(myCircle.pi, myCircle.radius);
myCircle.printArea(myCircle.area);
break;
case 3: myCircle.calculateCircumference(myCircle.pi, myCircle.radius);
myCircle.printCircumference(myCircle.circum);
break;
default: cout<<endl<<"You must enter either a '1', '2' or a '3'..."<<endl;
}
}