Question: #include #include #include / / / / / / / / / / / / / / / / / / / / / /

#include
#include
#include
////////////////////////////////////////////////////////////////////////////////
//MACROS: CONSTANTS
////////////////////////////////////////////////////////////////////////////////
//DATA STRUCTURES
////////////////////////////////////////////////////////////////////////////////
//GLOBAL VARIABLES
//place to store course information
struct CourseNode* course_collection = NULL;
typedef enum{
SER,
EGR,
CSE,
EEE
// SER =0, EGR =1, CSE =2, EEE =3
}SUBJECT;
typedef struct CourseNode{
SUBJECT subName;
int courseNum;
char teacher[1024];
int hours;
struct CourseNode* next;
}CourseNode;
int totalCredits(struct CourseNode* head){
int credits =0;
struct CourseNode* tmp = head;
while(tmp != NULL){
credits += tmp -> hours;
tmp = head->next;
}
return credits;
}
char* subName()
void course_insert(struct CourseNode** head, int subNum, int courseNumber, int credHours, char* prof ){
struct CourseNode *newClass ,*current;
newClass =(struct CourseNode*)malloc(sizeof(CourseNode));
newClass ->subName = subNum;
newClass ->courseNum = courseNumber;
newClass ->hours = credHours;
strcpy(newClass->teacher, prof);
if(*head == NULL ||(*head)->courseNum >= newClass->courseNum){
newClass->next =*head;
*head = newClass;
}
else{
current =*head;
while(current ->next != NULL && current->next->courseNum < newClass->courseNum){
current = current->next;
}
newClass->next =current->next;
current->next = newClass;
}
}
void course_drop(struct CourseNode** headRef, int num){
CourseNode* tmp =*headRef,*prev;
if(tmp != NULL && tmp->courseNum == num){
*headRef = tmp->next;
free(tmp);
return;
}
while(tmp !=NULL && tmp->courseNum != num){
prev = tmp;
tmp = tmp->next;
}
if(tmp == NULL){
return;
}
prev->next = tmp->next;
free(tmp);
//tmp = NULL:
}
void schedule_print(){
struct CourseNode* tmp;
while(tmp != NULL){
switch(tmp->subName){
case 0:
printf("SER %d %d %s ", tmp->courseNum,tmp->hours,tmp->teacher);
break;
case 1:
printf("EGR %d %d %s ", tmp->courseNum,tmp->hours,tmp->teacher);
break;
case 2:
printf("CSE %d %d %s ", tmp->courseNum,tmp->hours,tmp->teacher);
break;
case 3:
printf("EEE %d %d %s ", tmp->courseNum,tmp->hours,tmp->teacher);
break;
default:
printf("You have no classes in your schedule.");
break;
}
tmp = tmp ->next;
}
}
void branching(char option);
//main entry point. Starts the program by displaying a welcome and beginning an
//input loop that displays a menu and processes user input. Pressing q quits.
int main(){
char input_buffer;
printf("
Welcome to ASU Class Schedule
");
do {
printf("
Menu Options
");
printf("------------------------------------------------------
");
printf("a: Add a class
");
printf("d: Drop a class
");
printf("s: Show your classes
");
printf("q: Quit
");
printf("
Total Credits: %d
", totalCredits(course_collection));
printf("Please enter a choice --->");
scanf("%c", &input_buffer);
branching(input_buffer);
} while (input_buffer !='q');
free(course_collection);
return 0;
}
//takes a character representing an inputs menu choice and calls the appropriate
//function to fulfill that choice. display an error message if the character is
//not recognized.
void branching(char option){
int classNum;
int subjectNum;
int courseCred;
int n;
char teacher[1024];
switch (option){
case 'a':
printf("Add class subject (SER: 0| EGR: 1| CSE: 2| EEE: 3):");
scanf("%d", &subjectNum);
if(subjectNum >3|| subjectNum <0){
printf("Choose between the given selection please!
Pick class: ");
scanf("%d
", &subjectNum);
}
printf("What are the 3 numbers that follow the subject? (Ex: SER 334): ");
scanf("%d", &classNum);
printf("How many credits is this class?: ");
scanf("%d", &courseCred);
printf("Who teaches this class?: ");
scanf("%s", &teacher);
course_insert(&course_collection,subjectNum,classNum,courseCred,teacher);
break;
case 'd':
printf("enter the course number for the class you would like to drop: ");
scanf("%d", &n);
course_drop(&course_collection, n);
break;
case 's':
schedule_print();
break;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!