Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------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...)
- typedef struct _Course {
- int courseCode;
- char *courseName;
- char *courseDesc;
- Student *registeredStudents[25];
- Student *waitlistedStudents[25];
- int reg;
- int wait;
- } Course;
- void registerStudentList(int max, Course courseList[], Student studentList[]);
- --------- main file:
- int main() {
- srand(time(NULL));
- Student studentList[] = {
- { NULL, "Doctor", "Doom" },
- { NULL, "Lex", "Luther" },
- { NULL, "Cat", "Woman" },
- { NULL, "Two", "Face" },
- { NULL, "Red", "Skull" },
- { NULL, "Doctor", "Octopus" },
- { NULL, "Captain", "Cold" },
- { NULL, "Death", "Stroke" },
- { NULL, "Harley", "Quinn" },
- { NULL, "Dead", "Shot" },
- { NULL, "Poison", "Ivy" },
- { NULL, "Omega", "Red" },
- };
- initStudentID(MAX_STUDENTS, &studentList);
- Course courseList[] = {
- { NULL, "C Language", "Programming in C without an IDE", NULL, NULL, 0,0},
- { NULL, "Web Programming", "Websites from front to back", NULL, NULL, 0,0},
- { NULL, "Data Structures", "Handling data efficiently with Java", NULL, NULL,0,0},
- };
- initCourseCode(MAX_COURSES, &courseList);
- registerStudentList(MAX_STUDENTS, &courseList, &studentList);
- registerStudentList(MAX_STUDENTS, &courseList, &studentList);
- printCourseInfo(MAX_COURSES,&courseList);
- return 0;
- }
- --------- additions to your print file or whatever you called it:
- void printCourseInfo(int max, Course courseList[]) {
- int i, j;
- for (i = 0; i < max; i++) {
- printf("%03d %s %s\n",courseList[i].courseCode,courseList[i].courseName,courseList[i].courseDesc);
- printf("Registered Students: %d/5\n", courseList[i].reg);
- for(j = 0; j < courseList[i].reg; j++){
- printf("%d -", courseList[i].registeredStudents[j]->studentID);
- printf("%s %s\n", courseList[i].registeredStudents[j]->Name.first, courseList[i].registeredStudents[j]->Name.last);
- }
- printf("\n");
- printf("Waitlisted Students: (%d)\n", courseList[i].wait);
- for(j = 0; j < courseList[i].wait; j++){
- printf("%d -", courseList[i].waitlistedStudents[j]->studentID);
- printf("%s %s\n", courseList[i].waitlistedStudents[j]->Name.first, courseList[i].waitlistedStudents[j]->Name.last);
- }
- printf("\n\n");
- }
- }
- void registerStudentList(int max, Course courseList[], Student studentList[]){
- int i;
- int courseIndex;
- for(i = 0; i < max; i++){
- courseIndex=rand()%3;
- if(courseList[courseIndex].reg < 5){
- courseList[courseIndex].registeredStudents[courseList[courseIndex].reg] = &studentList[i];
- courseList[courseIndex].reg++;
- }
- else{
- courseList[courseIndex].waitlistedStudents[courseList[courseIndex].wait] = &studentList[i];
- courseList[courseIndex].wait++;
- }
- }
- }
- --------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement