Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to get average

0 votes
asked May 2, 2018 by naveed (120 points)
#include<iostream>

#include<string.h>

using namespace std;

class Student

{

protected:

char name[50],RollNumber[50];

int age;

public:

void in()

{

cout<<"Enter your Name \n";

cin>>name;

cout<<"Enter your roll number \n";

cin>>RollNumber;

cout<<"Enter your age only in years \n";

cin>>age;

}

void show()

{

cout<<"\t\t name   "<<name<<endl<<"roll number "<<RollNumber<<endl<<"age  "<<age<<endl;

}

int getage()

{

return age;

}

};

class UG : public Student // UG represents the undergraduate students

{

private:

int semester;

int fees,stipend;

Student information;

public:

void input()

{

information.in();

cout<<"Enter your semester \n";

cin>>semester;

cout<<"Enter your semester fees \n";

cin>>fees;

cout<<"Enter your stipend if u have got else write only 0 \n";

cin>>stipend;

}

void display()

{

information.show();

cout<<" semester   "<<semester<<endl<<"fees    "<<fees<<endl<<"stipend    "<<stipend<<endl;

}

int getsemester()

{

return semester;

}

int add(Student x)

{

int temp;

temp=x.getage()+getage();

return temp;

}

};

class PG : public Student  // PG represents the post graduate students

{

private:

int semester,fees,stipend;

Student information;

public:

void inputing()

{

information.in();

cout<<"Enter your semester \n";

cin>>semester;

cout<<"Enter your semester fees \n";

cin>>fees;

cout<<"Enter your stipend if u have got else write only 0 \n";

cin>>stipend;

}

void print()

{

information.show();

cout<<" semester     "<<semester<<endl<<"fees    "<<fees<<endl<<"stipend    "<<stipend<<endl;

}

int getsemester()

{

return semester;

}

int add(Student x)

{

int temp;

temp=x.getage()+getage();

return temp;

}

};

main()

{

int a;

float avrg;

avrg=0;

UG obj1,obj2,obj3;

PG obj4,obj5,obj6;

cout<<"\t\t student1 information \n";

obj1.input();

cout<<endl<<endl<<endl<<endl;

cout<<"\t\t student2 information \n";

obj2.input();

cout<<endl<<endl<<endl<<endl;

cout<<"\t\t student3 information \n";

obj3.input();

cout<<endl<<endl<<endl<<endl;

cout<<"\t\t student4 information \n";

obj4.inputing();

cout<<endl<<endl<<endl<<endl;

cout<<"\t\t student5 information \n";

obj5.inputing();

cout<<endl<<endl<<endl<<endl;

cout<<"\t\t student6 information \n";

obj6.inputing();

cout<<endl<<endl<<endl<<endl;

cout<<"\t\t\t average age semesterwise \n";

if(obj1.getsemester()==obj2.getsemester())

{

a=obj1.add(obj2);

avrg=a/2;

cout<<" \n average age of semester"<<obj1.getsemester()<<"is "<<avrg;

}

else

{

cout<<"\n the semester of the students is no similar to each other \n";

}

if(obj1.getsemester()==obj3.getsemester())

{

a=obj1.add(obj3);

avrg=a/2;

cout<<"\n average age of semester"<<obj1.getsemester()<<"is "<<avrg;

}

else

{

cout<<"\n the semester of the students is no similar to each other \n";

}

if(obj2.getsemester()==obj3.getsemester())

{

a=obj2.add(obj3);

avrg=a/2;

cout<<"\n average age of semester"<<obj2.getsemester()<<"is "<<avrg;

}

else

{

cout<<"\n the semester of the students is no similar to each other \n";

}

if(obj4.getsemester()==obj5.getsemester())

{

a=obj4.add(obj5);

avrg=a/2;

cout<<"\n average age of semester"<<obj4.getsemester()<<"is "<<avrg;

}

else

{

cout<<"\n the semester of the students is no similar to each other \n";

}

if(obj4.getsemester()==obj6.getsemester())

{

a=obj4.add(obj6);

avrg=a/2;

cout<<"\n average age of semester"<<obj4.getsemester()<<"is "<<avrg;

}

else

{

cout<<"\n the semester of the students is no similar to each other \n";

}

if(obj5.getsemester()==obj6.getsemester())

{

a=obj5.add(obj6);

avrg=a/2;

cout<<"\n average age of semester"<<obj5.getsemester()<<"is "<<avrg;

}

else

{

cout<<"\n the semester of the students is no similar to each other \n";

}

}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...