/*****************************************************************************/ /* File : STUDENTS.CC */ /* */ /* Authors : Craig E. Smith / Stephen C. Smith */ /* University of Massachusetts - Lowell */ /* */ /* Created : Spring Semester, 1992 (Jan - May) */ /* */ /* Revisions : CES/SCS - 01/25/92 - Initial Version */ /* */ /* Purpose : This module contains a working menu-driven test driver for */ /* the GENDB data-modeling tool. This module implements a */ /* University student registration application. This module */ /* currently '#includes' the GENDB.CC module (as opposed to */ /* linking with it) for simplicity. */ /* There are many places in this application where */ /* functions should probably be created to get the input values */ /* and checking for record existence, we decided against this */ /* approach for clarity purposes. This way each function can be */ /* looked at easily without looking at the interactions of many */ /* other functions. */ /* This program is not fully robust in the sense of data */ /* input. There are many places where data input can be */ /* incorrect, or left blank. Another problem arises when a */ /* character field includes spaces within the text. This is */ /* only valid if the field is the last field in the table. It */ /* is very important that the user enters these fields with a */ /* dash (or some other character) so that there are no spaces. */ /* This application was created to allow for understanding of */ /* the GENDB product and functions and how they can be used in */ /* an application. This was more important than data robustness.*/ /* */ /* Platforms : The following compilers have been used successfully : */ /* Turbo C++ (1.01) ( MS-DOS ) */ /* Zortech C++ (2.10) ( MS-DOS ) */ /* GNU C++ (g++) ( UNIX ) */ /* Other compilers should work as well, although it may be */ /* necessary to disable warning messages (usually for not */ /* following the function prototypes found in string.h, */ /* which is a typical problem encountered in C programs). */ /* */ /* Files : The following are files that should be kept with the GENDB */ /* system, wherever it goes, for completeness. */ /* GENDB.CC - GENDB source code */ /* GENDB.HPP - Include file for GENDB, all applications */ /* must include this file */ /* GENDB.DOC - User's Manual for GENDB */ /* TEST.SCH - Schema file for the main test-driver at the */ /* end of GENDB.CC */ /* TEST.DAT - Data file used by the main test-driver */ /* STUDENTS.CC - STUDENT Test Application SOURCE for GENDB */ /* STUDENTS.DAT - STUDENT Test Application DATA FILE for GENDB */ /* STUDENTS.SCH - STUDENT Test Application SCHEMA for GENDB */ /* */ /*****************************************************************************/ #ifdef VAXC #define PROTO 1 #endif #include #include #include "gendb.cc" /******************************************************************************/ /* Below is a group of four utility functions used within the students */ /* application to make user interaction a little easier. */ /******************************************************************************/ /******************************************************************************/ /* function: press_return */ /* purpose : This routine simply waits for the user to press return. */ /* returns : nothing. */ /******************************************************************************/ void press_return(char prompt_str[]) { char temp_str[80]; if (strlen(prompt_str) > 0) printf(prompt_str); gets(temp_str); return; } /******************************************************************************/ /* function: get_string */ /* purpose : This routine reads a string from the keyboard. */ /* returns : nothing. */ /******************************************************************************/ void get_string(char prompt_str[],char result[]) { printf(prompt_str); result[0] = '\0'; gets(result); return; } /******************************************************************************/ /* function: get_integer */ /* purpose : This routine reads an integer from the keyboard. */ /* returns : nothing. */ /******************************************************************************/ void get_integer(char prompt_str[],int *result) { char temp[80]; printf(prompt_str); strcpy(temp,"0"); gets(temp); *result = atoi(temp); return; } /******************************************************************************/ /* function: get_float */ /* purpose : This routine reads a float from the keyboard. */ /* returns : nothing. */ /******************************************************************************/ void get_float(char prompt_str[],float *result) { char temp[80]; printf(prompt_str); strcpy(temp,"0"); gets(temp); *result = atof(temp); return; } /******************************************************************************/ /* Below is a group of global variables to be used within the student */ /* application. They do not need to be global but it makes life a little */ /* easier than defining similar variables in many places. */ /******************************************************************************/ int data_has_changed; /* Set to 1 if changes have occured with the data */ char response_string[51]; /* Temp String To Receive User Response */ /*****************************************************/ /* Variables for each field of the CR (course) table */ /*****************************************************/ char v_course_num[7]; char v_course_name[51]; float v_credits; char v_comments[51]; /******************************************************/ /* Variables for each field of the ST (student) table */ /******************************************************/ char v_student_id[10]; char v_first_name[21]; char v_mid_init[2]; char v_last_name[21]; char v_telephone[16]; int v_house; char v_street[26]; char v_city[21]; char v_state[3]; char v_zip_code[11]; char v_yog[5]; char v_major[3]; /*************************************************************/ /* Variables for each field of the CO (courseoffering) table */ /*************************************************************/ char v_section[4]; char v_teacher[26]; char v_days[6]; char v_time[11]; char v_class_room[9]; char v_semester[6]; int v_max_students; /**********************************************/ /* Variable for assigning or storing a grade */ /**********************************************/ char v_grade[4]; /******************************************************************************/ /* Associate with the students database. Read the schema file and initialize */ /******************************************************************************/ database db ("students","students.sch"); /*************************************************************/ /* Create an Iterator for each table in the student database */ /*************************************************************/ iterator CR (&db,"course"); iterator ST (&db,"student"); iterator CO (&db,"courseoffering"); iterator PR (&db,"prerequisites"); iterator SE (&db,"studentsenrolled"); iterator CT (&db,"coursestaken"); int table_name=1; /* COURSE is the Default Table for add's and delete's */ #define SCREEN_INDENT 25 /* ident for menuitems */ /****************************************************************************/ /* The following macros provide simple screen management. */ /****************************************************************************/ #define clear_screen printf("\033[2J") #define set_cursor_pos(row,col) printf("\033[%1d;%1dH",row,col) #define set_screen_double_top printf("\033#3") #define set_screen_double_bottom printf("\033#4") #define set_screen_bold printf("\033[1m") #define set_screen_blink printf("\033[5m") #define set_screen_reverse printf("\033[7m") #define reset_screen printf("\033[0m") /******************************************************************************/ /* function: set_table_name */ /* purpose : This routine allows a user to change the base table to access */ /* returns : nothing. */ /******************************************************************************/ void set_table_name() { int new_table_name; get_integer("\nEnter New Table Name (1=Courses, 2=Course Prerequisites\n\ 3=Courses Being Offered, 4=Students: ",&new_table_name); if ((new_table_name <1) || (new_table_name >4)) printf("Invalid Table Name!\n"); else table_name=new_table_name; /* set the global variable for current table */ } /******************************************************************************/ /* function: add_to_course */ /* purpose : This routine allows a user to add a new course to the database */ /* returns : nothing. */ /******************************************************************************/ void add_to_course() { get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { printf("Course Already Exists In Database!\n"); return; } /* Make sure the course doesn't already exist */ get_string("Enter Course Name :",v_course_name); /* Get field values */ get_float("Enter Number of Credits :",&v_credits); get_string("Enter Course Comments :",v_comments); CR.Append(); /* Append the new record, and set the field values */ CR.Set("course_num",v_course_num); CR.Set("course_name",v_course_name); CR.Set("credits",v_credits); CR.Set("comments",v_comments); data_has_changed = 1; printf("Course Has Been Added To The Database\n"); } /******************************************************************************/ /* function: add_to_prereq */ /* purpose : This routine allows a user to add a new prerequisite course to */ /* the database */ /* returns : nothing. */ /******************************************************************************/ void add_to_prereq() { int found = 0; iterator CR2 (&db,"course"); get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course exists */ { printf("This Course Does Not Exist in Database! \n"); return; } found = 0; get_string("Enter Prerequisite Course Number :",v_course_num); table_loop(CR2) /* Use second iterator so we don't lose CR placeholder */ if (strcmp(CR2.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the prerequisite course exists */ { printf("This Course Does Not Exist in Database! \n"); return; } /* Loop through all prerequisites of course and see if the the one we are */ /* adding already exists in the database */ child_loop(CR,PR,"prerequisites") if (strcmp(PR.ParentVal("prereq_course"),CR2.PkeyVal()) == 0) { printf("This Prerequisite Course Already Exists in Database! \n"); return; } PR.Append(); /* Append and set fields to iterators' current */ PR.SetParent("course",CR.PkeyVal()); PR.SetParent("prereq_course",CR2.PkeyVal()); data_has_changed = 1; printf("Course Prerequisite Has Been Added To The Database\n"); } /******************************************************************************/ /* function: add_to_courseoffer */ /* purpose : This routine allows a user to add a new course offering to the */ /* database. A course offering is an instance of a course that is */ /* being offered during a particular semester. */ /* returns : nothing. */ /******************************************************************************/ void add_to_courseoffer() { int found = 0; get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course exists */ { printf("This Course Does Not Exist in Database! \n"); return; } get_string("Enter Class Section :",v_section); /* get field values */ get_string("Enter Class Teacher :",v_teacher); get_string("Enter Class Meeting Days :",v_days); get_string("Enter Class Meeting Time :",v_time); get_string("Enter Class Meeting Room :",v_class_room); get_string("Enter the Semester Being Offered (ie, SP92) :",v_semester); get_integer("Enter the Maximum Number of Class Attendees :",&v_max_students); child_loop(CR,CO,"sections") if ((strcmp(CO.StrVal("section"),v_section) == 0) && (strcmp(CO.StrVal("semester"),v_semester) == 0)) { printf("This Course Offering Already Exists in Database! \n"); return; } CO.Append(); /* append and set field values */ CO.SetParent("course_offer",CR.PkeyVal()); CO.Set("section",v_section); CO.Set("teacher",v_teacher); CO.Set("days",v_days); CO.Set("time",v_time); CO.Set("class_room",v_class_room); CO.Set("semester",v_semester); CO.Set("max_students",v_max_students); data_has_changed = 1; printf("Course Offering Has Been Added To The Database\n"); } /******************************************************************************/ /* function: add_to_student */ /* purpose : This routine allows a user to add a new student to the database */ /* returns : nothing. */ /******************************************************************************/ void add_to_student() { get_string("Enter Student ID :",v_student_id); table_loop(ST) if (strcmp(ST.StrVal("student_id"),v_student_id) == 0) { printf("Student Already Exists In Database!\n"); return; } get_string("Enter First Name :",v_first_name); /* get all field values */ get_string("Enter Middle Initial :",v_mid_init); get_string("Enter Last Name :",v_last_name); get_string("Enter Telephone Number :",v_telephone); get_integer("Enter House or Apartment Number :",&v_house); get_string("Enter Street Address :",v_street); get_string("Enter City :",v_city); get_string("Enter State :",v_state); get_string("Enter Zip Code :",v_zip_code); get_string("Enter Year of Graduation :",v_yog); get_string("Enter Curriculum Major :",v_major); ST.Append(); /* Append and set field values */ ST.Set("student_id",v_student_id); ST.Set("first_name",v_first_name); ST.Set("mid_init",v_mid_init); ST.Set("last_name",v_last_name); ST.Set("telephone",v_telephone); ST.Set("house",v_house); ST.Set("street",v_street); ST.Set("city",v_city); ST.Set("state",v_state); ST.Set("zip_code",v_zip_code); ST.Set("yog",v_yog); ST.Set("major",v_major); data_has_changed = 1; printf("Student Has Been Added To The Database\n"); } /******************************************************************************/ /* function: del_from_course */ /* purpose : This routine allows a user to delete a course from the database */ /* returns : nothing. */ /******************************************************************************/ void del_from_course() { int found = 0; get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Look for the course to delete */ { printf("This Course Does Not Exist in Database! \n"); return; } child_loop(CR,CO,"sections") /* Make sure it's not currently being offered */ { printf("You Cannot Delete a Course That is Being Offered! \n"); return; } child_loop(CR,PR,"isaprerequisiteof") /* not a prerequisite of a course */ { printf("You Cannot Delete a Course That is a Prerequisite! \n"); return; } child_loop(CR,CT,"roster_history") /* course hasn't been taken before */ { printf("You Cannot Delete a Course That Was Already Taken! \n"); return; } child_loop(CR,PR,"prerequisites") /* delete courses' prerequisite rows */ PR.Delete(); CR.Delete(); /* delete the course in question */ data_has_changed = 1; printf("This Course Has Been Deleted From the Database! \n"); } /******************************************************************************/ /* function: del_from_prereq */ /* purpose : This routine allows a user to delete a prerequisite course from */ /* the database */ /* returns : nothing. */ /******************************************************************************/ void del_from_prereq() { int found = 0; iterator CR2 (&db,"course"); get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course exists */ { printf("This Course Does Not Exist in Database! \n"); return; } found = 0; get_string("Enter Prerequisite Course Number :",v_course_num); table_loop(CR2) if (strcmp(CR2.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course prerequisite exists */ { printf("This Course Does Not Exist in Database! \n"); return; } found = 0; child_loop(CR,PR,"prerequisites") if (strcmp(PR.ParentVal("prereq_course"),CR2.PkeyVal()) == 0) { found = 1; /* find the correct row and delete it */ PR.Delete(); data_has_changed = 1; printf("This Prerequisite Has Been Deleted From the Database! \n"); } if (found == 0) printf("This Prerequisite Does Not Exist in Database! \n"); } /******************************************************************************/ /* function: del_from_courseoffer */ /* purpose : This routine allows a user to delete a course being offered from */ /* the database */ /* returns : nothing. */ /******************************************************************************/ void del_from_courseoffer() { int found = 0; get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course exists */ { printf("This Course Does Not Exist in Database! \n"); return; } found = 0; get_string("Enter Class Section :",v_section); child_loop(CR,CO,"sections") { found = 1; break; } if (found == 0) /* Make sure the course offering exists */ { printf("Course Offering Does Not Exist In Database\n"); return; } child_loop(CO,SE,"roster") /* look for enrolled students */ { printf("You Cannot Delete a Course That Has Enrolled Students! \n"); return; } CO.Delete(); data_has_changed = 1; printf("This Course Offering Has Been Deleted From the Database! \n"); } /******************************************************************************/ /* function: del_from_student */ /* purpose : This routine allows a user to delete a student from the database */ /* returns : nothing. */ /******************************************************************************/ void del_from_student() { int found = 0; printf("WARNING: This Option Will Delete ALL records for the Student\n"); get_string("Enter Student ID :",v_student_id); table_loop(ST) if (strcmp(ST.StrVal("student_id"),v_student_id) == 0) { found = 1; break; } if (found == 0) /* Make sure the student exists */ { printf("This Student Does Not Exist in Database! \n"); return; } child_loop(ST,SE,"isregisteredfor") /* delete registration records */ SE.Delete(); child_loop(ST,CT,"transcript") /* delete transcript records */ CT.Delete(); ST.Delete(); /* delete the student record */ data_has_changed = 1; printf("This Student Has Been Deleted From the Database! \n"); } /******************************************************************************/ /* function: register_student */ /* purpose : This routine allows a user to register a student for a particular*/ /* course offering */ /* returns : nothing. */ /******************************************************************************/ void register_student() { int found = 0; int num_attending = 0; int ok_to_register = 1; char course_looking_for[7]; get_string("Enter Student ID :",v_student_id); table_loop(ST) if (strcmp(ST.StrVal("student_id"),v_student_id) == 0) { found = 1; break; } if (found == 0) /* Make sure the student exists */ { printf("Student Does Not Exist In Database!\n"); return; } found = 0; get_string("Enter Course Number :",v_course_num); get_string("Enter Course Section Number :",v_section); get_string("Enter Course Semester (ie, SP92) :",v_semester); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course exists */ { printf("Course Was Not Found In Database\n"); return; } found = 0; child_loop(CR,CO,"sections") if ((strcmp(CO.StrVal("section"),v_section) == 0) && (strcmp(CO.StrVal("semester"),v_semester) == 0)) { found = 1; break; } if (found == 0) /* Make sure the course/section/semester exists */ { printf("Course/Section/Semester Was Not Found In Database\n"); return; } child_loop(ST,SE,"isregisteredfor") /* Don't Allow Duplicates */ if ((strcmp(SE.StrVal("course_num"),v_course_num) == 0) && (strcmp(SE.StrVal("section"),v_section) == 0) && (strcmp(SE.StrVal("semester"),v_semester) == 0)) { printf("This Student is Already Registered for This Course\n"); return; } child_loop(CO,SE,"roster") num_attending++; if (num_attending >= CO.IntVal("max_students")) { response_string[0] = '\0'; get_string("Class is Full, Register Anyway? ",response_string); if ((response_string[0] == 'n') || (response_string[0] == 'N')) { printf("This Student is Not Being Registered\n"); return; } } child_loop(CR,PR,"prerequisites") { strcpy(course_looking_for,PR.StrVal("course_num","prereq_course_path")); found = 0; child_loop(ST,CT,"transcript") if (strcmp(course_looking_for,CT.StrVal("course_num")) == 0) { found = 1; break; } if (found == 0) { printf("Missing Prerequisite Course : %s\n",course_looking_for); ok_to_register = 0; } } if (ok_to_register == 0) { response_string[0] = '\0'; get_string("Register Anyway? ",response_string); if ((response_string[0] == 'n') || (response_string[0] == 'N')) { printf("This Student is Not Being Registered\n"); return; } } SE.Append(); SE.SetParent("student",ST.PkeyVal()); SE.SetParent("course_offer",CO.PkeyVal()); data_has_changed = 1; printf("This Student Has Been Registered For the Course Offering\n"); } /******************************************************************************/ /* function: assign_grade */ /* purpose : This routine allows a user to assign a grade to a student that */ /* is enrolled in a course offering */ /* returns : nothing. */ /******************************************************************************/ void assign_grade() { int found = 0; get_string("Enter Student ID :",v_student_id); table_loop(ST) if (strcmp(ST.StrVal("student_id"),v_student_id) == 0) { found = 1; break; } if (found == 0) /* Make sure the student exists */ { printf("Student Does Not Exist In Database!\n"); return; } found = 0; get_string("Enter Course Number :",v_course_num); get_string("Enter Course Section Number :",v_section); get_string("Enter Course Semester (ie, SP92) :",v_semester); table_loop(CO) if ((strcmp(CO.StrVal("course_num"),v_course_num) == 0) && (strcmp(CO.StrVal("section"),v_section) == 0) && (strcmp(CO.StrVal("semester"),v_semester) == 0)) { found = 1; break; } if (found == 0) /* Make sure the course/section/semester exists */ { printf("Course/Section/Semester Was Not Found In Database\n"); return; } found = 0; child_loop(CO,SE,"roster") if (strcmp(SE.StrVal("student_id"),v_student_id) == 0) { found = 1; break; } if (found == 0) /* Make sure the student is enrolled */ { printf("Student Is not Enrolled in This Course/Section/Semester \n"); return; } get_string("Enter Course Grade :",v_grade); CT.Append(); CT.SetParent("studentnum",ST.PkeyVal()); CT.SetParent("coursenum",CO.ParentVal("course_offer")); CT.Set("section",v_section); CT.Set("teacher",CO.StrVal("teacher")); CT.Set("days",CO.StrVal("days")); CT.Set("time",CO.StrVal("time")); CT.Set("class_room",CO.StrVal("class_room")); CT.Set("grade",v_grade); CT.Set("when_taken",v_semester); SE.Delete(); data_has_changed = 1; printf("Grade Was Successfully Assigned For This Course and Section\n"); } /******************************************************************************/ /* function: display_student_schedule */ /* purpose : This routine allows a user to display a schedule for a particular*/ /* student during the semester specified. This does not include */ /* semesters already completed (they are part of the transcript) */ /* returns : nothing. */ /******************************************************************************/ void display_student_schedule() { int found = 0; get_string("Enter Student ID :",v_student_id); get_string("Enter Semester (ie, SP92) :",v_semester); table_loop(ST) if (strcmp(ST.StrVal("student_id"),v_student_id) == 0) { found = 1; break; } if (found == 0) /* Make sure the student exists */ { printf("Student Was Not Found In Database\n"); return; } printf("%s Student Schedule For %s %s %s, Student ID %s\n", v_semester, /* Print header info */ ST.StrVal("first_name"), ST.StrVal("mid_init"), ST.StrVal("last_name"), v_student_id); printf("\n"); child_loop(ST,SE,"isregisteredfor") /* Print courses enrolled in */ if (strcmp(SE.StrVal("semester"),v_semester) == 0) printf("%-7s %-4s %-6s %-11s %-9s %3.1f\n", SE.StrVal("course_num"), SE.StrVal("section"), SE.StrVal("days"), SE.StrVal("time"), SE.StrVal("class_room"), SE.FloatVal("credits")); } /******************************************************************************/ /* function: display_student_transcript */ /* purpose : This routine allows a user to display a transcript for a */ /* particular student. This includes courses that a student is */ /* currently enrolled in as well as all past courses taken */ /* returns : nothing. */ /******************************************************************************/ void display_student_transcript() { int found = 0; float total_credits = 0.0; float qual_credits = 0.0; float qual_points = 0.0; float gpa = 0.0; get_string("Enter Student ID :",v_student_id); table_loop(ST) if (strcmp(ST.StrVal("student_id"),v_student_id) == 0) { found = 1; break; } if (found == 0) /* Make sure the student exists */ { printf("Student Was Not Found In Database\n"); return; } printf("Student Transcript For %s %s %s, Student ID %s\n", ST.StrVal("first_name"), /* Print header info */ ST.StrVal("mid_init"), ST.StrVal("last_name"), v_student_id); printf("\n"); printf("Currently Registered For or Currently Taking:\n"); child_loop(ST,SE,"isregisteredfor") /* Print courses enrolled in */ { total_credits = total_credits + SE.FloatVal("credits"); printf("%-7s %-4s %-6s %-11s %-9s %-6s %3.1f\n", SE.StrVal("course_num"), SE.StrVal("section"), SE.StrVal("days"), SE.StrVal("time"), SE.StrVal("class_room"), SE.StrVal("semester"), SE.FloatVal("credits")); } printf("\n"); printf("Courses Previously Completed:\n"); child_loop(ST,CT,"transcript") /* Print courses completed */ { total_credits = total_credits + CT.FloatVal("credits"); strcpy(v_grade,CT.StrVal("grade")); if (strcmp(v_grade,"A") == 0) /* Calculate quality points... */ { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits") * 4.0); } else if (strcmp(v_grade,"AB") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits") * 3.5); } else if (strcmp(v_grade,"B") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits") * 3.0); } else if (strcmp(v_grade,"BC") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits") * 2.5); } else if (strcmp(v_grade,"C") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits") * 2.0); } else if (strcmp(v_grade,"CD") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits") * 1.5); } else if (strcmp(v_grade,"D") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); qual_points = qual_points + (CT.FloatVal("credits")); } else if (strcmp(v_grade,"F") == 0) { qual_credits = qual_credits + CT.FloatVal("credits"); } printf("%-7s %-4s %-6s %-11s %-9s %-6s %-2s %3.1f\n", CT.StrVal("course_num"), CT.StrVal("section"), CT.StrVal("days"), CT.StrVal("time"), CT.StrVal("class_room"), CT.StrVal("when_taken"), v_grade, CT.FloatVal("credits")); } printf("\n"); /* Print Footer Info. */ printf("Total Credits: %5.1f \n",total_credits); printf("Quality Point Credits: %5.1f \n",qual_credits); printf("Quality Points: %5.1f \n",qual_points); if (qual_credits > 0.0) gpa = qual_points/qual_credits; printf("G.P.A.: %6.4f \n",gpa); } /******************************************************************************/ /* function: display_class_roster */ /* purpose : This routine allows a user to display the roster (students */ /* enrolled in a course offering) for a particular course offering */ /* returns : nothing. */ /******************************************************************************/ void display_class_roster() { int found = 0; get_string("Enter Course Number :",v_course_num); get_string("Enter Section Number :",v_section); get_string("Enter Semester (ie, SP92) :",v_semester); table_loop(CO) if ((strcmp(CO.StrVal("course_num"),v_course_num) == 0) && (strcmp(CO.StrVal("section"),v_section) == 0)) { found = 1; break; } if (found == 0) /* Make sure the course/section/semester exists */ { printf("Course and Section Was Not Found In Database\n"); return; } printf("%s Student Roster For Course %s Section %s\n", v_semester, v_course_num, v_section); printf("\n"); child_loop(CO,SE,"roster") /* Loop through the enrolled students */ if (strcmp(CO.StrVal("semester"),v_semester) == 0) printf("%-7s %-4s %-6s %-11s %-9s\n", SE.StrVal("course_num"), SE.StrVal("section"), SE.StrVal("days"), SE.StrVal("time"), SE.StrVal("class_room")); } /******************************************************************************/ /* function: display_course_prerequisites */ /* purpose : This routine allows a user to display all prerequisite courses */ /* required before a student can be enrolled in a particular course */ /* returns : nothing. */ /******************************************************************************/ void display_course_prerequisites() { int found = 0; get_string("Enter Course Number :",v_course_num); table_loop(CR) if (strcmp(CR.StrVal("course_num"),v_course_num) == 0) { found = 1; break; } if (found == 0) /* Make sure the course exists */ { printf("Course Number Was Not Found In Database\n"); return; } printf("Prerequisites For Course %s:\n", v_course_num); printf("\n"); child_loop(CR,PR,"prerequisites") /* Print out all prerequisites */ printf("%-7s %-50s\n", PR.StrVal("course_num","prereq_course_path"), PR.StrVal("course_name","prereq_course_path")); } /******************************************************************************/ /* function: main */ /* purpose : This is the main program. It is the menu driven loop to access */ /* the different data manipulation functions */ /* returns : nothing. */ /******************************************************************************/ main() { int all_done=0; int user_choice; char temp_table_name[50]; db.Load ("students.dat"); /* load in all data from the students.dat file */ data_has_changed = 0; while (all_done == 0) { clear_screen; set_cursor_pos(1,1); switch (table_name) { case 1: strcpy(temp_table_name,"Courses"); break; case 2: strcpy(temp_table_name,"Course Prerequisites"); break; case 3: strcpy(temp_table_name,"Courses Being Offered"); break; case 4: strcpy(temp_table_name,"Students"); break; }; printf("Table Name = %s\n",temp_table_name); set_screen_bold; set_screen_reverse; set_cursor_pos(3,1); set_screen_double_top; printf(" CHGEN Student Database System \n"); set_cursor_pos(4,1); set_screen_double_bottom; printf(" CHGEN Student Database System \n"); reset_screen; printf("\n"); printf("%*s[1] Set Table Name\n",SCREEN_INDENT," "); printf("%*s[2] Add to Table\n",SCREEN_INDENT," "); printf("%*s[3] Delete From Table\n",SCREEN_INDENT," "); printf("%*s[4] Display Contents of a Table\n",SCREEN_INDENT," "); printf("%*s[5] Register Student For a Course\n",SCREEN_INDENT," "); printf("%*s[6] Assign Course Grade To Student\n",SCREEN_INDENT," "); printf("%*s[7] Display a Students Schedule\n",SCREEN_INDENT," "); printf("%*s[8] Display a Students Transcript\n",SCREEN_INDENT," "); printf("%*s[9] Display a Class Roster\n",SCREEN_INDENT," "); printf("%*s[10] Display Course Prerequisites\n",SCREEN_INDENT," "); printf("\n"); printf("%*s[11] Exit\n",SCREEN_INDENT," "); printf("\n%*sEnter Choice [CR] :",SCREEN_INDENT-8," "); get_integer("",&user_choice); printf("\n"); switch(user_choice) { case 1: set_table_name(); break; case 2: switch (table_name) { case 1 : add_to_course(); break; case 2 : add_to_prereq(); break; case 3 : add_to_courseoffer(); break; case 4 : add_to_student(); break; default : break; } break; case 3: switch (table_name) { case 1 : del_from_course(); break; case 2 : del_from_prereq(); break; case 3 : del_from_courseoffer(); break; case 4 : del_from_student(); break; default : break; } break; case 4: switch (table_name) { case 1 : table_loop(CR) CR.Print(); break; case 2 : table_loop(PR) PR.Print(); break; case 3 : table_loop(CO) CO.Print(); break; case 4 : table_loop(ST) ST.Print(); break; default : break; } break; case 5: register_student(); break; case 6: assign_grade(); break; case 7: display_student_schedule(); break; case 8: display_student_transcript(); break; case 9: display_class_roster(); break; case 10: display_course_prerequisites(); break; case 11: all_done = 1; if (data_has_changed == 1) { response_string[0] = '\0'; get_string("Save Changes To Data Base? ",response_string); if ((response_string[0] != 'n') && (response_string[0] != 'N')) { printf("Changes are being saved to database\n"); db.Dump ("students.dat"); } else printf("Changes are NOT BEING SAVED\n"); } break; }; /* switch */ if (all_done == 0) press_return("\nPress [CR] to Continue..."); } }