Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- class Shape
- {
- public:
- virtual double Area()=0;
- };
- class Diamond : public Shape{
- private:
- double side1 , side2;
- public:
- Diamond(double side1,double side2){
- this->side1 = side1;
- this->side2 = side2;
- }
- double getSide1()
- {
- return side1;
- }
- double getSide2()
- {
- return side2;
- }
- double Area()
- {
- return (side1 * side2) / 2;
- }
- };
- class Oval : public Shape
- {
- private:
- double Axis1;
- double Axis2;
- public:
- Oval(double one,double two)
- {
- Axis1 = one;
- Axis2 = two;
- }
- double getAxis1()
- {
- return Axis1;
- }
- double getAxis2()
- {
- return Axis2;
- }
- double Area()
- {
- return Axis1 * Axis2 * 3.14;
- }
- };
- class Pentagon : public Shape
- {
- private:
- double oneSide;
- public:
- Pentagon(double side)
- {
- oneSide = side;
- }
- double getSide()
- {
- return oneSide;
- }
- double Area()
- {
- return 1.0 / 4 * sqrt( 5 * ( 5 + 2 * sqrt(5)) * oneSide * oneSide);
- }
- };
- int main()
- {
- Shape* shape[10];
- int userChoice;
- int i= 0;
- double one, two;
- double side1, side2;
- double side;
- do
- {
- cout << endl << ">1 =Type 1 to make a Diamond= ";
- cout << endl << ">2 =Type 2 to make an Oval= ";
- cout << endl << ">3 =Type 3 to make a Pentagon= ";
- cout << endl << ">4 =Type 4 to list all currently stored shape areas= ";
- cout << endl << ">5 =Type 5 to close the Menu and exit the program= ";
- cout << endl << "Please enter a letter choice: ";
- cin >> userChoice;
- if(cin.fail())
- {
- cout<<"** Invalid.Must be an integer **"<<endl;
- cin.clear();
- cin.ignore(256, '\n');
- continue;
- }
- else if(userChoice<1 || userChoice>5)
- {
- cout<<"** Invalid Choice.Must be between 1-5 **"<<endl;
- continue;
- }
- switch(userChoice)
- {
- case 1:
- cout<< endl << "Input the two equal sides of the Diamond: ";
- cin >> side1 >> side2;
- shape[i] = new Diamond(side1 , side2);
- i++;
- break;
- case 2:
- cout<<"Input the two axes of the Oval: ";
- cin >> one >> two;
- shape[i] = new Oval(one , two);
- i++;
- break;
- case 3:
- cout << "Input a single side to the equal-sided Pentagon: ";
- cin >> side;
- shape[i] = new Pentagon(side);
- i++;
- break;
- case 4:
- cout<<"********************************************************"<<endl;
- for(int j = 0; j < i;j++)
- {
- cout<<"Current shape "<<(j+1)<<" has area = "<<shape[j]->Area() << endl;
- }
- cout<<"********************************************************"<<endl;
- break;
- case 5:
- break;
- default :
- cout<<"\nInvalid option";
- break;
- }
- }
- while(userChoice != 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement