inheritance

i am a semi beginner learning about inheritance can someone tell me why the name and re_no would not appear in the output please??


// assignment.cpp : Defines the entry point for the console application.


#include <iostream>
#include <string>
using namespace std;

class student{
public:
int reg_no;
protected:
string name;

public:
void get_det(){
cout<<"Please input your name:\n";
getline(cin,name);
cout<<"Please enter 1 for BSc.informatics or 2 for BTC(telecommunications)"<<endl;
cin>>reg_no;
while(reg_no>2||reg_no<1){cout<<"error!\n";
break;
}

}};

class informatics: public student{
public:
int devt;
int in4matx;
int data;
public:
void getter(){
cout<<"Please input your marks for Development studies:\n";
cin>>devt;
cout<<"Please input your marks for Informatics unit\n";
cin>>in4matx;
cout<<"Please input your marks for Data networking\n";
cin>>data;
cout<<"Your name is\n"<<name<<" registration number"<<reg_no<<endl; }

};
class btc: public student{
public:
int max;
int mod;
public:
void getter(){
cout<<"Please input your marks for Telecommunications unit\n";
cin>>max;
cout<<"Please input your marks for Data modulation\n";
cin>>mod;
cout<<"Your name is:\n"<<name<<" registration number"<<reg_no<<endl;
}
};


int main(){
student p;
informatics s;
btc c;
p.get_det();
if (p.reg_no==1){
s.getter();
cout<<"These are the marks you have given please verify:\n";
cout<<s.devt<<endl<<s.in4matx<<endl<<s.data<<endl;
}
else if(p.reg_no==2){
c.getter();
cout<<"These are the marks you have given please verify:\n";
cout<<c.max<<endl<<c.mod;
}
else
cout<<" you have entered a wrong registration number\n";
system ("pause");
return 0;
}

In your code p, s and c and three completely different objects. You are setting the values of name and reg for p but you are not setting these for s & c.
You did not entered values of name and reg_no fpr object c of type btc. To get the values you should call

c.get_det();

Objects p and c are two different objects and have no relation.
okay ill do tht thnx a lot.
Topic archived. No new replies allowed.