Given the Code:
class Student:
def __init__(self,uni,name,year):
self.uni=uni
self.name=name
self.year=year
self.course=[]
def enroll(self,course):
self.course.append(str(course.courseno))
def __str__(self):
return self.name+' is a student with
uni '+self.uni+' in year '+str(self.year)+' at NYU, enrolled in the
following courses: '+str(self.course)+'.'
class Professor:
def __init__(self,uni,name,office):
self.uni=uni
self.name=name
self.office=office
self.course=[]
def __str__(self):
return self.name+' is a professor at
NYU with an office in '+self.office+' and a uni of '+self.uni+',
teaching the following courses:'+str(self.course)+'.'
class Course:
def
__init__(self,courseno,professor,time,room):
self.courseno=courseno
self.professor=professor
self.time=time
self.room=room
self.students=[]
def enroll(self,student):
self.students.append(str(student.uni))
def __str__(self):
return 'Course '+self.courseno+' is
taught by '+str(self.professor.name)+' and meets at '+self.time+'
in '+self.room+'; student unis: '+str(self.students)+'.'
AND THE OUTPUT:
Mary Woods is a student with uni mw1111 in year 1 at NYU,
enrolled in the following courses: ['CS 0002'].
Vinod Khosla is a student with uni vk1023 in year 3 at NYU,
enrolled in the following courses: ['CS 0002', 'CS 0101']. Jane
Martinez is a student with uni jm1267 in year 2 at NYU, enrolled in
the following courses: ['CS 0101'].
Janine Tanaka is a professor at NYU with an office in WWH 419 and a
uni of jt8764, teaching the following courses: ['CS 0101']. Joe
Wang is a professor at NYU with an office in WWH 417
and a uni of jw2222, teaching the following courses: ['CS 0002'].
Course CS 0002 is taught by Joe Wang and meets at
MW 11-12:15 in Silver 201; student unis: ['mw1111', 'vk1023'].
Course CS 0101 is taught by Janine Tanaka and meets at
TR 11-12:15 in Silver 409; student unis: ['vk1023',
'jm1267'].
SOLVE PART 1
(You can do either or both parts of the extra credit.)
Write a remove method that removes a student from a course and add
it to both the Student and Course classes. If the student isn’t in
the course, it should do nothing (it should not generate an error).
Try removing Vinod Khosla from CS 0101 and print out the cs0101 and
Vinod objects again to show that he was removed. Then try removing
him a second time. This should do nothing but should not generate
an error even though he is no longer in the class.
Given the example objects above in the sample main program
above, how do you access Joe Wang’s office using the variable that
points to the class that he teaches? Print out the office by
accessing it in this manner.
SOLVE PART 2
Write out five CSV files using the sample data given above, one
each for the professors, students, courses, professor-course
relationships, and student-course relationships. You need to get
the data out of the objects created after running the main program
above; you can do things like put the object variable names in
lists or dictionaries. You are not allowed to write out the literal
values with statements like
f.write(“Janine Tanaka,jt8764,WWH 419\n”)
etc.
The professor CSV should have each professor’s name, uni, and
office in each row. As there are two professors, there should be
two rows.
The student CSV should have each student’s name, uni and year in
school in each row. As there are three students, there should be
three rows.
The course CSV should have each course’s number, meeting time, and
location in each row. As there are two courses, there should be two
rows.
The professor-course CSV should have, for each professor-course
pair, professor’s uni and the course name in each row. There are
two such relationships, so there should be two rows.
The student-course CSV should have, for each student-course pair,
the student’s uni and the course name in each row. There are four
such relationships, so there should be four rows.
Given the Code: class Student: def __init__(self,uni,name,year): self.uni=uni self.name=name
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Given the Code: class Student: def __init__(self,uni,name,year): self.uni=uni self.name=name
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!