Temporary
Temporary
int main()
{
int choice;
cout << "\t\t\t\tEnter Choice: " << endl;
cout << "\t\t1 for Triangle\t\t2 for Square" << endl;
cout << "\t\t3 for Rectangle\t\t4 to Quit" << endl;
cin >> choice;
while (choice != 4)
{
//Triangle
if (choice == 1)
{
Triangle obj;
cout << "Enter Height: " << endl;
cin >> obj.height;
cout << "Enter Base: " << endl;
cin >> obj.base;
cout << "Enter Side: " << endl;
cin >> obj.side;
obj.area(obj.base, obj.height, 1);
obj.perimeter(obj.base, obj.height, obj.side, 1);
}
//Square
if (choice == 2)
{
square obj;
cout << "Enter Length: " << endl;
cin >> obj.length;
obj.area(obj.length, 0, 2);
obj.perimeter(obj.length, 0, 0, 2);
}
//Rectangle
if (choice == 3)
{
Rectangle obj;
cout << "Enter Length: ";
cin >> obj.length;
cout << "Enter Width: ";
cin >> obj.width;
obj.area(obj.length, obj.width, 3);
obj.perimeter(obj.length,obj.width, 0, 3);
system("pause");
system("cls");
cout << "\t\t\t\tEnter Choice: " << endl;
cout << "\t\t1 for Triangle\t\t2 for Square" << endl;
cout << "\t\t3 for Rectangle\t\t4 to Quit" << endl;
cin >> choice;
}
system("pause");
return 0;
}
void Shape::area(int x, int y, int c)
{
int area;
//Triangle
if (c == 1)
{
area = (x*y)/2;
}
//Square
if (c == 2)
{
area = x*x;
}
//Rectangle
if (c == 3)
{
area = x*y;
}
cout << "Area is: " << area << endl;
}