Wednesday, March 4, 2009

Calculator Sample using Class in

An idea how to make calculator.
here is link for source code
Calculator using class.rar
included .cpp & .exe files
#include
#include
class a{
private:
double b;
double c;
double ans;
public:
a(){
b=0;
c=0;
ans=0;
}
void setb(double k){
b=k;
}
double getb(){
return b;
}
void setc(double k){
c=k;
}
double getc(){
return c;
}
void setans(double k){
ans=k;
}
double getans(){
return ans;
}


double adition (double a,double b)
{
double c=0;
c=a+b;
return c;
}
double subtraction(double a,double b)
{
double c=0;
c=a-b;
return c;
}
double multiplication(double a,double b)
{
double c=0;
c=a*b;
return c;
}
double divition(double a,double b)
{
double c;
c=a/b;
return c;
}
};

void main()
{
double b1=0;
double c1=0;
char ch;
a obj;
cout<cin>>b1;
obj.setb(b1);
cout<cin>>c1;
obj.setc(c1);
cout<cin>>ch;
if(ch=='+')
{
obj.setans(obj.adition(obj.getb(),obj.getc()));
cout<}
else if(ch=='-')
{
obj.setans(obj.subtraction(obj.getb(),obj.getc()));
cout<}
else if(ch=='*')
{
obj.setans(obj.multiplication(obj.getb(),obj.getc()));
cout<}
else if(ch=='/')
{
if(obj.getc()!=0)
{
obj.setans(obj.divition(obj.getb(),obj.getc()));
cout<}
if(obj.getc()==0)
cout<}
else{
cout<}
getch();
}

No comments:

Post a Comment