Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Number Calculator: #include #include int main() { while (true) { int num1, num2; std::string num1Str, num2Str, operation; std::cout < < Enter 1st number (one, two,

Number Calculator: #include #include int main() { while (true) { int num1, num2; std::string num1Str, num2Str, operation; std::cout << "Enter 1st number (one, two, three, four, or five): "; std::cin >> num1Str; if (num1Str == "one") { num1 = 1; } else if (num1Str == "two") { num1 = 2; } else if (num1Str == "three") { num1 = 3; } else if (num1Str == "four") { num1 = 4; } else if (num1Str == "five") { num1 = 5; } else { std::cout << "Input is not recognizd. Try again! "; continue; } std::cout << "Enter operation (add, sub, mul, div): "; std::cin >> operation; std::cout << "Enter 2nd number (one, two, three, four, or five): "; std::cin >> num2Str; if (num2Str == "one") { num2 = 1; } else if (num2Str == "two") { num2 = 2; } else if (num2Str == "three") { num2 = 3; } else if (num2Str == "four") { num2 = 4; } else if (num2Str == "five") { num2 = 5; } else { std::cout << "Input is not recognizd. Try again! "; continue; } if (operation == "add") { std::cout << num1 + num2 << std::endl; } else if (operation == "sub") { std::cout << num1 - num2 << std::endl; } else if (operation == "mul") { std::cout << num1 * num2 << std::endl; } else if (operation == "div") { if (num2 != 0) { std::cout << (float)num1 / num2 << std::endl; } else { std::cout << "Cannot divide by zero "; continue; } } else {

std::cout << "Input is not recognizd. Try again! "; continue; } } return 0; }

Shape Area Calculator: #include #include using namespace std; int main() { while (true) { string shape; cout << "Enter shape (circle, triangle, rectangle): "; cin >> shape; if (shape == "circle") { float radius; cout << "Enter the radius: "; cin >> radius; float area = M_PI * pow(radius, 2); cout << "Area of the circle: " << area << endl; } else if (shape == "triangle") { float base, height; cout << "Enter the base of the triangle: "; cin >> base; cout << "Enter the height of the triangle: "; cin >> height; float area = 0.5 * base * height; cout << "Area of the triangle: " << area << endl; } else if (shape == "rectangle") { float length, width; cout << "Enter the length of the rectangle: "; cin >> length; cout << "Enter the width of the rectangle: "; cin >> width; float area = length * width; cout << "Area of the rectangle: " << area << endl; } else { cout << "Shape is not recognized. Try again!" << endl; } } return 0; }

CLI

Combine the two problems Number Calculator and Shape Area Calculator into a single application. Create a menu for the user to select the calculator type. Also provides error checking for inputted values. The application should accept correct values with leading and trailing blank characters example, two\t is still equal to two. If the user makes three consecutive errors at any point, exit the application with a non-zero status code. Use functions and while loops for error checking and repeating input prompts.

In the main menu, shape is the command the user will type to access the space calculator. calc is the command the user will type to access the word calculator. quit is the command the user will type to exit the program.

The quit command will exit the program with a 0 status code.

Submit the source code function in a file named functions_calculator.cpp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago