Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a Simple Calculator C + + 2 program. I provided a screenshot of the instructions for this program. Read it carefully. The Code

This is a Simple Calculator C++2program. I provided a screenshot of the instructions for this program. Read it carefully. The Code I'll provide with comments read them carefully with the corresponding code provided on the screenshot. SimpleCalc.cpp #include "SimpleCalc.h"
void SimpleCalc::Calculate()
{
switch (operation)
{
case '+':
answer = operand1+ operand2;
desc = "addition";
break;
case'/':
//check to see if operand2 is 0
if (operand2==0)
{
desc ="No Division by 0!";
}
else
{
//regular division
desc = "division";
}
break;
default:
//handle an operation that is not acceptable
desc = "That operation is not allowed. Please try again";
}
}
SimpleCalc::SimpleCalc()
{
}
void SimpleCalc::SetOperation(char oper, double op1, double op2)
{
operation = oper;
operand1= op1;
operand2= op2;
//check if operand2=0 and operation is division
//then set desc and don't even call calculate
Calculate();
}
string SimpleCalc::GetResults()
{
//create a string that says "Your operation is addition: 5+7=12"
//or "Your operation is division: 6/0 Illegal Operation!
//check to see if the operation was illegal or if the operation was not
//a valid one. Then male a different desc
//return string();
}
Driver.cpp #include "SimpleCalc.h"
#include
bool DoAnother();
using namespace std;
int main()
{
//cout a course header
cout "Welcome to Simple Calculator!";
//declare any varibale you need and create a SimpleCalc object
char ans{'y'};
char op{'-'};
double num1{0.0}, num2{1.0};
string results;
SimpleCalc calc;
//start a play loop
do {
//ask the user for the operation and the two operands
cout "Please enter an operation(+,-,/)";
cout "Enter two operands: ";
cin >> num1>> num2;
//use the object to SetOperation
calc.SetOperation(op, num1, num2);
//call GetResults and show them
cout calc.GetResults();
//ask the user if they want to go again
cout "Do you want to calculate another question? (y/n);
cin >> ans;
} while (DoAnother());
//cout a goodbye
cout "Thank you using Simple Calculator, Goodbye!";
return 0;
}
bool DoAnother()
{
char ans{'y'};
cout "
Do you want to calculate another? (y/n)";
cin >> ans;
//check
if (ans =='y')
return true;
return false;
}
image text in transcribed

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

Step: 3

blur-text-image

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

Data Analysis In Microsoft Excel

Authors: Alex Holloway

1st Edition

B0CCCPKTTX, 979-8852388452

More Books

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago