fork download
  1. // #include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<vector>
  4. using namespace std;
  5. class Student{
  6. public:
  7. vector<double> theoryGrades;
  8. int noOfTheory;
  9.  
  10. Student(int n){
  11. noOfTheory=n;
  12. for(int i=0;i<noOfTheory;i++){
  13. double v; cin>>v;
  14. theoryGrades.push_back(v);
  15. }
  16. }
  17.  
  18. // Student(int noOfTheory)
  19. virtual double calculateCGPA(){
  20. double tot=0;
  21. for(int i=0;i<noOfTheory; i++){
  22. tot+=theoryGrades[i];
  23. }
  24. return tot/noOfTheory;
  25. }
  26. };
  27.  
  28. class BscStudent: public Student{
  29. public:
  30. vector<double> labGrades;
  31. int noOfLabs;
  32.  
  33. BscStudent(int nt, int nl):Student(nt){
  34. noOfLabs=nl;
  35. for(int i=0;i<noOfLabs;i++){
  36. double v; cin>>v;
  37. labGrades.push_back(v);
  38. }
  39. }
  40.  
  41. double calculateCGPA() override{
  42. double tot=0;
  43. for(int i=0;i<noOfTheory; i++){
  44. tot+=theoryGrades[i];
  45. }
  46. for(int i=0;i<noOfLabs; i++){
  47. tot+=labGrades[i];
  48. }
  49. return tot/(noOfTheory+noOfLabs);
  50. }
  51. };
  52.  
  53. class L4Student: public BscStudent{
  54. public: double thesisGrade;
  55.  
  56. L4Student(int nt, int nl, double tg): BscStudent(nt, nl), thesisGrade(tg){}
  57.  
  58. double calculateCGPA() override{
  59. double tot=0;
  60. for(int i=0;i<noOfTheory; i++){
  61. tot+=theoryGrades[i];
  62. }
  63. for(int i=0;i<noOfLabs; i++){
  64. tot+=labGrades[i];
  65. }
  66. tot+=thesisGrade;
  67. return tot/(noOfTheory+noOfLabs+1);
  68. }
  69. };
  70.  
  71. class MscStudent: public Student{
  72. public: double projectGrade, thesisGrade;
  73.  
  74. MscStudent(int n, double pg, double tg): Student(n), projectGrade(pg), thesisGrade(tg){}
  75.  
  76. double calculateCGPA() override{
  77. double tot=0;
  78. for(int i=0;i<noOfTheory; i++){
  79. tot+=theoryGrades[i];
  80. }
  81. tot+=projectGrade+thesisGrade;
  82. return tot/(noOfTheory+2);
  83. }
  84. };
  85.  
  86. void scholarshipAmount(Student *s){
  87. double cg=s->calculateCGPA();
  88. cout<<"CGPA: "<<cg<<endl;
  89. if(cg >= 3.80){
  90. cout<<"Scholarship amount: 10,000 BDT\n";
  91. return;
  92. }
  93. if(cg >= 3.70){
  94. cout<<"Scholarship amount: 5,000 BDT\n";
  95. return;
  96. }
  97. cout<<"No scholarship\n";
  98.  
  99. }
  100.  
  101. int main(){
  102. // Derived1 d1;
  103. // Derived2 d2;
  104. // Base *b=new Derived2;
  105. // b->f1();
  106. L4Student l4(3, 2, 4.00);
  107. scholarshipAmount(&l4);
  108.  
  109. return 0;
  110. }
  111.  
  112.  
Success #stdin #stdout 0s 5320KB
stdin
3.00 3.5 3.7
3.5 3.8
stdout
CGPA: 3.58333
No scholarship