0% found this document useful (0 votes)
3 views2 pages

Edp LAB-5

This C++ program provides a menu for calculating the perimeter of a square, the area of a trapezoid, and the surface area of a cube. Users can input the necessary measurements, and the program will display the results with two decimal precision. The program continues to run until the user chooses to exit by selecting the appropriate option.

Uploaded by

jilliane navarro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Edp LAB-5

This C++ program provides a menu for calculating the perimeter of a square, the area of a trapezoid, and the surface area of a cube. Users can input the necessary measurements, and the program will display the results with two decimal precision. The program continues to run until the user chooses to exit by selecting the appropriate option.

Uploaded by

jilliane navarro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <cmath>
#include <iomanip>
#include <conio.h>
#include <windows.h>
using namespace std;

double calculatePerimeter(double a) {
return 4 * a;
}

double calculateTrapezoidArea(double B, double b, double h) {


return ((B + b) * h) / 2;
}

double calculateCubeSurfaceArea(double x) {
return 6 * pow(x, 2);
}

void mainMenu() {
char option;

do {
system("cls");
cout << "\tMain List Option\n\n";
cout << "\t[A] Perimeter\n";
cout << "\t[B] Area\n";
cout << "\t[C] Surface Area\n";
cout << "\t[D] Exit\n";
cout << "\n\tEnter Option: ";
cin >> option;

option = toupper(option);
switch (option) {
case 'A': {
double a;
cout << "\nSquare\nEnter side measurement of the Square: ";
cin >> a;
cout << "\nThe Perimeter of the Square is "
<< fixed << setprecision(2)
<< calculatePerimeter(a) << " inches.\n";
break;
}
case 'B': {
double B, b, h;
cout << "\nTrapezoid\nInput Base 1 measurement: ";
cin >> B;
cout << "Input Base 2 measurement: ";
cin >> b;
cout << "Input Height measurement: ";
cin >> h;
cout << "\nThe Area of the Trapezoid is "
<< fixed << setprecision(2)
<< calculateTrapezoidArea(B, b, h) << " square units.\n";
break;
}
case 'C': {
double x;
cout << "\nCube\nInput side measurement of the Cube: ";
cin >> x;
cout << "\nThe Surface Area of the Cube is "
<< fixed << setprecision(2)
<< calculateCubeSurfaceArea(x) << " square cm.\n";
break;
}
case 'D':
cout << "\nExiting system...\n";
exit(0);
break;
default:
cout << "Invalid entry, please try again.\n";
}

cout << "\nPress <K/k> to go back to the main menu...";


char key = getch();
} while (key == 'K' || key == 'k');
}

int main() {
mainMenu();
return 0;
}

You might also like