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

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...
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...
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.
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.
C program simple version of blackjack following this design. 1. The basic rules of game A...
C program simple version of blackjack following this design. 1. The basic rules of game A deck of poker cards are used. For simplicity, we have unlimited number of cards, so we can generate a random card without considering which cards have already dealt. The game here is to play as a player against the computer (the dealer). The aim of the game is to accumulate a higher total of points than the dealer’s, but without going over 21. The...
Design a modular program which asks the user to enter a list of numbers. The numbers...
Design a modular program which asks the user to enter a list of numbers. The numbers must be stored in an array. The program then finds the index of the first occurrence of the smallest element in the array and the last occurrence of the largest element in the array. The program displays the position and value of each of these items.
Using Java, design a program to let user enter two lists of numbers within the range...
Using Java, design a program to let user enter two lists of numbers within the range [0, 9] from keyboard, you could either use flag to denote end of the list or ask user to enter the list size first and then enter the list numbers. Each of these two lists represents a set (keep in mind that duplicate elements are not allowed in the same set but are allowed between sets), so we have two sets A and B....
Write a Python program to add, multiply and divide any two numbers.
Write a Python program to add, multiply and divide any two numbers.
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT