Advertisement
DestinyHer0o

Student V

Nov 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4. #include <string>
  5. using namespace std;
  6. class Student
  7. {
  8. private:
  9. string name;
  10. string facNum;
  11. vector<int>grades;
  12. double avarageGrades;
  13. public:
  14. Student() {
  15. name = "Nameless"; facNum = "noFacNumber";
  16. }
  17. Student(string getName, string getFacNum) {
  18. name = getName; facNum = getFacNum;
  19. }
  20. void add_grdae(int getGrade) {
  21. grades.push_back(getGrade);
  22. }
  23.  
  24. double calculateAvarageGrades() {
  25. if (grades.size() != 0) {
  26. double aVg = 0;
  27. int numberOfElements = 0;
  28. for (int i = 0; i < grades.size(); i++){
  29. aVg += grades[i];
  30. //numberOfElements++;
  31. }
  32. return(aVg / grades.size());
  33. }
  34. else {
  35. cout << "There is no grades" << endl;
  36. }
  37. }
  38. void show()
  39. {
  40. cout << "Name:" << name << " " << "facuclty number: " << facNum << " ";
  41. if (grades.size() != 0) {
  42. cout << "average grades: " << calculateAvarageGrades() << endl;
  43. }
  44. else {
  45. cout << "There is no grades" << endl;
  46.  
  47. }
  48. }
  49. };
  50.  
  51.  
  52.  
  53. int main() {
  54.  
  55.  
  56.  
  57. Student ob1,ob2("Kristian", "18621357");
  58. ob1.show();
  59. ob2.show();
  60. cout << endl;
  61. ob2.add_grdae(6);
  62. ob2.add_grdae(5);
  63. ob2.add_grdae(6);
  64. ob2.show();
  65.  
  66.  
  67.  
  68. system("pause");
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement