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!!
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...
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...
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...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
Create a program using python that provides a simple calculator: Requires a login with a prompt...
Create a program using python that provides a simple calculator: Requires a login with a prompt for a username and a password prior to using the calculator If username and password are incorrect, the program should re-prompt to re-enter correct username and password Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators: Addition Subtraction Multiplication Division Square Root PI Exponents
Design a system which can add two 2-digit binary numbers (no carry in). Use a truth...
Design a system which can add two 2-digit binary numbers (no carry in). Use a truth table approach and use karnaugh-map Write a Boolean equation for each output and draw circuit.
1.write a small program using a loop to add a series of numbers 2.write a function...
1.write a small program using a loop to add a series of numbers 2.write a function called "main" that performs several given steps. Be sure to call the main() function so that its code executes In python and doesn't have to be long. just long enough to do what it says. Thank you.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT