Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Name: R.

Sharvesh
Department: Computer Science and Engineering
College Name: Rajalakshmi Engineering College
AIM :
To construct a typical calculator
ALGORITHM:
Step 1: Start
Step 2: Obtain the two numbers from the user.
Step 3: Ask the user about the operation which is to be performed
upon them.
Step 4: Create user-defined functions for addition, subtraction,
multiplication, division and modulo.
Step 5: Perform the desired operation and produce the output to the
user using switch-case statement.
Step 6: Stop.
PROGRAM:
// program for a typical calculator
#include<iostream>
using namespace std;

int add(int j,int t); // addition function


int sub(int u,int v); // subtraction function
int mul(int w,int i); // multiplication function
int divn(int e,int f); // division function
int mod(int g,int h); // modulo function
int main() // main function
{
int x,y,z,a,s,m,d,r;
cout<<"enter the two numbers: ";
cin>>x>>y;
cout<<"press 1 to add, 2 to sub, 3 to mul, 4 to div or 5 to mod : ";
cin>>z;
switch(z) {
case 1:
a = add(x,y); // calling the function add
cout<<"the sum of the numbers is "<<a;
break;
case 2:
s = sub(x,y); // calling the function sub
cout<<"the difference of the numbers is "<<s;
break;
case 3:
m = mul(x,y); // calling the function mul
cout<<"the product of the numbers is "<<m;
break;
case 4:
d = divn(x,y); //calling the function divn
cout<<"the quotient of the numbers is "<<d;
break;
case 5:
r = mod(x,y); //calling the function mod
cout<<"the remainder of the two numbers is "<<r;
break;

return 0;
}

int add(int x,int y) {


int sum;
sum = x+y;
return sum;
}
int sub(int x,int y) {
int dif;
dif = x-y;
return dif;
}
int mul(int x,int y) {
int pro;
pro = x*y;
return pro;
}
int divn(int x,int y) {
int quo;
quo = x/y;
return quo;
}
int mod(int x,int y) {
int rem;
rem = x%y;
return rem;
}
SAMPLE INPUT/OUTPUT:
enter the two numbers: 100 50
press 1 to add, 2 to sub, 3 to mul, 4 to div or 5 to mod : 5
the remainder of the two numbers is 0

You might also like