Guest User

Untitled

a guest
May 21st, 2012
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Average of an array (struct)
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. const int CLASSIZE = 1;
  8.  
  9. struct student
  10. {
  11. string firstName;
  12. string lastName;
  13.  
  14. void printTheInfo()
  15. {
  16. cout << "Name: " << firstName << " " << lastName;
  17. }
  18. void loadMe()
  19. {
  20. cout << "First Name: ";
  21. cin >> firstName;
  22. cout << "Last Name: ";
  23. cin >> lastName;
  24. }
  25. };
  26. struct grades
  27. {
  28. int grade1;
  29. int grade2;
  30. int grade3;
  31. int grade4;
  32. int grade5;
  33.  
  34. void printTheGrades()
  35. {
  36. cout << " Grades: " << grade1 << " " << grade2 << " " << grade3
  37. << " " << grade4 << " " << grade5 << endl;
  38. }
  39. void loadGrades()
  40. {
  41. cout << "Grade 1: ";
  42. cin >> grade1;
  43. cout << "Grade 2: ";
  44. cin >> grade2;
  45. cout << "Grade 3: ";
  46. cin >> grade3;
  47. cout << "Grade 4: ";
  48. cin >> grade4;
  49. cout << "Grade 5: ";
  50. cin >> grade5;
  51. }
  52. };
  53.  
  54. void printAllStudents(student [], grades [], int);
  55. void loadAllStudents(student [], grades [], int);
  56.  
  57. int main(int argc, char *argv[])
  58. {
  59. student theStudent[CLASSIZE];
  60. grades theGrade[CLASSIZE];
  61.  
  62. loadAllStudents(theStudent, theGrade, CLASSIZE);
  63. printAllStudents(theStudent, theGrade, CLASSIZE);
  64.  
  65. system("PAUSE");
  66. return EXIT_SUCCESS;
  67. }
  68.  
  69. void loadAllStudents(student theStudents[], grades theGrades[], int s)
  70. {
  71. for(int i = 0; i < s; i++)
  72. {
  73. theStudents[i].loadMe();
  74. theGrades[i].loadGrades();
  75. }
  76. }
  77. void printAllStudents(student theStudents[], grades theGrades[], int s)
  78. {
  79. for(int i = 0; i < s; i++)
  80. {
  81. theStudents[i].printTheInfo();
  82. theGrades[i].printTheGrades();
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment