Jan 15, 2013 at 7:15pm UTC
#include<iostream>
using namespace std;
class person
{
protected:
int id;
char name[50];
char add[100];
public:
void get_info();
void show_info();
person();
};
void person::get_info()
{
cout<<"enter your ID:"<<endl;
cin>>id;
cout<<"enter your name:"<<endl;
cin.get(name,50);
cout<<"enter your address:"<<endl;
cin.get(add,100);
}
void person::show_info()
{
cout<<"id:"<<id<<endl;
cout<<"name:"<<name<<endl;
cout<<"address"<<add<<endl;
}
person::person()
{
id=0;
name[0]='\0';
add[0]='\0';
}
class student:public person
{
private:
int rno;
int marks;
public:
void get_infos();
void show_infos();
student();
};
student::student()
{
rno=0;
marks=0;
}
void student::get_infos()
{
cout<<"enter your roll no:"<<endl;
cin>>rno;
cout<<"enter your marks:"<<endl;
cin>>marks;
}
void student::show_infos()
{
cout<<"roll no:"<<rno<<endl;
cout<<"marks:"<<marks<<endl;
}
int main()
{
student s;
s.get_info();
s.get_infos();
s.show_info();
s.show_infos();
return 0;
}
Last edited on Jan 15, 2013 at 7:25pm UTC
Jan 15, 2013 at 7:31pm UTC
it is not getting inputs for the object
Jan 15, 2013 at 8:21pm UTC
Don't forget to put cin.ignore()
after line 30
and after line 66 if you want to display the results.
Otherwise your console will exit without displaying the input...