
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);
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 8 images

- Write a class name FileDisplay with the following methods: Constructor: takes the name of a file as an argument displayHead: displays only the first five lines of the file’s contents. If the file contains less than 5 lines, it should display the file’s entire contents. displayContents: displays the entire contents of the file, the name of which was passed to the constructor. writeNew: displays the contents of a file, the name of which was passed to the constructor. Each line should be preceded with a line number followed by a colon. The line numbering should start at 1. As each line is displayed it should also be written to a new file, the name of which is passed in as a parameter. I have provided a test file called “testfile.txt”. I have also provided a driver for the application called “filedisplaytest.java”. This file is complete and should not be altered. Test File: This is line one.This is line two.This is line three.This is line four.This is line five.This is line…arrow_forwardpython class Student:def __init__(self, first, last, gpa):self.first = first # first nameself.last = last # last nameself.gpa = gpa # grade point average def get_gpa(self):return self.gpa def get_last(self):return self.last def to_string(self):return self.first + ' ' + self.last + ' (GPA: ' + str(self.gpa) + ')' class Course:def __init__(self):self.roster = [] # list of Student objects def drop_student(self, student):# Type your code here def add_student(self, student):self.roster.append(student) def count_students(self):return len(self.roster) if __name__ == "__main__":course = Course() course.add_student(Student('Henry', 'Nguyen', 3.5))course.add_student(Student('Brenda', 'Stern', 2.0))course.add_student(Student('Lynda', 'Robinson', 3.2))course.add_student(Student('Sonya', 'King', 3.9)) print('Course size:', course.count_students(),'students')course.drop_student('Stern')print('Course size after drop:', course.count_students(),'students')arrow_forwardin phython language Create a package folder named shapes. Inside this package, place two more package folders: 2d and 3d. Inside 2d package, place a module file: circle.py circle.py module has two function definitions: areaCircle(), circCircle(). areaCircle() function takes a parameter: radius, calculates and returns the area of the circle. You may assume PI is 3.14. circCircle() function also takes a parameter: radius, calculates and returns the circumference of the circle. Inside 3d package, place two module files: sphere.py and cylindir.py sphere.py module has two function definitions: areaSphere() and volumeSphere() which both take a parameter for radius, calculates and returns area and volume of a sphere respectively. cylindir.py module has two function definitions: areaCylindir() and volumeCylindir() which both take two parameters: height and radius. They calculate area and volume of a cylindir and return the values respectively. You may find the formulas for those shapes…arrow_forward
- #this is a python program #topic: OOP Design the Country class so that the code gives the expected output. [You are not allowed to change the code below] # Write your Class Code here country = Country() print('Name:',country.name) print('Continent:',country.continent) print('Capital:',country.capital) print('Fifa Ranking:',country.fifa_ranking) print('===================') country.name = “Belgium” country.continent = “Europe” country.capital = “Brussels” country.fifa_ranking = 1 print('Name:',country.name) print('Continent:',country.continent) print('Capital:',country.capital) print('Fifa Ranking:',country.fifa_ranking) Output: Name: Bangladesh Continent: Asia Capital: Dhaka Fifa Ranking: 187 =================== Name: Belgium Continent: Europe Capital: Brussels Fifa Ranking: 1arrow_forward// Declare data fields: a String named customerName, // an int named numItems, and // a double named totalCost.// Your code here... // Implement the default contructor.// Set the value of customerName to "no name"// and use zero for the other data fields.// Your code here... // Implement the overloaded constructor that// passes new values to all data fields.// Your code here... // Implement method getTotalCost to return the totalCost.// Your code here... // Implement method buyItem.//// Adds itemCost to the total cost and increments// (adds 1 to) the number of items in the cart.//// Parameter: a double itemCost indicating the cost of the item.public void buyItem(double itemCost){// Your code here... }// Implement method applyCoupon.//// Apply a coupon to the total cost of the cart.// - Normal coupon: the unit discount is subtracted ONCE// from the total cost.// - Bonus coupon: the unit discount is subtracted TWICE// from the total cost.// - HOWEVER, a bonus coupon only applies if the…arrow_forwardTrue or False: Object privileges allow you to add and drop usersarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





