Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We completed the calculator project 2 weeks ago. Here is the second phase: Your

ID: 674880 • Letter: W

Question

We completed the calculator project 2 weeks ago. Here is the second phase:

Your calculator program should now display a menu like this:

Choose a calculator:

1) Standard

2) Scientific

3) Trigonometric

Choice: __

If the user selects standard by entering 1, you will show a message:

Please enter your calculation is the following format a+b, For example if you want to add 5 and 2 together, you type 5+2:

So now your user can enter their calculations. You will use cin statements to read one float, one char and one float (in this order). Then you will use a switch case statement that uses the char variable to decide which operation to perform. So for example:

switch(op)

{

case '+':

cout << a+b << endl;

break;

case '-': ....

}

If your user chooses the scientific calculator, your program will show another menu such as :

1) log

2) sqrt

3) power

Depending on the operation, you will ask the user to enter the correct set of variables. For example, for power you need a number and a power, for sqrt you only need 1 number. You can use if-elseif-else for the scientific calculator

If your user chooses the trigonometric calculator, your program will first ask if the values are in degree or radians. C++ functions expect radians as input. Therefore, if your user selects degrees, you will take the input and convert to radians before calculating the results. In either case, the program should show a menu such as :

1) sine

2) cosine

3) tan

Choice:

Once you have all the information, you can proceed to do the calculations and output results.

Explanation / Answer

The below is the c program for creating a calculator for menu. Use this code for getting the menu for a calculator and implement the respective type of calculator code in that respective calling function.Below i also written the codes for 3 types of calculator you asked. All you need to do is that you just have to integrate the code.

Menu driven calculator:

#include<stdio.h>

#include<conio.h>

void main()

{

int a,b,c,ch;

clrscr();

printf(“ 1.add 2.subtract 3.multiply 4.division 5.remainder );

printf(“ enter your choice ”);

scanf(%d”,&ch);

switch(ch)

{

case1:

printf(“ enter values of a and b ”);

scanf(%d%d”,&a,&b);

c=a+b;

printf(“ the answer is %d”,c);

break;

case2:

printf(“ enter values of a and b ”);

scanf(%d%d”,&a,&b);

c=a-b;

printf(“ the answer is %d”,c);

break;

case3:

printf(“ enter values of a and b ”);

scanf(%d%d”,&a,&b);

c=a*b;

printf(“ the answer is %d”,c);

break;

case4:

printf(“ enter values of a and b ”);

scanf(%d%d”,&a,&b);

c=a/b;

printf(“ the answer is %d”,c);

break;

case5:

printf(“ enter values of a and b ”);

scanf(%d%d”,&a,&b);

c=a%b;

printf(“ the answer is %d”,c);

break;

default:

printf(“ enter the correct choice”);

break;

}

getch();

}

Output:

1.add

2.subtract

3.multiply

4.division

5.remainder

enter your choice

2

enter the values of a and b

7

4

the answer is 3

1) Standard

int main()

2) Scientific

3) Trigonometric

#include <stdio.h>

#include <string>

#include <iostream>

#include <cmath>

#include <algorithm>

#include <fstream>

using namespace std;

void welcome();

float decision(string);

float sides(float &, float &, float &, float &, float &);

int main(int argc, char *argv[])

{

welcome();

return 0;

}

void welcome(){

int menu;

float valuea;

float valueb;

float valuec;

float valueao;

float valuebo;

float valueco;

cout << "Trig Calculator" << endl << endl;

cout << "Select problem type 1. Right angle triangle" << endl;

cin >> menu;

switch(menu){

case 1:

cout << "If you do not know the value use 0. ";

valuea = decision("Do you know side A? ");

valueb = decision("Do you know side B? ");

valuec = decision("Do you know side C? ");

valueao = decision("Do you know angle A? ");

valuebo = decision("Do you know angle B? ");

sides(valuea, valueb, valuec, valueao, valuebo);

cout << " Triangle calculated: ";

cout << "Side A: " << valuea << endl;

cout << "Side B: " << valueb << endl;

cout << "Side C: " << valuec << endl;

cout << "Angle A: " << valueao << endl;

cout << "Angle B: " << valuebo << endl << endl;

welcome();

}

}

float decision(string question){

float value;

float radian = 3.1415/180;

cout << question;

cin >> value;

return value;

}

float sides(float &a, float &b, float &c, float &ao, float &bo){

float radian = 3.1415/180;

if(a !=0 && b!=0 && c==0){

c = sqrt(a * a + b * b);

}

if(a !=0 && c!=0 && b==0){

b = sqrt(c * c - a * a);

}

if(a ==0 && c!=0 && b!=0){

a = sqrt(c * c - b * b);

}

//TAN with side A

if(a!= 0 && b==0 && c==0){

if(ao !=0){

b = a/tan(ao*radian);

if(bo == 0){

bo = 90-ao;

}

}

if(bo !=0){

b = a*tan(bo*radian);

if(ao == 0){

ao = 90-bo;

}

}

c = sqrt((a*a)+(b*b));

}

//tan with sideB

if(a == 0 && b!=0 && c==0){

if(ao !=0){

a = b*tan(bo*radian);

if(bo == 0){

bo = 90-ao;

}

}

if(bo !=0){

a = b/tan(bo*radian);

if(ao == 0){

ao = 90-bo;

}

}

c = sqrt((a*a)+(b*b));

}

//sin with sideC

if(a == 0 && b==0 && c!=0){

if(ao !=0){

a = c*sin(ao*radian);

if(bo == 0){

bo = 90-ao;

}

}

if(bo !=0){

a = c*cos(bo*radian);

if(ao == 0){

ao = 90-bo;

}

}

b = sqrt((c*c)+(a*a));

}

if(ao == 0 && bo ==0){

ao = atan(a/b)*180/3.141592654;

bo = 90 - ao;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote