Simple console application Calculator (C++)

#include <iostream>

#include <iomanip>

#include <string>

#include <math.h>

using namespace std;

 

class Calculator

{

private : double Mem;

public:

Calculator()

{

Mem=0;

};

public  : double Add(float A,float B)

{

double Add_Total;

Add_Total=A+B;

return Add_Total;

}

 

public  : float Subb(float A,float B)

{

float Subb_Total;

Subb_Total=A-B;

return Subb_Total;

}

public  : double Mul(float A,float B)

{

double Mul_Total;

Mul_Total=A*B;

return Mul_Total;

}

public  : float Div(float A,float B)

{

float Div_Total;

bool check;

Div_Total=A/B;

check=isnan(Div_Total);

if(check==0)

return 0;

else

return Div_Total;

}

 

public  : int Mod(int A,int B)

{

int Div_Total;

Div_Total=A % B;

return Div_Total;

}

public  : void Set(double A)

{

Mem=A;

}

public  : double Get()

{

return Mem;

}

 

public : bool isnan(double x)

{

return (x <= DBL_MAX && x >= -DBL_MAX);

}

 

};

 

int main()

{

 

Calculator C_Obj;

string Y=”1″;

cout<<“Welcome to the simple calculator”<<endl;

do

{

cout<<“press “<<endl<<+

“[1] to Add”<<endl<< +

“[2] Subtract”<<endl<<+

“[3] Multiply”<<endl<< +

“[4] Divide”<<endl <<+

“[5] Modulus”<<endl<<+

“[6] Print Memory”<<endl<< +

“[0] Exit”<<endl;

float A,B;

double answer;

int option=0;

cin>>option;

switch(option)

{

case  1 :

cout<<“Enter two values to be added”<<endl;

cin>>A;

cin>>B;

answer=C_Obj.Add(A,B);

cout<<“The Addition of both values gives the output :  “<<answer<<endl;

C_Obj.Set(answer);

break;

case  2 :

cout<<“Enter two values to be Subtracted”<<endl;

cin>>A;

cin>>B;

answer=C_Obj.Subb(A,B);

cout<<“The Subbtraction of both values gives the output :  “<<answer<<endl;

C_Obj.Set(answer);

break;

case  3 :

cout<<“Enter two values to be Multiplied”<<endl;

cin>>A;

cin>>B;

answer=C_Obj.Mul(A,B);

cout<<“The Multiplication of both values gives the output :  “<<answer<<endl;

C_Obj.Set(answer);

break;

 

case  4 :

cout<<“Enter two values to be divided”<<endl;

cin>>A;

cin>>B;

answer=C_Obj.Div(A,B);

cout<<“The Division of both values gives the output :  “<<answer<<endl;

C_Obj.Set(answer);

break;

case 5:

cout<<“Enter two values to be Mod”<<endl;

int A1,B2;

cin>>A1;

cin>>B2;

answer=C_Obj.Mod(A1,B2);

cout<<“The Modulus of both values gives the output :  “<<answer<<endl;

C_Obj.Set(answer);

break;

 

case 6:

answer=C_Obj.Get();

cout<<“The Latest value set is : “<<answer<<endl;

break;

case 0:

Y=”0”;

break;

default:

cout<<“In Valid Option”<<endl;

}

}

while(Y!=”0”);

 

}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s