Q2 - P1
This program relies on a series of data files that are available in the data directory of this workspace:
data/ class_data.txt enrollment_data.txt
You've been hired by NYU's Computer Science department to create a tool that will allow professors to look up their course rosters online. Currently course registration data is stored using two different text files.
This part of the assignment will utilize the class_data.txt file which stores the course ID and the title of each course. There will always be one record in this file for every course that the CS department is currently offering. Please open this file to see how the data is organized.
Your task is to write a program that asks the user for a course ID. The program will then determine if the course ID is valid or not -- if it is not, the program can safely end. If it is valid, the program should report the full title of the course.
You cannot hard code your program to only work with the values contained within these files. The auto marking system uses a completely different set of data files that are organized in the same way as these sample files. Your program should work flawlessly using this new data.
Here's how you can get started:
• Begin by asking the user for a course.
• Next, open the file class_data.txt for reading and obtain all data from the file. Note that this file exists inside of the data directory, so you will need to use the directory name as part of the file path (e.g. data/class_data.txt).
• You should use try / except to ensure that the file opens successfully - if not, you can display the message "File cannot be found" and end the program.
• You'll need to parse this file so you can access the data you care about. Take a look at how the file is being organized:
COURSE_NUMBER_1,COURSE_DESCRIPTION_1
• COURSE_NUMBER_2,COURSE_DESCRIPTION_2
• COURSE_NUMBER_2,COURSE_DESCRIPTION_2
• Each line contains information about a course. On each line you have two values to work with - the course number and the course description. These values are separated by commas.
• The first step is to isolate the individual lines from one another.
• Hint: the split method may be useful here!
• After this, you need to examine each line and identify if that line contains the course number that the user typed in. This will require you to isolate the course number from the course description.
• Hint: a for loop along with another call to the split method may be useful here!
• Store the title somewhere (an accumulator variable?) so you can access it later.
• Finally, generate some output to let the user know if (a) the course cannot be found or (b) the course can be found, along with the title. Do this outside of the loop that you used to find the course. Hint: you may need to set a variable to indicate that you found the course, along with the course title to do
this.
Q2 - P2
Next you will need to see how many students are enrolled in the course (if it exists). Here's how to get started:
• Copy the code you wrote for part 1 (this is allowed for this part of the assignment)
• If the course specified by the user is running you will need to open up the enrollment_data.txt
file and read in the contents of this file as a string.
• You should use try / except to ensure that the file opens successfully - if not, you can display the message "File cannot be found" and end the program.
• This file is organized as follows:
COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME • COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME
• COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME
• COURSE_NUMBER,STUDENT_LAST_NAME,STUDENT_FIRST_NAME
• Each line contains information about a student. On each line you have three values to work with - the course number, the last name of the student and the first name of the student. These are all separated by commas.
• Begin by isolating the individual records from one another (the lines). Then examine each line to see if that line contains a student enrolled in the desired course.
• When examining a line of data you will need to further process that line it (to extract the course number and the student name)
• If that line contains the course number in question you should make a note of it. Hint: an accumulator list may be useful to store all of the students enrolled in this course.
• Finally, after you've finished examining each line you should print out your final report (how many students are enrolled and each of their names) - the names should be sorted in alphabetical order based on the last name.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.