Question
//////////////////////////////////////////////////////////////////////////////// //INCLUDES #include #include #include //////////////////////////////////////////////////////////////////////////////// //MACROS: CONSTANTS //////////////////////////////////////////////////////////////////////////////// //DATA STRUCTURES //////////////////////////////////////////////////////////////////////////////// //GLOBAL VARIABLES //place to store course information struct CourseNode* course_collection = NULL; ////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//INCLUDES
#include
#include
#include
////////////////////////////////////////////////////////////////////////////////
//MACROS: CONSTANTS
////////////////////////////////////////////////////////////////////////////////
//DATA STRUCTURES
////////////////////////////////////////////////////////////////////////////////
//GLOBAL VARIABLES
//place to store course information
struct CourseNode* course_collection = NULL;
////////////////////////////////////////////////////////////////////////////////
//FORWARD DECLARATIONS
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 ");
//TODO: stuff goes here...
//menu and input loop
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 ", TODO);
printf("Please enter a choice ---> ");
scanf(" %c", &input_buffer);
branching(input_buffer);
} while (input_buffer != 'q');
//TODO: stuff goes here...
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
/ot recognized.
void branching(char option) {
switch (option) {
case 'a':
//TODO
break;
case 'd':
//TODO
break;
case 's':
//TODO
break;
case 'q':
// main loop will take care of this.
break;
default:
printf(" Error: Invalid Input. Please try again...");
break;
}
}
In this assignment you will write a simple program that manages a set of courses a student is taking. This program will introduce new keywords (struct, enum), and the handling of heap memory allocations. Similar to the last assignment, we ask that you do your program development on Linux. The program will store a collection of courses, giving the user options to add to the collection, or remove from that collection. The collection of courses will be stored as a linked list (using structs as nodes). The problem must support any number of courses in the collection. Courses will be composed of a subject (enum), number, teacher, and number of credits. When a user adds a course, a new node must be created, and when a course is removed, its corresponding node is removed. When the program exits, it will save the courses that have been added to a text file. When it starts, it will check if there is course data to load, and load any existing data. This document is separated into four sections: Background, Requirements, Compiling a C Program from Terminal, and Submission. You have almost finished reading the Background section already. In Requirements, we will discuss what is expected of you in this homework. In Compiling and Running a C file on Linux, we discuss how to compile and run your program on Xubuntu. Lastly, Submission discusses how your source code should be submitted on Canvas. 2 Requirements (30 points] For this assignment you will write a course scheduler program in C. Your program must: Compile on GCC 5.3 or greater under Xubuntu (or another variant of Ubuntu) 18.04.x. Have an enumeration type (called Subject) to represent subjects ("SER=0, EGR=1, CSE=2, EEE=3"). Have a struct type (called CourseNode) to hold information about a course. Include a subject (see enum type above), a number (int), a teacher (a string of length 1024), and credit hours (int). It should also include the variables necessary to represent a linked list. Use a linked list of structs (called course_collection) to store course information. Your program will allow the user to enter any number of courses - this means you must use dynamic memory allocation to store the courses. When a user adds a course, a new node must be created, and when a course is removed, its corresponding node is removed. Note: your program may not exactly match the outputs below - screen shots are only provided as samples. Points allocation is: Update the main menu to display the total number of credits each time it is shown. [2 points] The program must not leak memory on exit. [4 points Create a void course_insert() function that adds courses to the collection and keeps it sorted by the course number (e.g., 240). Sorting by subject is not required. Populate the elements of the CourseNode as shown below. Two example inserts are shown. [8 points] Terminal - ruben@ruben-VirtualBoxc-/Desktop File Edit View Terminal Tabs Help Please enter a choice ---> a What is the subject? (SER=0, EGR=1, CSE=2, EEE=3)? What is the number (e.g. 240)? 222 How many credits is the class (e.g. 3)? What is the name of the teacher? Acuna Menu Options a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> - + x Terminal - ruben@ruben-VirtualBox:-/Desktop File Edit View Terminal Tabs Help Please enter a choice ---> a What is the subject? (SER=0, EGR-1, CSE-2, EEE=3)? What is the number (e.g. 240)? 230 How many credits is the class (e.g. 3)? What is the name of the teacher? Chen Menu Options a: Add a class d: Drop a class s: Show your classes 9: Quit Total Credits: 6 Please enter a choice ---> Create a void schedule_print() function. This function will display the contents of the course_collection list with format Subject Number Credits Teacher as shown. (Hint: Use a switch statement to map from an enumeration to a printf.) (2 points) Create a void course_drop() function. This function will prompt the user for a course by its number. It then searches for the course in course collection and removes it. If more than one course matches, then drop only the first occurrence. Dropping a course is only allowed if the course exists in the collection, otherwise an error message will be displayed. [4 points] Terminal - ruben@ruben-VirtualBox:-/Desktop Terminal Tabs Help File Edit View Menu Options a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 6 Please enter a choice --->d Enter number: 222 Menu Options a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> Terminal - ruben@ruben-VirtualBox:-/Desktop Terminal Tabs Help File Edit View a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> S Class Schedule: CSE230 3 Chen Menu Options a: Add a class d: Drop a class S: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> Properly deallocate memory when removing nodes. No memory leaks. [2 points Create a void schedule_load() function that will be called when your program starts. This function should check if a data file exists (plain text, filename up to you), and load any courses that it specifies. Courses should be sorted once the program finishes loading. It may assume that the file is in the format used by your schedule_save function. If the file does not exist, it should do nothing. [4 points) Create a void schedule_save() function that will be called when your program ends. This function saves the contents of the Course Collection to a plain text file (filename up to you). If the file already exists, you may override it. You should design the format of the data file yourself. [4 points] In this assignment you will write a simple program that manages a set of courses a student is taking. This program will introduce new keywords (struct, enum), and the handling of heap memory allocations. Similar to the last assignment, we ask that you do your program development on Linux. The program will store a collection of courses, giving the user options to add to the collection, or remove from that collection. The collection of courses will be stored as a linked list (using structs as nodes). The problem must support any number of courses in the collection. Courses will be composed of a subject (enum), number, teacher, and number of credits. When a user adds a course, a new node must be created, and when a course is removed, its corresponding node is removed. When the program exits, it will save the courses that have been added to a text file. When it starts, it will check if there is course data to load, and load any existing data. This document is separated into four sections: Background, Requirements, Compiling a C Program from Terminal, and Submission. You have almost finished reading the Background section already. In Requirements, we will discuss what is expected of you in this homework. In Compiling and Running a C file on Linux, we discuss how to compile and run your program on Xubuntu. Lastly, Submission discusses how your source code should be submitted on Canvas. 2 Requirements (30 points] For this assignment you will write a course scheduler program in C. Your program must: Compile on GCC 5.3 or greater under Xubuntu (or another variant of Ubuntu) 18.04.x. Have an enumeration type (called Subject) to represent subjects ("SER=0, EGR=1, CSE=2, EEE=3"). Have a struct type (called CourseNode) to hold information about a course. Include a subject (see enum type above), a number (int), a teacher (a string of length 1024), and credit hours (int). It should also include the variables necessary to represent a linked list. Use a linked list of structs (called course_collection) to store course information. Your program will allow the user to enter any number of courses - this means you must use dynamic memory allocation to store the courses. When a user adds a course, a new node must be created, and when a course is removed, its corresponding node is removed. Note: your program may not exactly match the outputs below - screen shots are only provided as samples. Points allocation is: Update the main menu to display the total number of credits each time it is shown. [2 points] The program must not leak memory on exit. [4 points Create a void course_insert() function that adds courses to the collection and keeps it sorted by the course number (e.g., 240). Sorting by subject is not required. Populate the elements of the CourseNode as shown below. Two example inserts are shown. [8 points] Terminal - ruben@ruben-VirtualBoxc-/Desktop File Edit View Terminal Tabs Help Please enter a choice ---> a What is the subject? (SER=0, EGR=1, CSE=2, EEE=3)? What is the number (e.g. 240)? 222 How many credits is the class (e.g. 3)? What is the name of the teacher? Acuna Menu Options a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> - + x Terminal - ruben@ruben-VirtualBox:-/Desktop File Edit View Terminal Tabs Help Please enter a choice ---> a What is the subject? (SER=0, EGR-1, CSE-2, EEE=3)? What is the number (e.g. 240)? 230 How many credits is the class (e.g. 3)? What is the name of the teacher? Chen Menu Options a: Add a class d: Drop a class s: Show your classes 9: Quit Total Credits: 6 Please enter a choice ---> Create a void schedule_print() function. This function will display the contents of the course_collection list with format Subject Number Credits Teacher as shown. (Hint: Use a switch statement to map from an enumeration to a printf.) (2 points) Create a void course_drop() function. This function will prompt the user for a course by its number. It then searches for the course in course collection and removes it. If more than one course matches, then drop only the first occurrence. Dropping a course is only allowed if the course exists in the collection, otherwise an error message will be displayed. [4 points] Terminal - ruben@ruben-VirtualBox:-/Desktop Terminal Tabs Help File Edit View Menu Options a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 6 Please enter a choice --->d Enter number: 222 Menu Options a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> Terminal - ruben@ruben-VirtualBox:-/Desktop Terminal Tabs Help File Edit View a: Add a class d: Drop a class s: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> S Class Schedule: CSE230 3 Chen Menu Options a: Add a class d: Drop a class S: Show your classes q: Quit Total Credits: 3 Please enter a choice ---> Properly deallocate memory when removing nodes. No memory leaks. [2 points Create a void schedule_load() function that will be called when your program starts. This function should check if a data file exists (plain text, filename up to you), and load any courses that it specifies. Courses should be sorted once the program finishes loading. It may assume that the file is in the format used by your schedule_save function. If the file does not exist, it should do nothing. [4 points) Create a void schedule_save() function that will be called when your program ends. This function saves the contents of the Course Collection to a plain text file (filename up to you). If the file already exists, you may override it. You should design the format of the data file yourself. [4 points]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started