double b ; double h ; // global variables for base and height
// Functions for Main Menus
voidF_First();
voidF_Second();
// Base Class
classShape { // Abstract class
protected:
double base;
double height;
public:
voidget_data(double base, double height) {
this -> base = base;
this -> height = height;
}
voidvirtualdisplay_area() = 0; // pure virtual function
};
// Triangle class to calculate the area of triangle
classTriangle : publicShape {
public:
voiddisplay_area() {
cout << "Area of triangle: " << 0.5 * base * height << endl;
}
};
// Rectangle class to calculate the area of rectangle
classRectanglee : publicShape {
public:
voiddisplay_area() {
cout << "Area of Rectangle: " << base * height << endl;
}
};
classCircle : publicShape{
public:
voiddisplay_area() {
cout << "Area of Circle: " << base * base * 3.1415 << endl;
}
};
intmain() {
for (int k = 0; k < 1000; k++) {
system("cls");
cout << " M A I N M E N U\n" << "-------------------------------\n" << "1. First program\n" << "2. Second program\n" << "0. Exit\n" << "-------------------------------\n" << "Your choice: \n";
switch (_getch())
{
// First program
case49:
F_First();
break;
// second program
case50:
F_Second();
break;
default:
cout << " Your choice is not available in Menu.\n Please, enter one more time.\n";
Sleep(0700); Sleep(0700);
break;
case48:
return0;
break;
} // Switch
} // For loop
system("pause");
}
voidF_First(){
for (int k = 0; k < 1000; k++) {
system("cls");
cout << " C A L C U L A T I N G A R E A S\n" << "-------------------------------------------\n" << "1. Triangle\n" << "2. Rectangle\n" << "0. Back\n" << "Your choice: \n";
switch (_getch())
{
// Case to Exit from the program
case48: {
system("cls");
main();
}break;
// First program
case49: {
system("cls");
cout << " T R I A N G L E \n";
cout << "----------------------------------\n";
Shape* shape; //
Triangle triangle;
shape = ▵ // overriding functions for triangle
cout << "Your choice is not available in Menu.\nPlease, enter one more time.\n";
Sleep(0700); Sleep(0700);
}
break;
} // Switch
} // For loop
system("pause");
}
voidF_Second() {
for (int k = 0; k < 1000; k++) {
system("cls");
cout << " S E C O N D P R O G R A M\n" << "-------------------------------------\n" << "1. Triangle\n" << "2. Rectangle\n" << "3. Circle\n"<< "0. Back\n" << "Your choice: \n";
switch (_getch())
{
// Case to Exit from the program
case48: {
system("cls");
main();
}break;
// First program
case49: {
system("cls");
cout << " T R I A N G L E \n";
cout << "----------------------------------\n";
Shape* shape; //
Triangle triangle;
shape = ▵ // overriding functions for triangle