1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <istream>
#include<math.h>
double Area_Circle(int);
int Area_Rectangle(int,int);
int Area_Square(int);
int Menu();
int Input_Side();
int Input_Radius();
void Output_Rectangle(int,int,double);
void Output_Shape(int,double);
using namespace std;
int main()
{
int radius, width, length, side, choice;
double area;
do
{
choice = Menu();
switch(choice)
{
case 1: width = Input_Side();
length = Input_Side();
area = Area_Rectangle(width,length);
cout << "Rectangle:\t" << "Width\t" << "Length\t" << "Area\n";
Output_Rectangle(width,length,area);
break;
case 2: radius = Input_Radius();
area = Area_Circle(radius);
cout << "Circle:\t" << "Radius\t" << "Area\n";
Output_Shape(radius,area);
break;
case 3: side = Input_Side();
area = Area_Square(side);
cout << "Square:\t" << "Sides\t" << "Area\n";
Output_Shape(side,area);
break;
case 4: cout << " Have a nice day!" << endl << endl;
break;
default: cout << "Invalid choice. " << endl << endl;
}
}while(choice >=1 || choice <= 4);
system("PAUSE");
return EXIT_SUCCESS;
}
int Menu()
{
int choice;
cout << "\n Choose a shape to calculate AREA";
cout << "\n...................................";
cout << "\n 1- Rectangle\n 2- Circle\n 3- Square\n 4- Exit";
cout << "\n\n Enter your choice: ";
cin >> choice;
}
int Input_Side()
{
int side;
cout << "\n Enter side: ";
cin >> side;
return (side);
}
int Input_Radius()
{
int radius;
cout << "\n Enter the radius: ";
cin >> radius;
return (radius);
}
double Area_Circle(int radius)
{
return (3.14 * radius * radius);
}
int Area_Rectangle(int length,int width)
{
return (length * width);
}
int Area_Square(int side)
{
return (side * side);
}
void Output_Rectangle(int width, int length, int area)
{
cout << "\t\t" << width << "\t" << length << "\t" << area;
}
void Output_Circle(int radius, double area)
{
cout << "\t\t" << radius << "\t" << area;
}
void Output_Square(int side, double area)
{
cout << "\t\t" << side << "\t" << area;
}
|