Akef C++
Akef C++
➢ Introduction
This is a program which lets a user find different characteristics of two and three dimensioned
forms. The program is designed to show the option of ten various forms of shapes which the user
can select from and depending on that selected option by the user, the program can perform
related calculations for that selected form such as area, circumference, volume, surface area. It
focuses on creating an interface that allows the application select a shape without having to start
anew for the other one.
➢ Code:
#include <iostream>
#include <cmath>
using namespace std;
// Function prototypes
void calculateSquare();
void calculateCircle();
void calculateTriangle();
void calculateCube();
void calculateSphere();
void calculatePyramid();
void calculateCone();
void calculateTrapezoid();
void calculatePentagon();
void calculateCuboid();
int main() {
int choice;
bool continueProgram = true;
while (continueProgram) {
// Display menu
cout << "Select a shape to calculate its properties:" << endl;
cout << "1. Square" << endl;
cout << "2. Circle" << endl;
cout << "3. Triangle" << endl;
cout << "4. Cube" << endl;
cout << "5. Sphere" << endl;
cout << "6. Pyramid" << endl;
cout << "7. Cone" << endl;
cout << "8. Trapezoid" << endl;
cout << "9. Pentagon" << endl;
cout << "10. Cuboid / Rectangular Prism" << endl;
cout << "Enter your choice (1-10, 0 to exit): ";
cin >> choice;
void calculateSquare() {
double side;
cout << "Enter the length of the side of the square: ";
cin >> side;
double area = side * side;
double circumference = 4 * side;
cout << "Area: " << area << endl;
cout << "Circumference: " << circumference << endl;
}
void calculateCircle() {
double radius;
cout << "Enter the radius of the circle: ";
cin >> radius;
double area = M_PI * radius * radius;
double circumference = 2 * M_PI * radius;
cout << "Area: " << area << endl;
cout << "Circumference: " << circumference << endl;
}
void calculateTriangle() {
double base, height, side1, side2, side3;
cout << "Enter the base and height of the triangle: ";
cin >> base >> height;
cout << "Enter the lengths of the three sides: ";
cin >> side1 >> side2 >> side3;
double area = 0.5 * base * height;
double circumference = side1 + side2 + side3;
cout << "Area: " << area << endl;
cout << "Circumference: " << circumference << endl;
}
void calculateCube() {
double side;
cout << "Enter the length of the side of the cube: ";
cin >> side;
double volume = side * side * side;
double surfaceArea = 6 * side * side;
cout << "Volume: " << volume << endl;
cout << "Surface Area: " << surfaceArea << endl;
}
void calculateSphere() {
double radius;
cout << "Enter the radius of the sphere: ";
cin >> radius;
double volume = (4.0 / 3) * M_PI * pow(radius, 3);
double surfaceArea = 4 * M_PI * radius * radius;
cout << "Volume: " << volume << endl;
cout << "Surface Area: " << surfaceArea << endl;
}
void calculatePyramid() {
double baseLength, baseWidth, height;
cout << "Enter the length and width of the base of the pyramid: ";
cin >> baseLength >> baseWidth;
cout << "Enter the height of the pyramid: ";
cin >> height;
double baseArea = baseLength * baseWidth;
double volume = (1.0 / 3) * baseArea * height;
double slantHeight = sqrt(pow(height, 2) + pow(baseWidth / 2, 2));
double lateralSurfaceArea = baseLength * sl
➢ Solution Steps:
Step 1: Define the Shapes and Their Properties
• 2D Shapes: Square, Circle, Triangle, Trapezoid, Pentagon
• Properties: Area, Circumference
• 3D Shapes: Spheres, Cubes, Pyramids, Cones, Prisms (more commonly
referred to as rectangular prism).
• Properties: Volume, Surface Area
Step 2: Drawing up a menu
Instead, I’ll make the menu that will let the user choose one of the ten shapes and
go on. The following menu will be displayed at the start and after each calculation
so that the users can make any of the selections.
Step 3: Recognizing that there are different types of shapes, the following
functions can be defined for each shape.
Prompts the user with the appropriate dimensions needed for the computation.
Determines the attribute that applies to them: area for 2D shapes and
circumference for 2D shapes; volume for 3D shapes and surface area for 3D
shapes. Then Prints the results.
Step 2: Create a Menu
create a menu that allows the user to select one of the ten shapes. This menu will
be displayed at the start and after each calculation to allow multiple selections.
Step 3: Relationships of Each Shape to Other Shapes
• Prompts the user for the appropriate lengths.
• There exists the following properties required: area and circumference for
2D shapes, volume and surface area for 3D shapes.
• Prints the results.
Step 4: Implement the Calculation Logic
implement the formulas for each shape.
Step 5: Develop the actual look and feel of the actual software including the
graphical user interface
The program will be running the program and have the menu on the screen, as well
as control the input the user will make. Following such invocations of the input
section, the user will be presented with an option to choose another shape or quit
the program.
Step 6: Testing
It will make sure that the program is operating correctly concerning all figures, and
the graphical user interface is easy to understand and without annoyance.
➢ Conclusion
This project affords an appreciation of the wrinkles of programming mathematics
in such a way that can calculate properties of different shapes. This way, the
creation of the menu is separated from the shapes themselves, the program is easily
maintainable and the menu is flexible. As it has been seen with the looping
structure, the interaction can go on and on and that is why the application does not
become tiresome.