Answer» #include #include using namespace std; class calc { private :
public : double add(double ,double ); }
double calc:: add(double x ,double y) { double sum=0; sum=a+b; return sum; }
int main() { calc c1; int x; double a,b; do { cout<<"1. add"; cout<<"enter ur choice ::::;"; CIN>>x; switch(x) { case 1:
double sum=0; cout<<"enter 1ST value::::"; cin>>a; cout<<"enter the 2nd no.:::;"; cin>>b; sum=( c1.add(a,b)); cout<<"value of sum is ::::"< }
} while(1);
} PLS REPLY .............. WATS MY FAULT .................Well I'm no expert at programming, but you haven't said what the problem is, what error you got, how you know it doesn't work etc.Not a C++ programmer but I compiled your code with DEV-CPP which flagged:
Code: [Select]double calc:: add(double x ,double y) { double sum=0; sum=a+b; return sum; }
15 new types may not be defined in a return type 15 two or more data types in DECLARATION of `add' 15 prototype for `calc calc::add(double, double)' does not match any in class `calc'
There were other errors, but sometimes fixing one, will clear up the others. As mentioned, what error did you get and what compiler are you using? Programming can be very technical so the more details the better.
Few things (errors) caught my eye...
- In the declaration of Calc::Add(double x, double y) the add function receives x and y but you assign the sum of a and b (which are not declared) to the variable sum.
- There should be a ; at the end of the class (i.e. after the }).
- Since the Switch-Case statement supports multiple cases, you need to use a 'break;' after each case.
I might not have listed all the errors.. but I have put up the corrected code which runs...
Code: [Select]#include<iostream> #include<math.h>
using namespace std;
class calc { private:
public : double add(double ,double ); };
double calc::add(double x ,double y) { double sum=0; sum=x+y; return sum; }
int main() { calc c1; int x; double a,b; do { cout<<"1. add";
cout<<"enter ur choice ::::;"; cin>>x; switch(x) { case 1:
double sum=0; cout<<"enter 1st value::::"; cin>>a; cout<<"enter the 2nd no.:::;"; cin>>b; sum=( c1.add(a,b)); cout<<"value of sum is ::::"<<sum<<endl; }
} while(1);
}
There should be a way to exit the do-while loop.
Looking at the code, it SEEMS that you have JUMPED too fast to understand the basic concepts correctly and this is not good.
|