#include #include using namespace std; double area_of_triangle(double base, double height) { double area; area = 0.5*base*height; return area; } double area_of_rectangle(double base, double height) { double area; area = base*height; return area; } double area_of_house(double base, double height) { double area, roof_height; roof_height = base * 0.5; area = area_of_triangle(base, roof_height) + area_of_rectangle(base, height); return area; } double volume_of_house(double base, double height, double depth) { return area_of_house(base, height)*depth; } void add_house(double &total, double base, double height, double depth) { total += volume_of_house(base, height,depth); } int main() { bool more = true; string request; double neighborhood_total = 0; while (more) { double base, height, volume, depth, area; cout << "\nchoose one of the following:\n"; cout << endl; cout << "T compute the area of a triangle\n"; cout << "R compute the area of a rectangle\n"; cout << "H compute the area of a house\n"; cout << "V compute the volume of a house\n"; cout << "A compute the volume of a house, and add it to the neighborhood\n"; cout << endl; cout << "S to stop\n"; getline(cin, request); if (("T" == request) || ("t" == request)) { cout << "Base: "; cin >> base; cin.ignore(numeric_limits::max(), '\n'); cout << "Height: "; cin >> height; cin.ignore(numeric_limits::max(), '\n'); area = area_of_triangle(base, height); cout << "The area is " << area << endl; } else if (("R" == request) || ("r" == request)) { cout << "Base: "; cin >> base; cin.ignore(numeric_limits::max(), '\n'); cout << "Height: "; cin >> height; cin.ignore(numeric_limits::max(), '\n'); area = area_of_rectangle(base, height); cout << "The area is " << area << endl; } else if (("H" == request) || ("h" == request)) { cout << "Base: "; cin >> base; cin.ignore(numeric_limits::max(), '\n'); cout << "Height: "; cin >> height; cin.ignore(numeric_limits::max(), '\n'); area = area_of_house(base, height); cout << "The area is " << area << endl; } else if (("V" == request) || ("v" == request)) { cout << "Base: "; cin >> base; cin.ignore(numeric_limits::max(), '\n'); cout << "Height: "; cin >> height; cin.ignore(numeric_limits::max(), '\n'); cout << "Depth: "; cin >> depth; cin.ignore(numeric_limits::max(), '\n'); volume = volume_of_house(base, height, depth); cout << "The volume is " << volume << endl; } else if (("A" == request) || ("a" == request)) { cout << "Base: "; cin >> base; cin.ignore(numeric_limits::max(), '\n'); cout << "Height: "; cin >> height; cin.ignore(numeric_limits::max(), '\n'); cout << "Depth: "; cin >> depth; cin.ignore(numeric_limits::max(), '\n'); add_house(neighborhood_total, base, height, depth); cout << "The neighborhood total is " << neighborhood_total << endl; } else if (("S" == request) || ("s" == request)) { more = false; } else { cout << "Invalid choice, try again\n"; } } cout << "The total for the neighborhood is " << neighborhood_total << ".\n"; system("pause"); return 0; }