الاثنين، 25 نوفمبر 2013
11:55 ص

staff (Inheritance) in ++C

2) An educational institution wishes to maintain a database of its employees. The database is divided into a number of classes whose hierarchical relationships are shown the figure below. The figure also shows the minimum information required for each class. Specify all the classes and define functions to create the 
database and retrieve individual information as and when required.
3) The database created in question 2 does not include educational information
of the staff. It has been decided to add this information to teachers and
officers (and not for typists) which will help the management in decision
making with regard to training, promotion, etc. Add another class called
education that holds two pieces of educational information, namely, highest
educational qualification and highest professional qualification. This class
should be inherited by the classes teacher and officer. Modify the program
of question 2 to incorporate these additions.

Q2:

#include "stdafx.h"

#include<iostream>

using namespace std;
class staff
{
protected:
int code;
char name[20];
public:
virtual void input() 
{
cout<<"\n Name  ";
cin>>name;
cout<<"\n Code  ";
cin>>code;
}
virtual void output()
{
cout<<"\n Name "<<name;
cout<<"\n Code "<<code;
}
int get_code()
{
return code;
}
};
class teacher:public staff
{
char subject[30];
int publication;
public:
void input()
{
cout<<"\n Name  ";
cin>>name;
cout<<"\n Code  ";
cin>>code;
cout<<"\n subject  ";
cin>>subject;
cout<<"\n publication  ";
cin>>publication;
}
void output()
{
cout<<"\n Name "<<name;
cout<<"\n Code "<<code;
cout<<"\n subject "<<subject;
cout<<"\n publication "<<publication;
}
};
class officer:public staff
{
int grade;
public:
void input()
{
cout<<"\n Name  ";
cin>>name;
cout<<"\n Code  ";
cin>>code;
cout<<"\n Grade  ";
cin>>grade;
}
void output()
{
cout<<"\n Name "<<name;
cout<<"\n Code "<<code;
cout<<"\n Grade "<<grade;
}
};
class typist:public staff
{

int speed;
public:
void input()
{
cout<<"\n Name  ";
cin>>name;
cout<<"\n Code  ";
cin>>code;
cout<<"\n Speed  ";
cin>>speed;
}
void output()
{
cout<<"\n Name "<<name;
cout<<"\n Code "<<code;
cout<<"\n Speed "<<speed;
}
};
class casual:public typist
{
float daily_wages;
public:
void input()
{
cout<<"\n Daily_wages  ";
cin>>daily_wages;
}
void output()
{
cout<<"\n Daily_wages "<<daily_wages;
}
};
class regular:public typist
{
};
void main()
{
staff s;
teacher tech;
officer off;
typist typ;
casual cas;
regular reg;
staff *ss=&s;

cout<<"\n\n Teacher ";
ss=&tech;
ss->input ();
ss->output ();

cout<<"\n\n Officer ";
ss=&off;
ss->input ();
ss->output ();
cout<<"\n\n Typist ";
ss=&typ;
ss->input ();
ss->output ();

cout<<"\n\n Casual ";
ss=&cas;
ss->input ();
ss->output ();
cout<<"\n\n Regular ";
ss=&reg;
ss->input ();
ss->output ();
}
___________________________________________________________________
Q3

#include "stdafx.h"

#include<iostream>
using namespace std;
class staff
{
protected:
char n[30];
int code;
public:
void in()
{
cout<<"\nEnter Name "; cin>>n;
cout<<"\nEnter Code "; cin>>code;
}
void out()
{
cout<<"\nName : "<<n;
cout<<"\nCode : "<<code;
}
};
class teacher:public staff
{
protected:
char sub[40];
int pub;
public:
void in_t()
{
in();
cout<<"\nEnter Subject : ";  cin>>sub;
cout<<"\nEnter Publication ";  cin>>pub;
}
void out_t()
{
out();
cout<<"\nSubject : "<<sub;
cout<<" \nPublication : "<<pub;
}
};
class officer:public staff
{
protected:
int grade;
public:
void in_off()
{
cout<<"\nEnter grade ";  cin>>grade;
}
void out_off()
{
cout<<"\n Grade : "<<grade;
}
};
class education:public teacher , public officer
{
char h_ed_q[40], h_pr_q[40];
public:
void input()
{
in_t();
in_off();
cout<<"\nEnter h_ed_q "; cin>>h_ed_q;
         cout<<"\nEnter h_pr_q "; cin>>h_pr_q;
}
void output()
{
out_t();
out_off();
cout<<"\nHighest Education Qualification "<<h_ed_q;
cout<<"\nHighest Profissional Qualification "<<h_pr_q;
}
};
void main()
{
education ed;
ed.input ();
ed.output ();
}

0 التعليقات:

إرسال تعليق