0% found this document useful (0 votes)
12 views

Brainstroming Tasks2

The document contains C++ code to create classes for person, student, teacher and staff. It derives the student, teacher and staff classes from the base person class. The code takes input from the user to create objects of these classes and displays their details like name, ratings etc. It also calculates the average GPA and feedback score.

Uploaded by

EHTISAM BAIG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Brainstroming Tasks2

The document contains C++ code to create classes for person, student, teacher and staff. It derives the student, teacher and staff classes from the base person class. The code takes input from the user to create objects of these classes and displays their details like name, ratings etc. It also calculates the average GPA and feedback score.

Uploaded by

EHTISAM BAIG
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1

Name:
Muhammad Ehtisam Baig

Roll no:
RP22-EE-433

Brainstorming Tasks 2

Task 1: Create a base class of person and derives classes of student, staff and
teacher. Person class should have the capability to store name, cnic and gender (1
for male and 2 for female). Student must have roll number, cgpa and attendance
percentage. Teacher class should have employee number, subject name, attendance
percentage and feedback score. Staff has employee number, work type (string),
attendance percentage and office score. Display the rating of all objects along with
their name, cnic and gender, roll number/subject/work type using display function.
The number of subjects and their gpa should be dynamic. Calculate the average
rating of each entity.

Source code
#include<iostream>
using namespace std;
class person
{
string name;
int cnic ;
int gender;
public:
void setperson(string n , int c , int g)
{
name = n ;
cnic = c;
gender = g;
}
void display()
{
2

cout<<"Name: "<<name<<"\nCNIC: "<<cnic<<"\n";


if (gender==1)
{
cout<<"Gender: Male";
}
if (gender==2)
{
cout<<"Gender: Female";
}
}

};
class student : public person
{
int rolln ;
float cgpa ;
int att;
public:
float s=0;
float k=0;
void setstudent(int r , float cg , int at)
{
rolln = r ;
cgpa = cg;
att = at;
}
void diplaystudent()
{
cout<<"\nRoll number: "<<rolln;
cout<<"\nCGPA: "<<cgpa;
cout<<"\nAttendence percentage: "<<att<<"%";
}
int performance()
{
return ((s/k)*att);
}
void cgpaa(float a,int b)
{
s=s+(a*b);
k=k+b;
3

}
float result()
{
return(s/k);
}
};
class teacher : public person
{
int empln , att;
float feed;
public:
void setteacher(int empl , int attp , float fed)
{
empln = empl;
att = attp;
feed = fed;
}
int hj = 0;
string ssb[10];
int ij;
void subjectsname(string sss , int kl)
{
ssb[kl];
ssb[hj]=sss;
hj++;
ij =kl;
}
int jh=0;
void subject()
{
cout<<ssb[jh];
jh++;
}
float gh=0;
int hg;
void score(float g , int h)
{
gh=gh+g;
hg=h;
}
4

float fscore()
{
return (gh/hg);
}
void diplayteacher()
{
cout<<"\nEmployee number: "<<empln;
for (int i = 0 ; i < ij ; i++)
{
cout<<"\nSubject "<<i+1<<" name: "<<ssb[i];
}
cout<<"\nAverage feedback score: "<<gh/hg;
cout<<"\nAttendence percentage: "<<att<<"%";
}
int performance()
{
return ((gh/hg)*att);
}
};
class staff : public person
{
string work;
int emn , offs , att;
public:
void setstaff(string w , int em , int off , int at)
{
work = w ;
emn = em;
offs = off;
att = at;
}
int performance()
{
return (att*offs);
}
void worktype()
{
cout<<"Work type: "<<work;
}
void diplaystaff()
5

{
cout<<"\nEmployee number of staff: "<<emn;
cout<<"\nType of work of staff: "<<work;
cout<<"\nAttendence percentage of staff: "<<att;
cout<<"\nOffice score of employee: "<<offs<<"\n";
}
};
int main()
{
string sname;
cout<<"Enter name of student: ";
cin>>sname;
int sid;
cout<<"Enter CNIC number: ";
cin>>sid;
int ssex;
cout<<"Press 1 if student is male\nPress 2 if student is female\nPress number: ";
cin>>ssex;
int su;
int rol , attp;
cout<<"Enter roll number of student: ";
cin>>rol;
cout<<"Enter attendence percentage of student: ";
cin>>attp;
cout<<"Enter number of subjects to calculate gpa: ";
cin>>su;
student *S1=new student[su];
S1[0].setperson(sname , sid , ssex);
int credit;
float gpaa;
for (int i = 0 ; i<su ; i++)
{
cout<<"Enter GPA of subject "<<i+1<<": ";
cin>>gpaa;
cout<<"Enter credit hour of subject "<<i+1<<": ";
cin>>credit;
S1[0].cgpaa(gpaa,credit);
}
S1[0].setstudent(rol , S1[0].result() , attp);
6

string tname;
cout<<"Enter name of techer: ";
cin>>tname;
int tid;
cout<<"Enter CNIC number: ";
cin>>tid;
int tsex;
cout<<"Press 1 if you are male\nPress 2 if you are female\nPress number: ";
cin>>tsex;
int temp , tattp;
cout<<"Enter employee number of teacher: ";
cin>>temp;
int tsu;
cout<<"Enter number of subjects that teacher teaches: ";
cin>>tsu;
class teacher *T1=new teacher[tsu];
string subnn;
for (int i = 0 ; i<tsu ; i++)
{
cout<<"Enter name of subject "<<i+1<<": ";
cin>>subnn;
T1[0].subjectsname(subnn,tsu);
}
cout<<"Enter attendence percentage of teacher: ";
cin>>tattp;
float subna;
T1[0].setperson(tname , tid , tsex);
for (int i = 0 ; i<tsu ; i++)
{
cout<<"Enter feedback of subject "<<i+1<<"(Out of 10): ";
cin>>subna;
T1[0].score(subna , tsu);
}
T1[0].setteacher( temp , tattp , T1[0].fscore());

string xname;
7

cout<<"Enter name of staff: ";


cin>>xname;
int xid;
cout<<"Enter CNIC number: ";
cin>>xid;
int xsex;
cout<<"Press 1 if student is male\nPress 2 if student is female\nPress number: ";
cin>>xsex;
staff X1;
X1.setperson(xname , xid , xsex);
string workt;
int xemp , xttp , ofs;
cout<<"Enter type of work of staff: ";
cin>>workt;
cout<<"Enter employee number of staff: ";
cin>>xemp;
cout<<"Enter attendence percentage of staff: ";
cin>>xttp;
cout<<"Enter office score of employee: ";
cin>>ofs;
X1.setstaff(workt , xemp , ofs , xttp);

cout<<"\nStudent Data\n";
S1[0].display();
S1[0].diplaystudent();
cout<<"\nRating: "<<S1[0].performance()<<"\n";
cout<<"\nTeacher Data\n";
T1[0].display();
T1[0].diplayteacher();
cout<<"\nRating: "<<T1[0].performance()<<"\n";
cout<<"\nStaff Data\n";
X1.display();
X1.diplaystaff();
cout<<"Rating: "<<X1.performance()<<"\n";
return 0;
}
8

Output

You might also like