Question

In: Computer Science

For this assignment you will develop pseudocode and write a C++ program for a simple calculator....

For this assignment you will develop pseudocode and write a C++ program for a simple calculator. You will create both files in Codio. Put your pseudocode and C++ code in the files below.

PSEUDOCODE FILE NAME: Calculator.txt
C++ SOURCE CODE FILE NAME : Calculator.cpp

DESCRIPTION:

Write a menu-driven program to perform arithmetic operations and computations on a list of integer input values. Present the user with the following menu. The user will choose a menu option. The program will prompt the user for 2 whole numbers (integers), perform the operation specified by the menu option and then display the result. Name your file Calculator.cpp.

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice:

Suppose the user chooses option (A). The program will prompt the user for 2 numbers, add them and display the sum, then thank the user.

Enter first number: 3
Enter second number 8
The sum is 11

Thank you for using the Calculator.

The program ends after giving the result.

Supposed the program is run again and the user enters option S. The program will subtract the second number from the first and present the result.

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: S

Enter first number: 4
Enter second number: 6
The difference is -2

Thank you for using the Calculator.

Option M will multiply the 2 numbers. Option D will divide the first number by the second. Option R will produce the remainder after dividing the first number by the second. If the user chooses (Q) the program exits with a message : “is turned off”

If the user enters an illegal option, the program should show an error message then end. For example.

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: G

invalid choice

NOTE:

  1. Your menu should appear exactly as it is shown above.

  2. The prompts for the user and the output for the results should appear exactly as specified above.

  3. The menu options are case insensitive. The Calculator should accept upper-case ‘M’ and lower-case 'm’.

  4. Account for invalid operations such as dividing a number by zero or attempting to get the remainder after dividing by zero. In the event that happens print “The remainder is Error”

More Examples

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: a

Enter first number: 5
Enter second number: 4
The sum is 9

Thank you for using the Calculator.

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: R

Enter first number: 8
Enter second number: 10
The remainder is 8

Thank you for using the Calculator.

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: m
Enter first number: 3
Enter second number: 2

The product is 6

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: D
Enter first number: 5
Enter second number: 0

The division is Error

Thank you for using the Calculator.

MY CALCULATOR

A) Add
S) Subtract
M) Multiply
D) Divide
R) Remainder (Mod)
Q) QUIT (turn off)

Enter Menu Choice: Q
is turned off

Thank you for using the Calculator.

Solutions

Expert Solution

The pseudo code and the full cpp code for the following problem is given below.

In the simple arithmetic calculator

The pseudocode for sum is.

int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1+num2; //add two number and display it
cout<<"The sum is "<<result<<endl;

The pseudo code for subtraction is.

int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1-num2; //difference store in result and displa it
cout<<"The difference is "<<result<<endl;

The pseudo code for multiplication is.

int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1*num2; //multiply both no. and display it
cout<<"The product is "<<result<<endl;

The pseudo code for division is.

int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
if(num2==0){ //if num 2 is 0
cout<<"The division is Error"<<endl; //display the error mssg
}
else{
int result=num1+num2;//else divided two number and display it
cout<<"The divisiom is "<<result<<endl;
}

The pseudo code for reminder is.

int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1%num2; //calculating reminder and display it
cout<<"The reminder is "<<result<<endl;

These are the following pseudo codes.

The full cpp program with output is given below.

CODE.

#include <iostream>

using namespace std;

int main()
{
//driver code to display menu
cout << "MY CALCULATOR" << endl;
cout<<"A) Add"<<endl;
cout<<"S) Subtract"<<endl;
cout<<"M) Multiply"<<endl;
cout<<"D) Divide"<<endl;
cout<<"R) Remainder(Mod)"<<endl;
cout<<"Q) Quit(turn off)"<<endl;
cout<<"Enter Menu Choice: ";
char x; //initialize char variable to take user response
cin>>x;
if(x=='A' || x=='a') //if user opt for addition the statement is correct
{
int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1+num2; //add two number and display it
cout<<"The sum is "<<result<<endl;
}
//condition for the user input for substraction
else if(x=='S' || x=='s')
{
int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1-num2; //difference store in result and displa it
cout<<"The difference is "<<result<<endl;
}
//condition for user input for multiplication
else if(x=='M' || x=='m')
{
int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1*num2; //multiply both no. and display it
cout<<"The product is "<<result<<endl;
}
//condition for user opt for division
else if(x=='D' || x=='d')
{
int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
if(num2==0){ //if num 2 is 0
cout<<"The division is Error"<<endl; //display the error mssg
}
else{
int result=num1+num2;//else divided two number and display it
cout<<"The divisiom is "<<result<<endl;
}
}
//condition for user opt for reminder
else if(x=='R' || x=='r')
{
int num1,num2;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
int result=num1%num2; //calculating reminder and display it
cout<<"The reminder is "<<result<<endl;
}
//condition for if the user want to quit.
else if(x=='Q' || x=='q'){
cout<<"is turned off"<<endl;
}

else{
cout<<"Invalid choice"<<endl;
}
cout<<"Thank you for using Calculator."; //thank you message
return 0;
}

SNAPS.

OUTPUT.

For any query message me in comment.


Related Solutions

REVERSE POLISH CALCULATOR C++ ONLY. For this assignment, you are to write a program, which will...
REVERSE POLISH CALCULATOR C++ ONLY. For this assignment, you are to write a program, which will calculate the results of Reverse Polish expressions that are provided by the user. You must use a linked list to maintain the stack for this program (NO array implementations of the stack). You must handle the following situations (errors): Too many operators (+ - / *) Too many operands (doubles) Division by zero The program will take in a Polish expression that separates the...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
1. Write pseudocode for the following program. You do not have to write actual C++ code....
1. Write pseudocode for the following program. You do not have to write actual C++ code. Assume you have a text file, that has been encrypted by adding 10 to the ASCII value of each character in the message. Design a decryption program that would reverse this process, and display the original message to the console.to the new array. 2.Write the code for the specified program. Use proper style and naming. Test and upload your code as a CPP file....
In C++ For this assignment, you will write a program to count the number of times...
In C++ For this assignment, you will write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of 31 characters named word An integer named count Functions Write the following functions: int main(int argc, char* argv[]) This function should declare an array of 200 WordCount objects and an integer numWords to track the number of array...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this week’s lab assignment, you will write a program called lab9.c. You will write a...
For this week’s lab assignment, you will write a program called lab9.c. You will write a program so that it contains two functions, one for each conversion. The program will work the same way and will produce the same exact output. The two prototypes should be the following: int btod(int size, char inputBin[size]); int dtob(int inputDec); The algorithm for the main() function should be the following: 1. Declare needed variables 2. Prompt user to enter a binary number 3. Use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT