Advertisement
Guest User

Inherit

a guest
Apr 21st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include<iostream.h>
  2.  
  3. #include<conio.h>
  4.  
  5. #include<stdio.h>
  6.  
  7. #define size 5
  8.  
  9.  
  10.  
  11. class student
  12.  
  13. {
  14.  
  15. int rollno;
  16.  
  17. char name[20];
  18.  
  19. public:
  20.  
  21. void input()
  22.  
  23. {
  24.  
  25. cout<<"\n\nEnter Name : ";
  26.  
  27. gets(name);
  28.  
  29. cout<<"\n\nEnter Roll Number : ";
  30.  
  31. cin>>rollno;
  32.  
  33. }
  34.  
  35. void display()
  36.  
  37. {
  38.  
  39. cout<<"\n\nName : "<<name;
  40.  
  41. cout<<"\n\nRoll Number : "<<rollno;
  42.  
  43. }
  44.  
  45. };
  46.  
  47. class mark : public student
  48.  
  49. {
  50.  
  51. float m1,m2,m3;
  52.  
  53. public:
  54.  
  55. void getdata()
  56.  
  57. {
  58.  
  59. input();
  60.  
  61. cout<<"\n\nEnter marks in Mathematics : ";
  62.  
  63. cin>>m1;
  64.  
  65. cout<<"\n\nEnter marks in Physics : ";
  66.  
  67. cin>>m2;
  68.  
  69. cout<<"\n\nEnter marks in Chemistry : ";
  70.  
  71. cin>>m3;
  72.  
  73. }
  74.  
  75. void showdata()
  76.  
  77. {
  78.  
  79. clrscr();
  80.  
  81. display();
  82.  
  83. cout<<"\n\nMarks in Mathematics : "<<m1;
  84.  
  85. cout<<"\n\nMarks in Physics : "<<m2;
  86.  
  87. cout<<"\n\nMarks in Chemistry : "<<m3;
  88.  
  89. cout<<"\n\nTotal Marks : "<<compute();
  90.  
  91. }
  92.  
  93. float compute()
  94.  
  95. {
  96.  
  97. return (m1+m2+m3);
  98.  
  99. }
  100.  
  101. };
  102.  
  103. class Grade : public mark
  104.  
  105. {
  106.  
  107. float total,avg;
  108.  
  109. char grade;
  110.  
  111. public:
  112.  
  113. void calc()
  114.  
  115. {
  116.  
  117. getdata();
  118.  
  119. avg = mark::compute()/3;
  120.  
  121. total = mark::compute();
  122.  
  123. if(avg>=80)
  124.  
  125. grade = 'A';
  126.  
  127. else if(avg>=60)
  128.  
  129. grade = 'B';
  130.  
  131. else if(avg>=40)
  132.  
  133. grade = 'C';
  134.  
  135. else
  136.  
  137. grade = 'D';
  138.  
  139. }
  140.  
  141. };
  142.  
  143. void main()
  144.  
  145. {
  146.  
  147. Grade s[size];
  148.  
  149. int i=0;
  150.  
  151. clrscr();
  152.  
  153. for(i=0;i<size;i++)
  154.  
  155. {
  156.  
  157. clrscr();
  158.  
  159. cout<<"\n\nEnter the details for Student "<<i+1;
  160.  
  161. s[i].calc();
  162.  
  163. }
  164.  
  165. cout<<"\n\nEnter 1 to continue : ";
  166.  
  167. cin>>n;
  168.  
  169. if(n==1)
  170.  
  171. for(i=0;i<size;i++)
  172.  
  173. {
  174.  
  175. cout<<"\n\nDetails for student "<<i+1;
  176.  
  177. mark::showdata();
  178.  
  179. cout<<"\n\nAverage : "<<avg;
  180.  
  181. cout<<"\n\nGrade : "<<grade;
  182.  
  183. getch();
  184.  
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement