Develop a mark sheet in C++ for university examination with following data: a) Students’ name b) Enrolment no c) roll no d) Theory marks in 5 subjects e) Practical marks in five subjects f) grade Overload << and >> operator .Grade should be calculated for each subject. Use Constructor overloading. Roll no should be auto generated
#include<iostream>
#include<ctime>
using namespace std;
class marksheet
{
char student_name[20];
long int enroll;
int rollno;
int s[4];
int p[4],t[4];
public:
marksheet(){};
marksheet(char sn , long int en ,int rn)
{
student_name[20] = sn;
enroll=en;
rollno=rn;
}
void theory();
void practical();
void sum();
void grade();
friend istream & operator >>(istream &,marksheet &);
friend ostream & operator <<(ostream &,marksheet &);
};
istream & operator >>(istream& in , marksheet &m)
{
cout<<"enter the student name "<<endl;
in>>m.student_name;
cout<<"Enter theory marks of 5 subjects out of 70 : "<<endl;
for (int i = 0; i < 5; i++)
{
in>>m.s[i];
}
cout<<"Enter practical marks of 5 subjects out of 30 : "<<endl;
for (int i = 0; i < 5; i++)
{
in>>m.p[i];
}
cout<<"Enter enrollment no. :"<<endl;
in>>m.enroll;
return (in);
}
void marksheet :: sum()
{
for (int i = 0; i < 5; i++)
{
t[i]=s[i]+p[i];
cout<<"totol marks : "<<t[i]<<endl;
}
}
void marksheet :: grade ()
{
for (int i = 0; i < 5; i++)
{
if(t[i]>=80)
// ch='A';
cout<<"grade = A"<<endl;
else if(t[i]>=60)
// ch='B';
cout<<"grade = B"<<endl;
else if(t[i]>=40)
// ch='C';
cout<<"grade = C"<<endl;
else if(t[i]>=33)
// ch='D';
cout<<"grade = D"<<endl;
else if(t[i]<33)
// ch='f';
cout<<"grade : FAIL"<<endl;
}
}
ostream & operator <<(ostream & out , marksheet &m)
{
m.rollno=rand()%100;
out<<"student name : "<<m.student_name<<endl;
out<<"roll no : "<<m.rollno<<endl;
out<<"Enroll no. : "<<m.enroll<<endl;
return(out);
}
int main()
{
srand(time(NULL));
marksheet ms;
cin>>ms;
cout<<"\n\n*****************STUDENT INFO******************\n"<<endl;
cout<<ms;
ms.sum();
ms.grade();
}
output :
enter the student name
Rahul
Enter theory marks of 5 subjects out of 70 :
20
30
40
50
60
Enter practical marks of 5 subjects out of 30 :
25
26
27
28
29
Enter enrollment no. :
27
roll no : 17
Enroll no. : 27
totol marks : 45
totol marks : 56
totol marks : 67
totol marks : 78
totol marks : 89
grade = c
grade = C
grade = B
grade = B
grade = A
Comments
Post a Comment