Summary: In this assignment, you will develop a program which loads data from a file and lets a console user navigate and use that data in meaningful ways.

1 Background

You will develop a program that loads student, course, and grade data from a text file, then allows the user to perform simple queries on that data through a command line interface. The intention of this assignment is to familiarize you with reading data from files, allocating and using dynamically defined 1D and 2D arrays, and further developing your understanding of structs and pointers.

This document is separated into four sections: Background, Requirements, Data File, Running the Program, and Submission.

2 Requirements

For this assignment, you will develop a program to import and handle course data stored in a text file. Your program must:

  • Compile on GCC 5.3 or greater under Xubuntu (or another variant of Ubuntu) 18.04
  • Have a struct type (called Student) to hold information about a student. A dynamically allocated array of these will be a global variable.
  • Have an enum type (called Academic Level) that defines four values indicating a Student's grade level - Freshman, Sophomore, Junior and Senior.
  • Have a struct type (called Course) which holds course information. A dynamically allocated array of these will be a global variable.
  • Have a struct type (called Assign) to hold information about an assignment. A dynamically allocated array of these will be held in your course struct.
  • Have a struct type (called ScoreStruct) to hold information about a student's performance on an assignment. A dynamically allocated array of these will be held in your course struct.
  • Your program will support any number of courses, students, and assignments. All dynamic allocation will be dependent on values read from the provided data file.

Points for this assignment are divided amongst the following requirements:

  • Properly define the Student, Assign, Grade and Course structs and the Academic Level enumeration type
  • Successfully load all of the text data into the appropriate structs
  • Successfully display all course names in the main menu see image.
  • Implement an assignmentMenu(Course course) function which prints a menu of assignments associated with the course and allows the user to choose one. With that selection, call another function getAssignmentScore(Course course, int assignmentNum) which calculates the average score for that assignment and prints it as seen below. see image.
  • Implement a studentMenu(Course course) function which prints a menu of students allows the user to choose one. With that selection, call another function getStudentScores(Course course, int studentNum) which prints that student's scores on each assignment, as well as their final score (the average of all of their scores) in the class see image.
  • Implement a printCourse(Course course) function which cleanly prints all data associated with a course see image.
  • Free all data before the program's termination. No memory leaks!

3 Reading From the Data File and the Command Line

Your program is required to read from a text file which contains a description of a set of students and courses that need to be imported into your program. The data is structured as follows: see image.

The example data used above is provided with the assignment, annotated and not, for you to test your program. It is assumed that every student has a grade for every assignment in every course.

Since the data is stored as an ASCII text file, all values can be read from the file using the function fscanf( FILE * stream, const char * format, ). Some helpful resources to understand how this function works can be found at:

  • http://www.cplusplus.com/reference/cstdio/fscanf/b
  • https://www.tutorialspoint.com/c_standard_library/c_function_fscanf.htm

Similarly, for some of the functionality your program is expected to support, you will need to be able to query the terminal user for menu selections. This requires that you use the function scanf( const char * format, ). The provided code has several examples of this function in action but you may find the following resources helpful:

  • http://www.cplusplus.com/reference/cstdio/scanf/b
  • https://computer.howstuffworks.com/c7.htm

4 Running the Program

It is suggested that you compile and run this program from the terminal. In Ubuntu based systems, the terminal can be opened with the shortcut CTRL+ALT+t. After the terminal opens, you can perform the following steps to run the program:

1. You will start in your root directory. Navigate to the directory containing your source code and text data with the commands cd, ls, .., etc If you are unfamiliar with this process and these commands, refer to the related instructional materials provided in the course shell.

2. Once in the correct directory, we want to compile BaseReader.c. To do this we will execute the GCC compiler suite on the source file. The simplest command to do so is "gcc BaseReader.c - o reader", which will compile the file BaseReader.c and save the execute output as 'reader'.

3. Normally, to run the file we have built, we just need to enter "./reader". The dot slash means look for a file in the current folder. However, this program requires the name of the file containing our text data so we need to offer that somehow. With this code in particular, the author has chosen to use 'getopt', a function that lets you use options as a means of passing in information or flags. To run the program, we will type ./reader -d simple-data.txt.

To read more about getopt (you will need it in the next assignment, too) you might find the following resources helpful:

  • https://www.tutorialspoint.com/getopt-function-in-c-to-parse-command-line-arguments
  • https://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.