Posted By

woofeR on 02/15/09


Tagged

get basic display set cpp avarage


Versions (?)

GradeBook.cpp


 / Published in: C++
 

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include "GradeBook.h"
  4.  
  5. using namespace std;
  6.  
  7. void GradeBook::displayMessage(int no){
  8. cout << "welcome to course " << no << endl;
  9. }
  10. void GradeBook::displayMessage(){
  11. cout << "welcome to course " << getCourseNo() << endl;
  12. }
  13. void GradeBook::setCourseNo(int no){
  14. courseNo = no;
  15. }
  16. int GradeBook::getCourseNo(){
  17. return courseNo;
  18. }
  19.  
  20. double GradeBook::determineCourseAverage(){
  21. int grade, counter = 0;
  22. double avarage = 0.0;
  23.  
  24. cout << "enter the grade!" << " (student no" << counter+1 << ")" << endl;
  25. cin >> grade;
  26.  
  27. while (grade >=0){
  28. avarage += grade;
  29. counter++;
  30. cout << "again, enter the grade!" << " (student no" << counter+1 << ")" << endl;
  31. cin >> grade;
  32. }
  33.  
  34. if (counter > 0){
  35. avarage = avarage / counter;
  36. return avarage;
  37. }
  38. else
  39. return 0.0;
  40. }

Report this snippet  

You need to login to post a comment.