Advertisement
Guest User

Assingment Q2

a guest
Oct 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string name;
  8. string matric_no, code;
  9. int subject, credit ,cnt ,sum_credit=0;
  10. float gpa_sum=0, gpa_avrg;
  11. char grade,choice;
  12. bool choice_bool=true;
  13.  
  14. while(choice_bool==true)
  15. {
  16. cout<<"Name: ";
  17. getline(cin,name);
  18. cout<<"Matrics No: ";
  19. cin>>matric_no;
  20. cout<< "How many subjects that you have taken: ";
  21. cin>>subject;
  22. cout<<endl;
  23. cout<<"=============================================="<<endl;
  24. cout<<"EXAMINATION RESULT SEMESTER I SESION 2017/2018"<<endl;
  25. cout<<"=============================================="<<endl;
  26. cout<<"NAME: "<<name<<endl;
  27. cout<<"MATRIC NO :"<<matric_no<<endl;
  28. cout<< fixed<<setprecision(1);
  29. cnt=1;
  30.  
  31. while(cnt<=subject)
  32. {
  33. cout<<"SUBJECT "<<"["<<cnt<<"]"<<endl;
  34. cout<<"CODE: ";cin>>code;
  35.  
  36. cout<<"CREDIT: "; cin>>credit;
  37. sum_credit=sum_credit+credit;
  38.  
  39. cout<<"GRADE: ";cin>>grade;
  40. while(grade!='A'&& grade!='B'&& grade!='C'&& grade!='D')
  41. {
  42. cout<<"**INVALID GRADE**"<<endl;
  43. cout<<"GRADE: "<<endl; cin>>grade;
  44. }
  45.  
  46. switch(grade)
  47. {
  48. case 'A': cout<<"POINT VALUE: 4"<<endl<<endl;
  49. grade=4;
  50. gpa_sum=gpa_sum+grade;
  51. break;
  52. case 'B': cout<<"POINT VALUE: 3"<<endl<<endl;
  53. grade=3;
  54. gpa_sum=gpa_sum+grade;
  55. break;
  56. case 'C': cout<<"POINT VALUE: 2"<<endl<<endl;
  57. grade=2;
  58. gpa_sum=gpa_sum+grade;
  59. break;
  60. case 'D': cout<<"POINT VALUE: 1"<<endl<<endl;
  61. grade=1;
  62. gpa_sum=gpa_sum+grade;
  63. break;
  64.  
  65. }
  66.  
  67. cnt++;
  68.  
  69. }
  70.  
  71. gpa_avrg=gpa_sum/subject;
  72. cout<<endl;
  73. cout<<"=============================================="<<endl;
  74. cout<<"TOTAL POINT VALUE: "<<sum_credit<<endl;
  75. cout<<"GPA: "<<gpa_avrg<<endl;
  76. cout<<"=============================================="<<endl;
  77. cout<<"Do you want to continue [Y to continue]"<<endl;
  78. cin>>choice;
  79. if (choice=='y')
  80. choice_bool=true;
  81. else
  82. choice_bool=false;
  83. cin.ignore(256, '\n');
  84.  
  85. }
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement