Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming assignment 4 required us to write code to convert both to and from string records to dictionary items when reading or writing data to

Programming assignment 4 required us to write code to convert both to and from string records to dictionary items when reading or writing data to a text file. Also, we needed to cast our numbers from strings to integers when reading the file before doing any arithmetic. Moreover, although the program did not have 250 functions, you can see that as a program grows in size and complexity, keeping track of many, many functions will eventually reach a point where focus is lost.

We now have remedies for both of these issues. For this program we will make a bunch of student objects, and we'll have a dictionary that holds a collection of these student objects. That is, the dictionary will represent a course the students are enrolled in. Using a class will allow us to keep both the student data and the methods that operate on that data together. Collecting the class instances into a dictionary and making use of the pickle module will allow us to store and retrieve our student data without having to complete any data conversion.

We might have used a list to contain the student objects, but is this case we will use a dictionary. The key associated with the student object will be the student ID. This allows being able to find a given student directly using their ID, without having to iterate through a loop of students to find the one we want.

So, here's what we need to do. We'll use a dictionary to be a container for a given course, CIT101. We will populate that dictionary with instances of a student class.

The class we write to represent a particular student needs to have the following 4 (and only 4) instance variables:

  • a unique id
  • a name structured as lastname, firstname, for example, "smith, john"
  • two exam scores representing a midterm and an final

Your class will also need 3 and only 3 methods. The first method needs to be a constructor to create each student so the user can enter the student ID, name, and 2 exam scores. In addition to the constructor, the class will also need the following 2 methods (and no more).

  • a helper method to calculate the letter grade for the student based on the average of the exam scores. Use the grading scale used for this class.
  • a method to return the name, two exam scores, and the letter grade for a student.

Your program will allow adding student instances to the CIT101 dictionary so that the dictionary will hold the information for that course.

Each student instance in the dictionary will use the student ID as a key, and the student object instance associated with that ID will be assigned as the key's value. Assume the dictionary is calledCIT101,and the class is calledStudent, so calling

Student(id, name, midterm, final)

creates an instance of the student class. If we were hard-coding all this, it might look like the following.

CIT101 = {}# create the containing dictionary

# add student instance to CIT101 dictionary

CIT101["123"] = Student("123", "smith, john", 78, 86)

When you loop through the items in a dictionary, hopefully you recall our study of dictionaries.

for key in dictname:

print(key, dictname[key])

By analogy, if we were to loop thru the dictionary of student objects, we would use something like this, where we named our dictionary studentsDictionary (I'd pick a shorter name). This would print the sid and the object stored at that key. This is just an example, printing the student object would be messy. I just want you to see the structure.

for sid in studentsDictionary:

print(sid, studentsDictionary[sid])

There is a program very similar in structure to this assignment at the end of the first set of lecture notes on classes. It will be the best guide for getting started on this program.

Your program needs to have a 5-option menu that should look very much like the following. Shown is a sample of entering a new student and then displaying all students and their grades.

image text in transcribed
\f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

The outer covering of the brain is covered with..........?

Answered: 1 week ago

Question

The brain system is composed of...........?

Answered: 1 week ago

Question

What connects two hemisphere of the brain?

Answered: 1 week ago

Question

Fluid filled cavity in the brain is called as........?

Answered: 1 week ago

Question

Which part of the brain controls emotions experience?

Answered: 1 week ago