Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- void displayHeader();
- void displayMenu();
- void calculateCircle(double x);
- void calculateTriangle(double h,double s1, double s2, double s3);
- void calculateSquare (double s);
- void calculateRectangle(double w ,double l);
- void displayResult(double x, double y, string shape);
- int main()
- {
- int answer;
- displayHeader();
- displayMenu();
- cin >> answer;
- switch (answer)
- {
- case 1: // circle
- double radius;
- cout << "Enter radius of circle " << endl;
- cin >> radius;
- calculateCircle(radius);
- break;
- case 2: // triangle
- double tHeight;
- double s1;
- double s2;
- double s3;
- cout << "Enter height of triangle " << endl;
- cin >> tHeight;
- cout << "Enter side1 of triangle " << endl;
- cin >> s1;
- cout << "Enter side2 of triangle " << endl;
- cin >> s2;
- cout << "Enter side3 of triangle " << endl;
- cin >> s3;
- calculateTriangle(tHeight,s1, s2,s3);
- break;
- case 3: // square
- double side;
- cout << "Enter side of square " << endl;
- cin >> side;
- calculateSquare(side);
- break;
- case 4: // rectangle
- double rHeight;
- double width;
- cout << "Enter width of rectangle " << endl;
- cin >> width;
- cout << "Enter height of rectangle " << endl;
- cin >> rHeight;
- calculateRectangle(width, rHeight);
- break;
- case 5:
- cout << "BYEEEEEEEee" << endl;
- break;
- default:
- cout << "Bad choice! Please try again later.\n";
- }
- return 0;
- }
- void displayHeader() {
- //cout << "******************************************************************" << endl;//
- cout << "Welcome to the Circumference and Surface Area Calculator!" << endl;
- cout << "******************************************************************" << endl;
- }
- void displayMenu() {
- cout << "Here are some shapes you could use to calculate the circumference and surface area" << endl;
- cout << "1 - Circle\n";
- cout << "2 - Triangle\n";
- cout << "3 - Square\n";
- cout << "4 - Rectangle\n";
- cout << "Quit\n";
- }
- void calculateCircle(double r)
- {
- double circumference = 2 * 3.14 * r;
- double surfaceArea = 3.14 * (r * r);
- displayResult(circumference, surfaceArea, "circle");
- }
- void calculateTriangle(double h,double s1, double s2, double s3){
- double circumference = s1 + s2 + s3;
- double surfaceArea = (h * s1) / 2;
- displayResult(circumference, surfaceArea, "triangle");
- }
- void calculateSquare(double s){
- double circumference = s * 4;
- double surfaceArea = s *s;
- displayResult(circumference, surfaceArea, "square");
- }
- void calculateRectangle(double w ,double l){
- double circumference = 2 * (w + l);
- double surfaceArea = w * l;
- displayResult(circumference, surfaceArea,"rectangle");
- }
- void displayResult(double c, double s, string shape){
- cout << "The circumference of the " << shape << " is " << c << endl;
- cout << "The surface area of the " << shape << " is " << s << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement