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

You should put comments in your take-home assignments. Solutions without comment

ID: 3683109 • Letter: Y

Question

You should put comments in your take-home assignments. Solutions without comments will be deducted 5 points in grade. Write a calculator program. The main menu will have the option to exit, and several options for mathematical operators. The program will continually loop until specified to exit. The program must contain the operations of division, squareroot (or squareroot in general), and one other of your choice. squareroot can be performed by including the math.h library, and usingthe sqrt () function. The user will input all variables. You must create 3 exception classes: one for handling the input stream fail state, one for divide by zero, and one for taking the squareroot of a negative number. Your program must check for the fail state every time the user enters something from the input stream. This is done by: if (! cin). If the input stream is in fail state throw the exception. You must also check if the user has tried to divide by zero, or squareroot a negative number, and throw the appropriate exception. Your program must have at least one try block (all of the throw calls should be in the try block). And it must have catch blocks for each of the three exceptions. Each block should report an appropriate message, and then allow the program to continue execution without exiting. The fail state catch block can resolve the issue with the following lines of code: cin.clear(); cin. ignore(1024, ' ');

Explanation / Answer

#include <iostream>
using namespace std;

class test
{
public:int x,y,sum;
float fsum;
void first()
{
cout<<"Enter first number ";
}
void second()
{
cout<<"Enter second number ";
}
int add()
{
sum=x+y;
cout<<sum;
}
int minus()
{
sum=x-y;
cout<<sum;
}
int mult()
{
sum=x*y;
cout<<sum;
}
int divide()
{
sum=x/y;
cout<<fsum;
}
};


int main()
{
test z;
int choice;
cout<<"1.Addition 2.Subtraction 3.Multiplication 4.Divition ";
cin>>choice;
switch (choice){
case 1:

z.first();
cin>>z.x;
z.second();
cin>>z.y;
z.add();
break;

case 2:
z.first();
cin>>z.x;
z.second();
cin>>z.y;
z.minus();
break;

case 3:
z.first();
cin>>z.x;
z.second();
cin>>z.y;
z.mult();
break;

case 4:
z.first();
cin>>z.x;
z.second();
cin>>z.y;
z.divide();
break;
}
return 0;
}

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