Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1.  
  2. //#include "Student_Class.cpp.webarchive" //; // only for Microsoft Visual Studio C++ programs
  3. #include <iostream>
  4. #include <string>
  5. #include <stdio.h>
  6. #include <cctype>
  7. #include "Student.h"//;
  8.  
  9.  
  10. //#include "Student_Class.cpp.webarchive";
  11.  
  12. class Student_Class;
  13. int main(int argc, char* argv[]);
  14. char data[100];
  15. #include "Student_Class.cpp.webarchive"
  16.  
  17. using namespace std;
  18.  
  19. // define an array of students
  20. class Student CIS054[] = {
  21. Student ("Joe Williams", 44536, 3.4),
  22. Student ("Sally Washington", 55458, 3.7),
  23. Student ("Fred MacIntosh", 66587, 2.9),
  24. Student ("Jose De La Cruz", 67892, 3.5),
  25. Student ("777 Dan McElroy", 77777, 4.0),
  26. Student ("Thinh Nguyen", 73657, 3.6)
  27. };
  28.  
  29.  
  30. int main(int argc, char* argv[])
  31. { Student s;
  32. int NumberOfStudents = sizeof(CIS054)/sizeof(Student);
  33.  
  34. // Display the header line
  35. // List all the students in the course
  36. for (int i=0; i&lt;NumberOfStudents; i++)
  37. cout &lt;&lt; " " &lt;&lt; CIS054[i].getIdNumber() &lt;&lt; " " &lt;&lt; CIS054[i].getName() &lt;&lt; endl;
  38. cout &lt;&lt; endl; // blank line after displaying the student names
  39.  
  40. // compute the average gpa of all the students
  41. double total=0;
  42. for (int i=0; i&lt;NumberOfStudents; i++)
  43. total += CIS054[i].getGpa();
  44. double average = total / NumberOfStudents;
  45. cout &lt;&lt; " " &lt;&lt; "The average GPA of all the students is " &lt;&lt; average &lt;&lt; endl &lt;&lt; endl;
  46. return 0;
  47. }
  48.  
  49. </pre></body></html>
  50.  
  51. // open a file in write mode.
  52. ofstream outfile;
  53. outfile.open('Student_Class.cpp');
  54. // default Student constructor
  55. {
  56. Student::Student();
  57. {
  58. name = ""; // set name to an empty string
  59. IdNumber = 0;
  60. gpa = 0.0;
  61. }
  62. // Fully qualified Student constructor
  63. Student::Student(string n, int id, double g)
  64. {
  65. setName(n); // use setName to validate data
  66. setIdNumber(id); // use setIdNumber to validate data
  67. setGpa(g); // use setGpa to validate data
  68. }
  69.  
  70. //mutators and accessors
  71. void Student::setName(string n)
  72. {
  73. if ( isupper(n[0]) ) // 1st character of name must be A-Z
  74. name = n;
  75. else
  76. name = "--Bad name entered";
  77. }
  78. string Student::getName()
  79. {
  80. return name;
  81. }
  82. void Student::setIdNumber(int id)
  83. {
  84. if ( id>1 && id<100000) // must be from 0 to 100000
  85. IdNumber = id;
  86. else
  87. IdNumber = 0; // indicate an illegal selection
  88. }
  89. int Student::getIdNumber()
  90. {
  91. return IdNumber;
  92. }
  93. void Student::setGpa(double g)
  94. {
  95. if (g>=0.0 && g<=4.0) // gpa must be from 0.0 to 4.0
  96. gpa = g;
  97. else
  98. gpa = 0;
  99. }
  100. double Student::getGpa()
  101. {
  102. return gpa;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement