Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* This is the main portion of the RSVP program, by Christopher Aden <cbaden@ucdavis.edu>.
  2.  * All output is handled in this file. The file takes in function
  3.  * prototypes from vector.h, course.h, and student.h, and the functions written
  4.  * in their corresponding c files. The main will read into two structures: a student struc and a course struc.
  5.  * The read in file is specified by the user with a command line argument.
  6.  * The user is then presented with the menu of options, asking if they want to find a CRN
  7.  * or subject, which sends them to a corresponding function. They are also given the ability to
  8.  * add or remove classes from a user using a student ID. */
  9.  
  10. #include <stdio.h>
  11. #include "vector.h"
  12. #include "course.h"
  13.  
  14. //This function prompts the user for their RSVP choice. Their choice is assigned as an int and returned.
  15. int get_choice()
  16. {
  17.     int entry;
  18.     printf("\n");
  19.     printf("RSVP Menu\n");
  20.     printf("0. Done.\n");
  21.     printf("1. Find by CRN.\n");
  22.     printf("2. Find by subject.\n");
  23.     printf("3. Add course.\n");
  24.     printf("4. Remove course.\n");
  25.     printf("Your choice (0 - 4): ");
  26.     scanf("%d", &entry);
  27.     return entry;
  28. }
  29.  
  30. //Function takes in courses struc, student struc, and associated array sizes.
  31. //It will then enter a loop where it calls get_choice and gets an int value for the variable entry.
  32. //If entry is zero, the loop breaks. An entry value of 1 finds a CRN, 2 finds a subject, 3 adds a course to a student,
  33. // and 4 will remove a course. If neither 0, 1, 2, 3, nor 4 are entered, the choice is outside the range and the loop continues.
  34. void display_info(courseStruct * courses, studentStruct * students, int courseArraySize, int studentArraySize)
  35. {
  36.     int entry=5;
  37.     while (1)
  38.     {
  39.         entry = get_choice();
  40.         if (entry == 0)
  41.             break;
  42.         else if (entry == 1)
  43.             find_CRN(courses, students, courseArraySize, studentArraySize);
  44.         else if (entry == 2)
  45.             find_subject(courses, courseArraySize);
  46.         else if (entry == 3)
  47.             add_course(courses, &students, courseArraySize, studentArraySize);
  48.         else if (entry == 4)
  49.             remove_course(courses, &students, courseArraySize, studentArraySize);
  50.         else
  51.             printf("Your choice is outside the acceptable range.  Please try again.\n");
  52.     }
  53.    
  54. }
  55.  
  56. //Main declares the course and student structures, and starting memory size ints.
  57. //It then reads in the source course list from command line argument 1 with the function
  58. //read_courses (written in course.c). Once the information is correctly entered into the strucs,
  59. //the user is presented with a main menu and chooses what they'd like to do.
  60. int main(int argc, char ** argv)
  61. {
  62.     courseStruct * courses; studentStruct * students;
  63.     int courseArraySize = COURSE_ARRAY_SIZE, studentArraySize = STUDENT_ARRAY_SIZE;
  64.     read_courses(argv[1], &courses, &courseArraySize);
  65.     read_students(argv[2], &students, &studentArraySize);
  66.     display_info(courses, students, courseArraySize, studentArraySize);
  67.     return (0);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement