Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- #include<stdio.h>
- #define size 5
- class student
- {
- int rollno;
- char name[20];
- public:
- void input()
- {
- cout<<"\n\nEnter Name : ";
- gets(name);
- cout<<"\n\nEnter Roll Number : ";
- cin>>rollno;
- }
- void display()
- {
- cout<<"\n\nName : "<<name;
- cout<<"\n\nRoll Number : "<<rollno;
- }
- };
- class mark : public student
- {
- float m1,m2,m3;
- public:
- void getdata()
- {
- input();
- cout<<"\n\nEnter marks in Mathematics : ";
- cin>>m1;
- cout<<"\n\nEnter marks in Physics : ";
- cin>>m2;
- cout<<"\n\nEnter marks in Chemistry : ";
- cin>>m3;
- }
- void showdata()
- {
- clrscr();
- display();
- cout<<"\n\nMarks in Mathematics : "<<m1;
- cout<<"\n\nMarks in Physics : "<<m2;
- cout<<"\n\nMarks in Chemistry : "<<m3;
- cout<<"\n\nTotal Marks : "<<compute();
- }
- float compute()
- {
- return (m1+m2+m3);
- }
- };
- class Grade : public mark
- {
- float total,avg;
- char grade;
- public:
- void calc()
- {
- getdata();
- avg = mark::compute()/3;
- total = mark::compute();
- if(avg>=80)
- grade = 'A';
- else if(avg>=60)
- grade = 'B';
- else if(avg>=40)
- grade = 'C';
- else
- grade = 'D';
- }
- };
- void main()
- {
- Grade s[size];
- int i=0;
- clrscr();
- for(i=0;i<size;i++)
- {
- clrscr();
- cout<<"\n\nEnter the details for Student "<<i+1;
- s[i].calc();
- }
- cout<<"\n\nEnter 1 to continue : ";
- cin>>n;
- if(n==1)
- for(i=0;i<size;i++)
- {
- cout<<"\n\nDetails for student "<<i+1;
- mark::showdata();
- cout<<"\n\nAverage : "<<avg;
- cout<<"\n\nGrade : "<<grade;
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement