Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

C++ Help converting existing assignment to use classes.

Original assignment:
Create a program that calculates the hypotenuse of a triangle, the area of a trapezoid, and the volume of a rectangle. The user must input the variables in the formulas.
Changes to be made:
Convert previous assignment to utilize a class structure in portable .h and .cpp files
Exit the program only on user demand

code:
//dispays menu
void displayMenu() {
   cout << "Please Choose a calculation function" << endl;
   cout << endl;
   cout << "Enter 1 to calculate the hypotenuse of a triangle of a triangle" << endl;
   cout << endl;
   cout << "Enter 2 to calculate the area of a trapezoid" << endl;
   cout << endl;
   cout << "Enter 3 to calculate the volume of a rectangular prism" << endl;
   cout << endl;
   cout << "Enter any other letter or number input to exit" << endl;
}


//hypotenuse of triangle and associated functions
double calculateHypotenuse(double sideA, double sideB) {
   double hypotenuse = sqrt((sideA * sideA) + (sideB * sideB));
   return hypotenuse;
}
void hypotenuseMenuOption() {
   double side1;
   double side2;
   cout << "Enter the measurement of the base of the triangle" << endl;
   cin >> side1;
   cout << "Enter the measurement of the height of the triangle" << endl;
   cin >> side2;
   cout << endl;
   cout << " The hypotenuse of the triangle is: " << calculateHypotenuse(side1, side2);

}

//trapezoid area and associated functions
double calculateTrapezoidArea(double base1, double base2, double height) {
   double area = ((base1 + base2) / 2) * height;
   return area;
}

void trapezoidAreaMenuOption() {
   double b1;
   double b2;
   double h;
   cout << "Enter the first base of the trapezoid" << endl;
   cin >> b1;
   cout << "Enter the second base of the trapezoid" << endl;
   cin >> b2;
   cout << "Enter the height of the trapezoid" << endl;
   cin >> h;
   cout << endl;
   cout << "The area of the trapezoid is: " << calculateTrapezoidArea(b1, b2, h);
}

//volume of a rectangular prism and associated functions
double calculateRectangleVolume(double length, double width, double height) {
   double volume = length * width * height;
   return volume;
}

void rectangleVolumeMenuOption() {
   double rectangleLength;
   double rectangleWidth;
   double rectangleHeight;
   cout << "Enter the length of the rectangle" << endl;
   cin >> rectangleLength;
   cout << "Enter the width of the rectangle" << endl;
   cin >> rectangleWidth;
   cout << "Enter the height of the rectangle" << endl;
   cin >> rectangleHeight;
   cout << endl;
   cout << "The volume of the rectangular prism is: " << calculateRectangleVolume(rectangleLength, rectangleWidth, rectangleHeight);
}

//driver
int main() {
   displayMenu();
   int menuChoice;
   cin >> menuChoice;
   if (menuChoice == 1) {
       hypotenuseMenuOption();
   }
   else if (menuChoice == 2) {
       trapezoidAreaMenuOption();
   }
   else if (menuChoice == 3) {
       rectangleVolumeMenuOption();
   }
   else {
       exit(0);
   }
  

 
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education