0% found this document useful (0 votes)
106 views

Calculator Made in C++ Using Function

This document contains code for a calculator program written in C++. It defines functions for addition, subtraction, multiplication, division, square, cube, sine, cosine, and tangent. The main function uses an if/else statement to call the appropriate function based on the user's input selection and displays the calculation result. Functions are used to modularize the code and make it more organized and readable.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Calculator Made in C++ Using Function

This document contains code for a calculator program written in C++. It defines functions for addition, subtraction, multiplication, division, square, cube, sine, cosine, and tangent. The main function uses an if/else statement to call the appropriate function based on the user's input selection and displays the calculation result. Functions are used to modularize the code and make it more organized and readable.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Submitted To: Sir NaveedYasir

Submitted By: M. Rehan Tariq


Subject Of: Programming Fundamentals
Campus Name: UON (OLD Campus)
Semester: First Semester BS CS (Evening)

Assignment Of PROGRAMMING FUNDAMENTALS

Calculator made in C++ Using


Function
How To Code A Calculator Using Function:
#include<iostream>
#include<math.h>
Using namespace std;
int function(a,b){return(a*b);}
\\here we put the function of subtraction;
int sub(){int a,b;
cout<<“Enter your First And Second Number”<<endl;
cin>>a>>b;
cout<<“Subtraction of the given numbers is: ”<<a-b<<endl;}
\\here we put the function of addition;
int add(){int a,b;
cout<<“Enter your First And Second Number”<<endl;
cin>>a>>b;
cout<<“Addition of the given numbers is: ”<<a+b<<endl;}
\\here we put the function of Multiplication;
int prod(){int a,b;
cout<<“Enter your First And Second Number”<<endl;
cin>>a>>b;
cout<<“Product of the given numbers is: ”<<a*b<<endl;}
\\here we put the function of Division;
int div(){int a,b;
cout<<“Enter Numenator And Denomenator”<<endl;
cin>>a>>b;
cout<<“Division of the given numbers is: ”<<a/b<<endl;}
\\here we put the function of Cube;
int cube(){int a;
cout<<“Enter your Number”<<endl;
cin>>a;
cout<<“Cube of the given number is: ”<<a*a*a<<endl;}
\\here we put the function of Square;
int squar(){int a;
cout<<“Enter your Number”<<endl;
cin>>a;
cout<<“Square of the given number is: ”<<a*a<<endl;}
\\here we put the function of Multiplication;
int prod(){int a,b;
cout<<“Enter your First And Second Number”<<endl;
cin>>a>>b;
cout<<“Product of the given numbers is: ”<<a*b<<endl;}
\\here we put the functions of Trignometry;
int trigonometric(){int a,b;
cout<<"Enter Angle of Sin In Degree "<<endl;
cin>>a;
b = sin(a);
cout<<" Your Sin"<<a<<" = "<<b<<endl;}
int cos(){int a,b;
cout<<"Enter Angle of Cos in Degree "<<endl;
cin>>a;
b = cos(a);
cout<<"Your cos"<<a<<" = "<<b<<endl;}
int tan(){int a,b;
cout<<"Enter Tan angle in Degree: "<<endl;
cin>>a;
b = tan(a);
cout<<"Your tan"<<a<<" = "<<b<<endl;}

int main(){int o;
cout<<"Select Any Operation "<<endl;
cout<<"Enter 1 for Sum "<<endl;
cout<<"Enter 2 for Product "<<endl;
cout<<"Enter 3 for Division "<<endl;
cout<<"Enter 4 for Subtraction "<<endl;
cout<<"Enter 5 for Square "<<endl;
cout<<"Enter 6 for Cube "<<endl;
cout<<"Enter 7 for Sin function Value:"<<endl;
cout<<"Enter 8 for Cos function Value: "<<endl;
cout<<"Enter 9 for tan function Value: "<<endl;
cin>>o;
if(o == 1){add();}
else if(o == 2){prod();}
else if(o == 3){div();}
else if(o == 4){sub();}
else if(o == 5){squar();}
else if(o == 6){cube();}
else if(o == 7){trigonometric();}
else if(o == 8){cos();}
else if(o == 9){tan();}
return 0;}

You might also like