/*
Cpp Manipulators used are endl and setw().
These manipulators require inclusion of header file <iomanip>
endl : It is used for ending of line in an output.
setw(): This manipulator sets the character spacing in an output i.e
for e.g. cout<<"Hello"<<setw(3)<<"World";
here setw(3) will set 3 character spacing between "Hello World".
*/
#include<iostream>
#include<iomanip>
#include<string.h>
using namespace std;
class student
{
protected:
int rno;
char name[20];
public:
student(int r,char name1[])
{
rno=r;
strcpy(name,name1);
}
void display()
{
cout<<"\n Student rno="<<rno;
cout<<"\n Student name="<<name;
}
};
class student_exam:public student
{
protected:
int *ptr;
int no;
public:
student_exam(int r,char nm[],int n):student(r,nm)
{
no=n;
ptr=new int[no];
}
void accept()
{
for(int i=0;i<no;i++)
{
cout<<"\n Enter Subject mark=";
cin>>ptr[i];
}
}
void display()
{
cout<<"\n==============MARK SHEET============\n";
for(int i=0;i<no;i++)
cout<<"\n Subject"<<i<<":"<<ptr[i]<<"\n";
}
};
class student_result:public student_exam
{
protected:
float per;
char grade;
public:
student_result(int r,char nm[],int no):student_exam(r,nm,no)
{
}
void cal()
{
int t=0;
for(int i=0;i<no;i++)
{
t=t+ptr[i];
}
per=t/no;
if(per>70)
grade='A';
else if(per>=60 && per<70)
grade='B';
else if(per>=50 && per<60)
grade='C';
else if(per>=40 && per<50)
grade='D';
else grade='E';
student::display();
student_exam::display();
cout<<"\n======================================================";
cout<<"\n Percentage="<<per<<"%";
cout<<"\n Grade="<<setw(5)<<grade<<endl;
}
};
main()
{
int no,s;
char name[20];
cout<<"\n Enter roll no=";
cin>>no;
cout<<"\n Enter name=";
cin>>name;
cout<<"\n Enter no of subject=";
cin>>s;
student_result ob(no,name,s);
ob.accept();
cout<<"\n MARKLIST IS \n";
ob.cal();
}
/*
Enter roll no=12
Enter name=sachin
Enter no of subject=3
Enter Subject mark=34
Enter Subject mark=45
Enter Subject mark=67
MARKLIST IS
Student rno=12
Student name=sachin
==============MARK SHEET============
Subject0:34
Subject1:45
Subject2:67
======================================================
Percentage=48%
Grade= D
*/
// CPP programs
Comments
Post a Comment
Please do not enter any spam links in the comment box.