#include<iostream>
using namespace std;
class person //here i make 1st class name person
{
protected: //here i declare data members
string name;
int age;
public: //here i define mamber function
void getdata(string x,int y)
{
name=x;
age=y;
}
};
class student:virtual public person //here i make 2ed class name student and inherit with class person
{
protected: //here i declare data members
int rollno;
public: //here i define mamber function
void getdata(string x,int y,int z)
{
name=x;
age=y;
rollno=z;
}
};
class faculty:virtual public person //here i make 3ed class name faculty and inherit with class person
{
protected: //here i declare data members
string department;
public: //here i define mamber function
void getdata(string x,int y,string z)
{
name=x;
age=y;
department=z;
}
};
class TA:virtual public student,virtual public faculty//here i make 4th class name TA and inherit with class student and class faculty
{
private: //here i declare data members
int no;
public: //here i define mamber function
void getdata(string x,int y,string z,int b,int i)
{
name=x;
age=y;
department=z;
rollno=b;
no=i;
}
void putdata()
{
cout<<"your name is:"<<name<<endl;
cout<<"your age is:"<<age<<endl;
cout<<"your department is:"<<department<<endl;
cout<<"your roll no is:"<<rollno<<endl;
cout<<"your no is:"<<no<<endl;
}
};
int main()
{
TA obj1;
obj1.person::getdata("hamza",18);
obj1.student::getdata("hamza",18,4718);
obj1.faculty::getdata("hamza",18,"cs");
obj1.TA::getdata("hamza",18,"cs",4718,13);
obj1.putdata();
}
No comments:
Post a Comment