Let we have to prepare the final result of each student for a particular subject. The final
marks are sum of marks obtained by the student in T1, T2, T3, P1, P2, and attendance in theory class. Let
there are following classes:(a) Student: Its data members are student name and roll number and member function is to print
the values of the data members.
(b) T1T2T3: Its data members are marks obtained by a student in T1, T2, and T3 and member
function is to print the values of the data members.
(c) P1P2: Its data members are marks obtained by a student in P1 and P2 and member function is
to print the values of the data members.
(d) Attendance: Data member of this class is the percentage of attendance of a student in the
theory class and member function is to print the values of the data member.
(e) Total: Data members of this class are total marks obtained and the grade secured by a student
and member function is to print the values of the data members.
#include <iostream>
using namespace std;
class Student{
private:
string name;
string rollno;
public:
void setInfo(string n, string r){
name=n;
rollno=r;
}
void displayInfo(){
cout<<name;
cout<<rollno;
}
};
class T1T2T3{
private:
int T1, T2, T3;
public:
void setT1T2T3(int t1, int t2, int t3){
T1=t1;
T2=t2;
T3=t3;
}
void displayT1T2T3(){
cout<<T1<<endl;
cout<<T2<<endl;
cout<<T3<<endl;
}
};
class P1P2{
private:
int P1, P2;
public:
void setT1T2T3(int p1, int p2){
P1=p1;
P2=p2;
}
void displayP1P2(){
cout<<P1<<endl;
cout<<P2<<endl;
}
};
class Attendance{
private:
float percentage;
public:
void setPerc(float p){
percentage=p;
}
void displayPercentage(){
cout<<percentage;
}
};
class Total{
private:
int total;
public:
void displayTotal(){
cout<<total<<endl;
}
};
int main()
{
Student s;
s.setInfo("John","001bcb");
s.displayInfo();
return 0;
}
Comments
Leave a comment