Hi guys!the program below is of a small standard calculator.
It is a program by passing a reference to a function..
If this program give errors please let me know,i am ready to help any time..
May this program helps you alot!!
#include<iostream>
#include<conio.h>
using namespace std;
char op;
void add(double, double,char );
void sub(double, double,char);
void mul(double, double,char);
void div(double, double,char);
main()
{
double num1,num2;
char op;
cout<<"Enter 1st number:";
cin>>num1;
cout<<"Enter 2nd number:";
cin>>num2;
cout<<"Tell the operation:";
cin>>op;
add(&num1,&num2,&op);
getch();
return 0;
}
void add(double *a, double *b)
{
switch(op)
{
case 1:
cout<<"Sum is:"<<*a+*b;
break;
case 2:
sub(&a,&b);
break;
case 3:
mul(&a,&b);
break;
case 4:
div(&a,&b);
break;
default:
cout<<"operation not available"
}
}
void sub(double *c, double *d)
{
cout<<"Difference is:"<<*c-*d;
}
void mul(double *e, double *f)
{
cout<<"Product is:"<<*e**f;
}
void div(double *g, double *h)
{
cout<<"Quotient is:"<<*g / *h;
}
It is a program by passing a reference to a function..
If this program give errors please let me know,i am ready to help any time..
May this program helps you alot!!
#include<iostream>
#include<conio.h>
using namespace std;
char op;
void add(double, double,char );
void sub(double, double,char);
void mul(double, double,char);
void div(double, double,char);
main()
{
double num1,num2;
char op;
cout<<"Enter 1st number:";
cin>>num1;
cout<<"Enter 2nd number:";
cin>>num2;
cout<<"Tell the operation:";
cin>>op;
add(&num1,&num2,&op);
getch();
return 0;
}
void add(double *a, double *b)
{
switch(op)
{
case 1:
cout<<"Sum is:"<<*a+*b;
break;
case 2:
sub(&a,&b);
break;
case 3:
mul(&a,&b);
break;
case 4:
div(&a,&b);
break;
default:
cout<<"operation not available"
}
}
void sub(double *c, double *d)
{
cout<<"Difference is:"<<*c-*d;
}
void mul(double *e, double *f)
{
cout<<"Product is:"<<*e**f;
}
void div(double *g, double *h)
{
cout<<"Quotient is:"<<*g / *h;
}
No comments:
Post a Comment