Skip to content

CIS2275CPPII/MlengelaP2

Repository files navigation

Simple Calculator

Write a class that is a simple calculator. It performs addition, subtraction, multiplication, and division operations. All operations are performed on doubles. The class should be named SimpleCalc. It has one default constructor. There is a public function called SetOperation that is passed a character representing the desired operation, and the two operands. The character symbols are +, -, /, and *. The actual calculation is performed in Calculate, called by SetOperation. The result of the operation is returned via a GetResults function that returns a neatly formatted string that your operation is addition: 5 + 7 = 12 states the name of the operation, shows the two operands, the math operator, and the result in an equation-type format. For example, if the user requested that 5 and 7 are added together, the results string should look like this:

Your operation is addition: 5 + 7 = 12

If the user requests a division by zero, the result string indicates that it is illegal to perform a division by zero. It should say something like this:

Your operation is division: 6 / 0 Illegal Operation!

Your main function should show your course header and create a SimpleCalc object. Then begin a do-while loop that asks the user to select an operation and enter the two operands. Pass the values into the SetOperation function and call GetResults. Be sure to take care of the case when the user enters the wrong operation. Show the results string to the user. Format the output numbers to 2 decimal places. Continue to allow the user to perform math until they wish to stop. Then display a good-bye message.

Your class should look like this:

image

Sources:

Usage:

Contribution:

About

This is simple calculator. C++ GUI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages