/*write a c++ a menu driven program using class to perform all arithmetic
operation +,-*,/ using inline function*/
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
#include<float.h>
class arith
{
public:inline void add(int a,int b)
{
int c;
c=a+b;
cout<<"\nthe addition is:-"<<c;
}
inline void sub(int a,int b)
{
int c;
c=a-b;
cout<<"\nthe substraction is:-"<<c;
}
inline void mult(int a,int b)
{
int c;
c=a*b;
cout<<"\nthe multiplication is:-"<<c;
}
inline void div(int a,int b)
{
float c;
c=a/(b+0.0);
cout<<"\nthe division is:-"<<c;
}
};
int main()
{
arith a;
int ch,n1,n2;
clrscr();
while(1)
{
cout<<"\n1:addition";
cout<<"\n2:substraction";
cout<<"\n3:multiplication";
cout<<"\n4:division";
cout<<"\n5:exit";
cout<<"\nenter your choice:-";
cin>>ch;
switch(ch)
{
case 1:cout<<"\nenter two number";
cin>>n1>>n2;
a.add(n1,n2);
break;
case 2:cout<<"\nenter two number";
cin>>n1>>n2;
a.sub(n1,n2);
break;
case 3:cout<<"\nenter two number";
cin>>n1>>n2;
a.mult(n1,n2);
break;
case 4:cout<<"\nenter two number";
cin>>n1>>n2;
a.div(n1,n2);
break;
case 5:exit(0);
default:cout<<"\nyou entered wrong choice";
}
}
getch();
return 0;
}
/*enter your choice:-1
enter two number3 4
the addition is:-7
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-2
enter two number3 2
the substraction is:-1
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-3
enter two number4 5
the multiplication is:-20
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-4
enter two number4 6
the division is:-0.666667
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-6
you entered wrong choice
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-5
*/
operation +,-*,/ using inline function*/
#include<conio.h>
#include<stdlib.h>
#include<iostream.h>
#include<float.h>
class arith
{
public:inline void add(int a,int b)
{
int c;
c=a+b;
cout<<"\nthe addition is:-"<<c;
}
inline void sub(int a,int b)
{
int c;
c=a-b;
cout<<"\nthe substraction is:-"<<c;
}
inline void mult(int a,int b)
{
int c;
c=a*b;
cout<<"\nthe multiplication is:-"<<c;
}
inline void div(int a,int b)
{
float c;
c=a/(b+0.0);
cout<<"\nthe division is:-"<<c;
}
};
int main()
{
arith a;
int ch,n1,n2;
clrscr();
while(1)
{
cout<<"\n1:addition";
cout<<"\n2:substraction";
cout<<"\n3:multiplication";
cout<<"\n4:division";
cout<<"\n5:exit";
cout<<"\nenter your choice:-";
cin>>ch;
switch(ch)
{
case 1:cout<<"\nenter two number";
cin>>n1>>n2;
a.add(n1,n2);
break;
case 2:cout<<"\nenter two number";
cin>>n1>>n2;
a.sub(n1,n2);
break;
case 3:cout<<"\nenter two number";
cin>>n1>>n2;
a.mult(n1,n2);
break;
case 4:cout<<"\nenter two number";
cin>>n1>>n2;
a.div(n1,n2);
break;
case 5:exit(0);
default:cout<<"\nyou entered wrong choice";
}
}
getch();
return 0;
}
/*enter your choice:-1
enter two number3 4
the addition is:-7
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-2
enter two number3 2
the substraction is:-1
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-3
enter two number4 5
the multiplication is:-20
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-4
enter two number4 6
the division is:-0.666667
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-6
you entered wrong choice
1:addition
2:substraction
3:multiplication
4:division
5:exit
enter your choice:-5
*/
No comments:
Post a Comment