Question

In: Computer Science

Design a simple calculator program using C++ which is able to: 1. ADD two decimal numbers...

Design a simple calculator program using C++ which is able to:

1. ADD two decimal numbers

2. MULTIPLY two decimal numbers.

The following features must be incorporated in your program.
1. Must have an interface for the user to be able to either select the ADD option or MULTIPLY option or
to EXIT the program.
NOTE: If the user makes a wrong selection, a display must be shown to inform the user and the user
must be given a choice to select again.
2. All user inputs must be stored in a SINGLE DIMENSION ARRAY before the results are computed.
3. ALL results must be displayed to TWO decimal places.
4. An option must be available to CONTINUE any one calculation repeatedly without having to exit the
program.


C. Your program coding may incorporate any of the C program statements as per requirement but the
following MUST included in your program.
1. system(“cls”)
2. switch break
3. do....while4. void functions
5. if
6. macros

Solutions

Expert Solution

CODE:

#include <iostream>
#include<stdlib.h>
#include<cmath>
#define add(a,b)(a+b)
#define multiply(a, b)(a*b)

using namespace std;


void printResult(double numbers[],double a,char c){
//fucntion to print the result
cout<<numbers[0]<<" "<<c<<" "<<numbers[1]<<" = "<<round(a*100.0)/100.0<<endl;
}
int main()
{
//do while loop
do{
system("cls");
double *numbers = new double[2],result;
int choice;
char option;
//asking the user to enter the operation choice
cout<<"\nEnter\n1. ADD two decimal number\n2. MULTIPLY two decimal numbers\n3. Exit:"<<endl;
cin>>choice;
//asking the user to enter two numbers
cout<<"Enter a number: "<<endl;
cin>>numbers[0];
cout<<"Enter a number: "<<endl;
cin>>numbers[1];
//switch case
switch(choice){
case 1:
//if choice is 1
//the numbers will add
result = add(numbers[0],numbers[1]);
printResult(numbers,result,'+');
break;
case 2:
//case 2
//numbers will be multiplied
result = add(numbers[0],numbers[1]);
//printing the result
printResult(numbers, result, '*');
break;
case 3:
//exiting the code
exit(1);
break;
default:
//default case
cout<<"Invalid Input!"<<endl;
break;
}
//asking the user to continue or not
cout<<"Do you want to continue? (y/n) for yes/no"<<endl;
cin>>option;
//if user enters n the program ends
if(option == 'n')
break;
}while(1);

return 0;
}
__________________________________________

CODE IMAGES:

_________________________________________

OUTPUT:

_________________________________________

Feel free to ask any questions in the comments section

Thank YOu!


Related Solutions

Write a simple Calculator program using Scheme programming language. It should be able to do following...
Write a simple Calculator program using Scheme programming language. It should be able to do following operations: "+", "-", " * *, "/". the format when using the calculator function should be (calculator(operand1 operation operand2)) -> (calculator(2 + 5)) should give the output of 7.
Write a short and simple C++ program (must be able to have custom inputs): Design a...
Write a short and simple C++ program (must be able to have custom inputs): Design a class that holds the following personal data: name, address, age, and phone number Write appropriate accessor and mutator functions. Demonstrate the class by writing a program that creates three instances of it. One instance should hold your information, and the other two should hold your friends' or family members' information. Thanks!!
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator,...
TASK: Using stack functions, write a program in C++ language that acts as a simple calculator, reading an infix algebraic expression with numbers and simple operations: +, -, *, / , (, and ). The program converts an infix expression into an equivalent postfix expression, and then evaluates the postfix expression, and then prints the result if input expression is correct otherwise prints error messages. Your program must interact with the user until the user quits.    REQUIREMENTS: - Your...
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...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should...
Integer value calculator: Write a program using C++ that acts as a calculator. The program should ask the user for two numbers and an operator. Then the program must print the result using the two input values and the operator. Prompts and input requirements. Ask the user for two integer values and a value that indicates the operation. Likely you will want to choose the normal operators: + - * / %. Output Requirements: Make your output easy to understand,...
Must make a "Calculator" using C. The calculator must subtract, add, divide, and multiply inputs, and...
Must make a "Calculator" using C. The calculator must subtract, add, divide, and multiply inputs, and tell whether a number is prime or not. The user chooses how many inputs go into the calculator. For example, the code will ask the user what function they want. If the user chooses to subtract, the the code will then ask the user how many numbers they want to subtract. After, the code will ask the user to input as many numbers as...
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...
PYTHON: Im writing a program to make a simple calculator that can add, subtract, multiply, divide...
PYTHON: Im writing a program to make a simple calculator that can add, subtract, multiply, divide using functions. It needs to ask for the two numbers from the user and will ask the user for their choice of arithmetic operation 1- subtract 2- add 3- divide 4- multiply
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You...
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You should generate B complement signal (flip all the bits of Input B,
Design a program which a census the numbers and percentages of houses with particular numbers of...
Design a program which a census the numbers and percentages of houses with particular numbers of occupants in a road. The output must appear in a table like the one below: Output Occupants 0 1 2 3 4 5 6 >6 No. houses 2 3 7 9 6 4 2 2 Percentage 5.7% 8.6% 20.0% 25.7% 17.1% 11.4% 5.7% 5.7% Houses with more than 6 occupants are considered to be overcrowded, and are to be output under a single column...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT