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

#include <iostream> #include <math.h> #define PI 3.141592654 using namespace std

ID: 3760845 • Letter: #

Question

#include <iostream>

#include <math.h>

#define PI 3.141592654

using namespace std;

int main()

{

double op1;

double op2;

int choice1,choice2,choice3;

char op;

char rd;

double angle;

cout<<"Choose a calculator: 1) Standard 2) Scientific 3) Trigonometric Choice: ";

cin>> choice1;

if(choice1 == 1)

{

cout<<"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: ";

cin>>op1>>op>>op2;

switch(op)

   {

case '+':

   cout << op1+op2<<endl;

break;

case '*':

   cout <<op1*op2<<endl;

break;

case '-':

   cout<<op1-op2<<endl;

break;

case '/':

   cout<<op1/op2<<endl;

break;

}

}

  

if(choice1 == 2)

{

cout<<" 1) log 2) sqrt 3) power Choice: ";

cin>>choice2;

if(choice2 == 1

   ){

cout<<"Enter 1 value: ";

cin>>op1;

cout<<log(op1)<<endl;

}

if(choice2 == 2)

   {

cout<<"Enter 1 value: ";

cin>>op1;

cout<<sqrt(op1)<<endl;

}

if(choice2 == 3)

   {

cout<<"Enter 2 values: ";

cin>>op1>>op2;

cout<<pow(op1,op2)<<endl;

}

}

if(choice1 == 3)

{

cout<<"Radians (r) or degrees (d): ";

cin>>rd;

cout<<" 1) sine 2) cosine 3) tan Choice: ";

cin>>choice3;

cout<<"Enter value: ";

cin>>angle;

if(rd == 'd')

   angle = angle * PI/180.0;

if(choice3 == 1)

   cout<<sin(angle)<<endl;

if(choice3 == 2)

   cout<<cos(angle)<<endl;

if(choice3 == 3)

   cout<<tan(angle)<<endl;

  

}

return 0;

}

Now that you finished the calculatior 1.0, you are ready to improve it more.First you will use input validation, second you will test programs and present test results.

(A) This time you will use while and/or do while loops for two things

1) Input validation. Each input needs to be validated to check if it was acceptable. if not, you give the user another chance to try again

2) The program menu should now have a Wuit option. The program should end only when the user chooses the Quit option

Everything else in the program remains the way it is except for these enhancements.

If you already implemented all of this, you may resubmit the program the way it is.

Once you finish the program, you will be asked to tests another student's program. The testing instructions will be posted soon

Explanation / Answer

#include <iostream>

#include <math.h>

#define PI 3.141592654

using namespace std;


int main()

{


double op1;

double op2;

int choice1,choice2,choice3;

char op;

char rd;

double angle;


cout<<"Choose a calculator: 1) Standard 2) Scientific 3) Trigonometric 4) Quit Choice: ";

cin>> choice1;
while(choice1>4 || choice1<1)
{
   cout<<"invalid choice.Enter Again"<<endl;
      cin>> choice1;

}
while(choice1 !=4)
{
if(choice1 == 1)

{

    cout<<"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: ";

    cin>>op1>>op>>op2;
while(op=='/'&& op2==0)
{
   cout<<"Second operand can not be 0 in case of division. Please enter correct input"<<endl;
      
        cin>>op2;

}
while(op!='+' && op!='-'&&op!='*'&&op!='/')
{
  
   cout<<"Invalid operator. Please input again "<<endl;
   cin>>op;
}
    switch(op)

    {

    case '+':{

    cout << op1+op2<<endl;

      break;
}
    case '*':
{
    cout <<op1*op2<<endl;

      break;
}
    case '-':
    {

    cout<<op1-op2<<endl;

      break;
    }

    case '/':{
    cout<<op1/op2<<endl;}

      break;
}
    }
    if(choice1 == 2)

{

    cout<<" 1) log 2) sqrt 3) power Choice: ";

    cin>>choice2;
    while(choice2>3 || choice2<1)
    {
       cout<<"Invalid Choice. input again"<<endl;
       cin>>choice2;
    }

    if(choice2 == 1){

      cout<<"Enter 1 value: ";

      cin>>op1;
      while(op1<=0){
      cout<<"Enter Positive number"<<endl;
      cin>>op1;
      }

      cout<<log(op1)<<endl;

    }

    if(choice2 == 2)

    {

      cout<<"Enter 1 value: ";

      cin>>op1;
    
while(op1<=0){
      cout<<"Enter Positive number"<<endl;
      cin>>op1;
      }
      cout<<sqrt(op1)<<endl;

    }

    if(choice2 == 3)

    {

      cout<<"Enter 2 values: ";

      cin>>op1>>op2;
    
      cout<<pow(op1,op2)<<endl;

    }

}
if(choice1 == 3)

{

      cout<<"Radians (r) or degrees (d): ";

      cin>>rd;
      while(rd!='r' || rd!='d')
      {
         cout<<"Invalid value. Input Again"<<endl;
         cin>>rd;
      }

      cout<<" 1) sine 2) cosine 3) tan Choice: ";

      cin>>choice3;
      while(choice3<1 || choice3>3)
      {
         cout<<"Invalid choice. Input Again"<<endl;
         cin>>choice3;
        
      }

      cout<<"Enter value: ";

      cin>>angle;

      if(rd == 'd')

    angle = angle * PI/180.0;

      if(choice3 == 1)

    cout<<sin(angle)<<endl;

      if(choice3 == 2)

    cout<<cos(angle)<<endl;

      if(choice3 == 3)

    cout<<tan(angle)<<endl;

    

}
cout<<"Choose a calculator: 1) Standard 2) Scientific 3) Trigonometric 4) Quit Choice: "<<endl;

cin>>choice1;
}

return 0;

}