0
Clear code error
#include <iostream> using namespace std; class addition public : { Void add (int a,int b,int c) { c=a+b; } }; public subtract :public addition; { Void sub (int d,int e) { e=c-d; } }; int main() { subtn.s; s.add ; s.sub; cout <<"enter the add: "; cin >>a+b; cout <<"the value of add "<<c; cout <<"enter the sub: "; cin >>d; cout <<"the value of sub "<<e; return 0; }
3 Antworten
+ 1
// Probably you need something like that:
#include <iostream>
using namespace std;
class Addition {
public:
int c;
int add (int a,int b) {
return a+b;
}
};
class Subtract : public Addition {
public:
int sub(int d) {
return c-d;
}
};
int main() {
Subtract s;
int a,b,d;
cout <<"enter the add: ";
cin >> a;
cin >> b;
cout << a << " + " << b << endl;
s.c = s.add(a,b);
cout <<"the value of add "<< s.c << endl;
cout <<"enter the sub: ";
cin >> d;
cout << "you entered sub: " << d << endl;
cout <<"the value of sub "<< s.sub(d) << endl;
return 0;
}
0
where you denote C
0
It is a field in class Addition