Write a program which allows the user to perform simple tasks on a calculator. A
ID: 3725227 • Letter: W
Question
Write a program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one +, -,*,/,or% A X M S Q of the following: representing the usual arithmetic operators representing the average of two numbers representing the maximum of two numbers representing the minimum of two numbers representing the square of a number indicating the user wants to quit the program The program reads the user's response into a variable of type char. Using a switch statement, the program determines which method to call to process the user's request. For example, if the user enters +, a method is called which prompts the user to enter two integers. The method then finds the sum of the two integers and the method prints the results of the operation. If the user enters X, a method asks for two integers and finds the larger of the two. If the user enters S, a method asks for one value and finds the square of that value. If the user enters Q, the program stops. For each calculation performed, the method prints the operation requested, the user's original input, and the result. Note: All output must be sent to a file Sample Output: Operation: addition augend: 25 addend: 35 sum: 60 Write a program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one +, -,*,/,or% A X M S Q of the following: representing the usual arithmetic operators representing the average of two numbers representing the maximum of two numbers representing the minimum of two numbers representing the square of a number indicating the user wants to quit the program The program reads the user's response into a variable of type char. Using a switch statement, the program determines which method to call to process the user's request. For example, if the user enters +, a method is called which prompts the user to enter two integers. The method then finds the sum of the two integers and the method prints the results of the operation. If the user enters X, a method asks for two integers and finds the larger of the two. If the user enters S, a method asks for one value and finds the square of that value. If the user enters Q, the program stops. For each calculation performed, the method prints the operation requested, the user's original input, and the result. Note: All output must be sent to a file Sample Output: Operation: addition augend: 25 addend: 35 sum: 60 Write a program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one +, -,*,/,or% A X M S Q of the following: representing the usual arithmetic operators representing the average of two numbers representing the maximum of two numbers representing the minimum of two numbers representing the square of a number indicating the user wants to quit the program The program reads the user's response into a variable of type char. Using a switch statement, the program determines which method to call to process the user's request. For example, if the user enters +, a method is called which prompts the user to enter two integers. The method then finds the sum of the two integers and the method prints the results of the operation. If the user enters X, a method asks for two integers and finds the larger of the two. If the user enters S, a method asks for one value and finds the square of that value. If the user enters Q, the program stops. For each calculation performed, the method prints the operation requested, the user's original input, and the result. Note: All output must be sent to a file Sample Output: Operation: addition augend: 25 addend: 35 sum: 60Explanation / Answer
Please find the descriptive code in C language. Please note that the script is self-explanatory, with abundance of statements in support to print and display. One can modify the input and output formatting as per the requirment.
Hope this helps! if it wroks, please thumbs up!
==========================
#include<iostream>
#include<stdio.h>
using namespace std;
float addition(float a, float b)
{
return(a+b);
}
float subtraction(float a, float b)
{
return(a-b);
}
float multiplication(float a, float b)
{
return(a*b);
}
float division(float a, float b)
{
return(a/b);
}
int modulo(int a, int b)
{
return(a%b);
}
float average(float a, float b)
{
return((a+b)/2);
}
float maximum(float a, float b)
{
return(a>b?a:b);
}
float square(float a)
{
return(a*a);
}
int main()
{
char choice,mod='%';
float op1,op2;
int m1,m2;
printf("************ Opertion Menu ************ ");
printf("For Addition input + ");
printf("For Subtraction input - ");
printf("For Multiplication input * ");
printf("For Division input / ");
printf("For Modulo input %c ",mod);
printf("For Average of Two numbers input A ");
printf("For Maximum of Two numbers input M ");
printf("For Calculating the square of a number input S ");
printf("To quit input Q ");
printf(" Please input the choice of opertion code: ");
scanf("%c",&choice);
switch(choice)
{
case '+': printf("Please enter the operands for operand1 + operand2: ");
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operand 2: ");
scanf("%f",&op2);
printf("Operation requested: Addition(+) Operand-1: %f Operand-2: %f",op1,op2);
printf(" Result: %f ",addition(op1,op2));
break;
case '-': printf("Please enter the operands for operand1 - operand2: ");
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operand 2: ");
scanf("%f",&op2);
printf("Operation requested: Subtraction(-) Operand-1: %f Operand-2: %f",op1,op2);
printf(" Result: %f ",subtraction(op1,op2));
break;
case '*': printf("Please enter the operands for operand1 * operand2: ");
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operand 2: ");
scanf("%f",&op2);
printf("Operation requested: Multiplication(*) Operand-1: %f Operand-2: %f",op1,op2);
printf(" Result: %f ",multiplication(op1,op2));
break;
case '/': printf("Please enter the operands for operand1 / operand2: ");
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operand 1: ");
scanf("%f",&op2);
printf("Operation requested: Division(/) Operand-1: %f Operand-2: %f",op1,op2);
printf(" Result: %f ",division(op1,op2));
break;
case '%': printf("Please enter the operands for modulo(operand1,operand2): ");
printf("Operand 1: ");
scanf("%d",&m1);
printf("Operand 2: ");
scanf("%d",&m2);
printf("Operation requested: Modulo(%c) Operand-1: %d Operand-2: %d",mod,m1,m2);
printf(" Result: %d ",modulo(m1,m2));
break;
case 'A': printf("Please enter the operands for ((operand1 + operand2 )/2): ");
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operand 2: ");
scanf("%f",&op2);
printf("Operation requested: Average(A) Operand-1: %f Operand-2: %f",op1,op2);
printf(" Result: %f ",average(op1,op2));
break;
case 'M': printf("Please enter the operands for max(operand1,operand2): ");
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operand 1: ");
scanf("%f",&op1);
printf("Operation requested: Maximum(M) Operand-1: %f Operand-2: %f",op1,op2);
printf(" Result: %f ",maximum(op1,op2));
break;
case 'S': printf("Please enter the operands for square(operand): ");
printf("Operand : ");
scanf("%f",&op1);
printf("Operation requested: Square(S) Operand: %f",op1);
printf(" Result: %f ",square(op1));
break;
case 'Q': break;
}
system("PAUSE");
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.