0
can anyone help?
what's wrong in this code? i want to print teacher sub,publication,name,id using inheritance but it tells me wrong why? https://code.sololearn.com/csFnO6gq6VYH/?ref=app
19 Antworten
+ 6
rakib.id=1012;
ID is not yet a property of one of the objects.
if you want a teacher, you need to declare one.
staff rakib; // rakikb is a staff member
teacher t1; //t1 is a teacher, this object does have the property pub
char is just one character
since you have referenced std, you can use "string" to declare the name
+ 3
You need to write you code in the playground first before you can show it
https://code.sololearn.com/c19CQV3zNo9p.
+ 3
found the solution...
thank you guys..
actually i'm new in solo...
+ 2
If you want to post long codes, please write it in code playground and then share it here. Plain text is harder to read.
+ 2
Click on edit post, there should be a + sign at the bottom, click on it and select 'insert code'
+ 2
Okay, the problem in your code is that your class has no member named id, code...etc. you must first define them inside your class before assigning them
+ 1
ok.. thanks for advising..
+ 1
but how i could share my code here?
+ 1
done
+ 1
oh.. now it make sense.. thank you
+ 1
Welcome in Sololearn, Keep asking, Keep Coding.
Have fun in the playground.
0
😂
0
You using int main so in last use return zero ok
0
ممكن احد يشرح لي البرنامج 👀
0
Check id variable
0
#include<iostream>
#include<conio.h>
using namespace std;
class staff{
public:
// char name;
string name;
int code;
int pub;
void display1(){
cout<<name<<endl;
cout<<code<<endl;
}
};
class teacher:public staff
{
public:
int pub;
char sub;
void display2(){
cout<<pub<<endl;
cout<<sub<<endl;
display1();
}
};
class officer:public staff
{
char grade;
void display3(){
cout<<grade<<endl;
}
};
int main(){
cout << "print staff"<<endl;
staff rakib;
//rakib.id=1012;
rakib.code=222;
rakib.pub=04;
// rakib.sub="eee";
rakib.name="hasan_rakib";
rakib.display1();
//getch();
cout << "print teacher"<<endl;
teacher t1;
t1.code=333;
t1.pub=04;
t1.sub='e';
t1.name="hakim";
t1.display1();
t1.display2();
//getch();
}
0
hi
0
Glad to see yo
- 1
Hi