I (and am sure others too) would like to see how you call those
functions. It's not enough to see the class definition and the
implementation, one always has to see how the class is used.
Ok so here is my full program. it compiles but the answer like I says is
wrong:
#include <iostream>
#include <cmath>
using namespace std;
const double PI = 3.14159;
class Point
{ int x,y, color;
public:
Point(int a=0, int b=0, int c=0){
x=a; y=b; color=c; }
};
class Shape
{ protected:
Point p1;
public:
Shape(Point p)
1(p) {}
Shape(){};
int SetColor();
void CreateShape(); //choosing the shape
void DrawShape();
void DisplayShape();
protected:
};
class Circle : public Shape
{
public:
Circle (){};
Circle(Point p, int r=0) : Shape(p) {itsRadius = r;}
Circle (int radius){
itsRadius = 0;
volume =0;
}
void CreateCircle();
void ShowCircle();
void SetVolume( float radius){
volume = PI * pow(radius,2); }
float GetVolume(){ return volume; }
private:
float itsRadius;
float volume;
};
void Shape::CreateShape()
{ Circle circ;
char choice;
// Circle circle_array[10];
//int count_circle =0;
do {
cout<<" Shape Management System "<<endl;
cout<< " ============================================== "<<endl;
cout <<endl <<endl;
cout<<" 1. Create a Circle "<<endl;
cout<<" 2. Create a Cylinder "<<endl;
cout<<" 3. Create a Triangle "<<endl;
cout<<" 4. Go back to main menu "<<endl;
cout << " Your choice please: " ;
cin >> choice;
switch (choice)
{
case '1':
circ.CreateCircle() ;
break;
case '2':
break;
case '3':
break;
case '4': cout<<"This exit will go back to the previous menu !" <<endl;
break;
default: cout<<"Error: Invalid option, Please try again" <<endl;
break;
}
}while ( (choice != '4') ) ;
}
void Shape:
isplayShape()
{ Circle circ;
char choice;
do {
cout<<" Shape Management System "<<endl;
cout<< " ============================================== "<<endl;
cout <<endl <<endl;
cout<<" 1. Show Circles created "<<endl;
cout<<" 2. Show Cylinders created "<<endl;
cout<<" 3. Show Triangles created "<<endl;
cout<<" 4. Go back to main menu "<<endl;
cout << " Your choice please: " ;
cin >> choice;
switch (choice)
{
case '1':
circ.ShowCircle() ; //SetTime( &s[0], &count, &totalTime[0] );
break;
case '2':
break;
case '3':
break;
case '4': cout<<"This exit will go back to the previous menu !" <<endl;
break;
default: cout<<"Error: Invalid option, Please try again" <<endl;
break;
}
}while ( (choice != '4') ) ;
}
void menu()
{ char choice;
Circle draw;
float *count =0;
do {
cout<<endl <<" Shape Management System "<<endl;
cout<< " ============================================== "<<endl;
cout<<" 1. Create Object "<<endl;
cout<<" 2. Display Object Created "<<endl;
cout<<" 3. Quit "<<endl;
cout << " Your choice please: " ;
cin >> choice;
switch (choice)
{
case '1':
draw.CreateShape(); //SetTime( &s[0], &count, &totalTime[0] );
break;
case '2':
draw.DisplayShape();
break;
case '3': cout<<"Thank you for having used this system, Bye Bye!!!";
break;
default: cout<<"Error: Invalid option, Please try again" << endl <<endl;
}
}while ( (choice != '3') ) ;
}
float main()
{
menu();
getch();
return 0;
}
void Circle::CreateCircle() //Draw a circle
{ Circle cir(0);
char color;
float itsRadius;
cout<<"Enter the radius in cm: " ;
cin>> itsRadius;
cir.SetVolume(itsRadius);
cout<<" Volume: " << cir.GetVolume() <<endl;
color = SetColor();
}
void Circle::ShowCircle()
{
cout <<" Volume is : " << GetVolume() <<" cm cube " <<endl;
}
int Shape::SetColor() //Functions for the base class
{ char input;
cout<<" Choose a color from the following menu: " <<endl;
cout<<" 1. Blue "<<endl;
cout<<" 2. Green "<<endl;
cout<<" 3. Red "<<endl;
cout<<" 4. Orange "<<endl;
cout<<" 5. Yellow "<<endl;
cout<<" 6. Purple "<<endl;
cin >> input ;
if (input == '1' || input == '2' || input == '3' || input == '4' || input
== '5' || input == '6') return input ;
else
{ cout<<"You have not choosen a color, Please choose a number between 1 to
6 !" <<endl;
}
return 0;
}