You are on page 1of 20

DHARAMSINH DESAI UNIVERSITY , NADIAD.

Faculty of management and information science.


Department of MCA

ADVANCE PROGRAMMING TECHNIQUES - I


TERM-WORK

TOPIC: Calculator using C++ programming.


DATE : 02/05/2019
SUBMITTED BY : KARNIKA SHUKLA.
SEMESTER : MCA-II
ROLL NO.: MA021 (18MAPOG025)
SUBMITTED TO: Dr. Narayan a. joshi.
TOPIC: CALCULATOR

CODE:

#include <iostream>

#include <string.h>

#include <conio.h>

#include <math.h>

using namespace std;

class Scientific_cal

public:

float a,b;

int z;

void body()

cout<<"\n\t\t Scientific calculator opened..!!!\n"<<endl;

void Power(float x,float y)

float p;

p = pow(x,y);

cout<<"\t\tPower: "<<p;
}

void Sine(float x)

float s;

s = sin(x);

cout<<"\t\tSin: "<<s;

void Square(float x)

float sq;

sq = sqrt(x);

cout<<"\t\tSquare of a Given Value is: "<<sq;

void Cos(float x)

float c;

c = cos(x);

cout<<"\t\tCOS: "<<c;

void Tan(float x)

{
float t;

t = tan(x);

cout<<"\t\tTAN: "<<t;

void Log(float x)

float l;

l = log(x);

cout<<"\t\tNatural Logarithm: "<<l;

void Baselog(float x)

float bl;

bl = log10(x);

cout<<"\t\tLOG with Base 10: "<<bl;

};

class Simple_calc

public:

void Body()

{
cout << "\t\t Simple calculator opened..!! \n" << endl;

int Addition(int x, int y)

int ans = x + y;

return ans;

int Subtraction(int x, int y)

int ans = x - y;

return ans;

int Multiplication(int x, int y)

int ans = x * y;

return ans;

int Division(int x, int y)

int ans = x / y;

return ans;

};

class factorial{
int f, n;

public:

void fact()

f=1;

cout<<"\n\t\tEnter a Number:";

cin>>n;

for(int i=1;i<=n;i++)

f=f*i;

void display()

cout<<"\n\t\tFactorial of "<<n<<" is "<<f;

};

void scientific()

Scientific_cal key;

key.body();

int z;

float a;
float b;

cout<<"\t\t *********AVAILABLE FUNCTIIONS********* "<<endl;

cout<<"\t\t 1. Power. "<<endl;

cout<<"\t\t 2. Sin. "<<endl;

cout<<"\t\t 3. Square. "<<endl;

cout<<"\t\t 4. Cos. “<<endl;

cout<<"\t\t 5. Tan. "<<endl;

cout<<"\t\t 6. Log. "<<endl;

cout<<"\t\t 7. Base Log. "<<endl;

cout<<"\t\t **************************************\n"<<endl;

cout<<"\t\t WHAT YOU WANT TO FIND ? ";

cin>>z;

switch(z)

case 1:

cout<<"\t Enter the Number for Calculating its Power: ";

cin>>a;

cout<<endl;

cout<<"\t Enter the Power for a Number: ";

cin>>b;

key.Power(a,b);

break;

case 2:
cout<<"\t Enter the Number for Calculating SIN: ";

cin>>a;

key.Sine(a);

break;

case 3:

cout<<"\t Enter the Number for Calculating Square: ";

cin>>a;

key.Square(a);

break;

case 4:

cout<<"\t Enter the Number for Calculating COS: ";

cin>>a;

key.Cos(a);

break;

case 5:

cout<<"\t Enter the Number for Calculating TAN: ";

cin>>a;

key.Tan(a);

break;

case 6:

cout<<"\t Enter the Number for Calculating LOG: ";


cin>>a;

key.Log(a);

break;

case 7:

cout<<"\t Enter the Number for Calculating LOG WITH


BASE 10: ";

cin>>a;

key.Baselog(a);

break;

cout<<endl;

cout<<"\t\t Do you want to continue with scientific calc ? (y/n | Y/N) ";

char ch;

cin>>ch;

if(ch == 'Y' || ch == 'y')

scientific();

else

return;

void simple()

{
int func;

int x, y;

Simple_calc key;

key.Body();

cout << "\t\t *********AVAILABLE FUNCTIONS********* " << endl;

cout << "\t\t 1 - Addition " << endl;

cout << "\t\t 2 - Subtraction " << endl;

cout << "\t\t 3 - Multiplication " << endl;

cout << "\t\t 4 - Division " << endl;

cout << "\t\t**************************************"<<endl;

cout << "\t\t What function do you want to use? ";

cin >> func;

cout << endl;

switch(func)

case 1: //Addition

cout << "\t\t**ADDITION**" << endl;

cout << "\t\tPlease enter first number: " ;

cin >> x;

cout << "\t\tPlease enter second number: " ;


cin >> y;

cout<<endl<<"\t\t";

cout << x << " + " << y << " = ";

cout << key.Addition(x, y);

break;

case 2: //Subtraction

cout << "\t\t**SUBTRACTION**" << endl;

cout << "\t\tPlease enter first number: " ;

cin >> x;

cout << "\t\tPlease enter second number: " ;

cin >> y;

cout<<endl<<"\t\t";

cout << x << " - " << y << " = ";

cout << key.Subtraction(x, y);

break;

case 3: //Multiplication

cout << "\t\t**MULTIPLICATION**" << endl;

cout << "\t\tPlease enter first number: " ;

cin >> x;

cout << "\t\tPlease enter second number: " ;

cin >> y;

cout<<endl<<"\t\t";

cout << x << " x " << y << " = ";

cout << key.Multiplication(x, y);


break;

case 4: //Division

cout << "\t\t**DIVISION**" << endl;

cout << "\t\tPlease enter first number: " ;

cin >> x;

cout << "\t\tPlease enter second number: ";

cin >> y;

cout<<endl<<"\t\t";

cout << x << " / " << y << " = ";

cout << key.Division(x, y);

break;

default:

cout << "\t\tInvalid Input...";

break;

cout<<endl;

cout<<"\t\t Do you want to continue with simple calc ? (y/n | Y/N) ";

char ch;

cin>>ch;

if(ch == 'Y' || ch == 'y')

simple();

else

return;
}

void fact()

factorial ob;

ob.fact();

ob.display();

int main()

int n;

cout<<endl;

cout<<"\t\t ***************MENU*****************\n";

cout<<"\t * 1.Scientific calculator. *\n";

cout<<"\t\t * 2.Simple calculator. *\n";

cout<<"\t\t * 3.factorial. *\n";

cout<<"\t\t * 4.Exit. *\n";

cout<<"\t\t ************************************\n";

cout<<"\n\t\t Enter your choice : ";

cin>>n;

switch(n)

case 1:
scientific();

break;

case 2:

simple();

break;

case 3:

fact();

break;

case 4:

break;

default:

cout<<"\nInappropriate choice ..!!";

return 0;

}
OUTPUT:

1.
2.
3.
4.
5.
6.

You might also like