Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1.  
  2. -------changes to structures.h ( only added an int reg and int wait which are indexes of your registered and waitlisted students and the method declaration below...)
  3. typedef struct _Course {
  4. int courseCode;
  5. char *courseName;
  6. char *courseDesc;
  7. Student *registeredStudents[25];
  8. Student *waitlistedStudents[25];
  9. int reg;
  10. int wait;
  11. } Course;
  12.  
  13.  
  14. void registerStudentList(int max, Course courseList[], Student studentList[]);
  15.  
  16.  
  17. --------- main file:
  18.  
  19. int main() {
  20.  
  21. srand(time(NULL));
  22.  
  23. Student studentList[] = {
  24. { NULL, "Doctor", "Doom" },
  25. { NULL, "Lex", "Luther" },
  26. { NULL, "Cat", "Woman" },
  27. { NULL, "Two", "Face" },
  28. { NULL, "Red", "Skull" },
  29. { NULL, "Doctor", "Octopus" },
  30. { NULL, "Captain", "Cold" },
  31. { NULL, "Death", "Stroke" },
  32. { NULL, "Harley", "Quinn" },
  33. { NULL, "Dead", "Shot" },
  34. { NULL, "Poison", "Ivy" },
  35. { NULL, "Omega", "Red" },
  36. };
  37.  
  38. initStudentID(MAX_STUDENTS, &studentList);
  39.  
  40. Course courseList[] = {
  41. { NULL, "C Language", "Programming in C without an IDE", NULL, NULL, 0,0},
  42. { NULL, "Web Programming", "Websites from front to back", NULL, NULL, 0,0},
  43. { NULL, "Data Structures", "Handling data efficiently with Java", NULL, NULL,0,0},
  44. };
  45.  
  46. initCourseCode(MAX_COURSES, &courseList);
  47.  
  48. registerStudentList(MAX_STUDENTS, &courseList, &studentList);
  49. registerStudentList(MAX_STUDENTS, &courseList, &studentList);
  50. printCourseInfo(MAX_COURSES,&courseList);
  51.  
  52. return 0;
  53. }
  54.  
  55.  
  56. --------- additions to your print file or whatever you called it:
  57.  
  58. void printCourseInfo(int max, Course courseList[]) {
  59. int i, j;
  60. for (i = 0; i < max; i++) {
  61. printf("%03d %s %s\n",courseList[i].courseCode,courseList[i].courseName,courseList[i].courseDesc);
  62.  
  63. printf("Registered Students: %d/5\n", courseList[i].reg);
  64. for(j = 0; j < courseList[i].reg; j++){
  65. printf("%d -", courseList[i].registeredStudents[j]->studentID);
  66. printf("%s %s\n", courseList[i].registeredStudents[j]->Name.first, courseList[i].registeredStudents[j]->Name.last);
  67. }
  68. printf("\n");
  69. printf("Waitlisted Students: (%d)\n", courseList[i].wait);
  70. for(j = 0; j < courseList[i].wait; j++){
  71. printf("%d -", courseList[i].waitlistedStudents[j]->studentID);
  72. printf("%s %s\n", courseList[i].waitlistedStudents[j]->Name.first, courseList[i].waitlistedStudents[j]->Name.last);
  73. }
  74.  
  75.  
  76. printf("\n\n");
  77. }
  78.  
  79. }
  80.  
  81. void registerStudentList(int max, Course courseList[], Student studentList[]){
  82. int i;
  83. int courseIndex;
  84. for(i = 0; i < max; i++){
  85. courseIndex=rand()%3;
  86. if(courseList[courseIndex].reg < 5){
  87. courseList[courseIndex].registeredStudents[courseList[courseIndex].reg] = &studentList[i];
  88. courseList[courseIndex].reg++;
  89. }
  90. else{
  91. courseList[courseIndex].waitlistedStudents[courseList[courseIndex].wait] = &studentList[i];
  92. courseList[courseIndex].wait++;
  93. }
  94. }
  95. }
  96. --------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement