CS115 Programming Fundamentals Department of Computer Science School of Engineering and Digital Sciences Assignment 2 Due: November 17, 2023 23:55. 1. In this assignment, you are to write a program that should be able to read, process, and record information about students to a file. The program should be able to i) add information about a new student, ii) delete an existing student, iii) find a student, and iv) view all students. The program should first prompt the user to enter the name of a file from where information will be read. If there is no such a file, the program should create one. Each line of the file contains the ID, name, department, and GPA of a student. The values are separated by a comma (',')(a sample file is given on Moodle). The program should read line-by-line, make a student object for each line, and populate the 'students' list with these student objects. Then it should prompt the user to choose one of the four operations above or exit. All operations that the user chooses should be done on this list. When the user chooses to exit the program, all information in the students list should be written back to the same file. Please see the figure below for an execution sample. You need to make a module called 'student' that includes classes called 'Student' and 'RecordSystem'. The Student class includes necessary attributes and methods. The RecordSystem class includes methods necessary to perform operations on student objects. Write your main code in another file and import the student module to perform the required operations mentioned above. Starter codes are given on Module. Enter the file name: StudInfo.txt The file doesn't exist. Creating a new file. Choose an operation: v - to view all, a - to add, s- to show one, d - to delete, e - to exit: a
Added by Alina
Close
Step 1
```python # student.py class Student: def __init__(self, id, name, department, gpa): self.id = id self.name = name self.department = department self.gpa = gpa class RecordSystem: def __init__(self): self.students = Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 71 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
(Geometry: The Circle2D class) Define the Circle2D class that contains: ? Two private float data fields named x and y that specify the center of the circle with get/set methods. ? A private data field radius with get/set methods. ? A constructor that creates a circle with the specified x, y, and radius. The default values are all 0. ? A method getArea() that returns the area of the circle. ? A method getPerimeter() that returns the perimeter of the circle. ? A method containsPoint(x, y) that returns True if the specified point (x, y) is inside this circle (see Figure 8.10a). ? A method contains(circle2D) that returns True if the specified circle is inside this circle (see Figure 8.10b). ? A method overlaps(circle2D) that returns True if the specified circle overlaps with this circle (see Figure 8.10c). ? Implement the _ _contains_ _(another) method that returns True if this circle is contained in another circle. ? Implement the _ _cmp_ _, _ _lt_ _, _ _le_ _, _ _eq_ _, _ _ne_ _, _ _gt_ _, _ _ge_ _ methods that compare two circles based on their radius. (a) A point is inside the circle. (b) A circle is inside another circle. (c) A circle overlaps another circle. Draw the UML diagram for the class, and then implement the class. Write a test program that prompts the user to enter two circles with x- and y-coordinates and the radius, creates two Circle2D objects c1 and c2, displays their areas and perimeters, and displays the result of c1.containsPoint(c2.getX(), c2.getY()), c1.contains(c2), and c1.overlaps(c2). Here is a sample run:
The Springfield school board has made the decision to close one of its middle schools (sixth, seventh, and eighth grades) at the end of this school year and reassign all of next year's middle school students to the three remaining middle schools. The school district provides bussing for all middle school students who must travel more than approximately a mile, so the school board wants a plan for reassigning the students that will minimize the total bussing cost. The annual cost per student of bussing from each of the six residential areas of the city to each of the schools is shown in the following table (along with other basic data for next year), where 0 indicates that bussing is not needed and a dash indicates an infeasible assignment. Area No. of Students Percentage in 6th Grade Percentage in 7th Grade Percentage in 8th Grade Bussing Cost per Student School 1 Bussing Cost per Student School 2 Bussing Cost per Student School 3 1 450 32 38 30 $300 0 $700 2 600 37 28 35 — $400 $500 3 550 30 32 38 $600 $300 $200 4 350 28 40 32 $200 $500 — 5 500 39 34 27 0 — $400 6 450 34 28 38 $500 $300 0 School capacity: 900 1,100 1,000 The school board also has imposed the restriction that each grade must constitute between 30 and 36 percent of each school’s population. The above table shows the percentage of each area’s middle school population for next year that falls into each of the three grades. The school attendance zone boundaries can be drawn so as to split any given area among more than one school, but assume that the percentages shown in the table will continue to hold for any partial assignment of an area to a school. You have been hired as an operations research consultant to assist the school board in determining how many students in each area should be assigned to each school. a. Formulate a linear programming model for this problem. b. Solve the model. c. What is your resulting recommendation to the school board? After seeing your recommendation, the school board expresses concern about all the splitting of residential areas among multiple schools. They indicate that they “would like to keep each neighborhood together.” d. Adjust your recommendation as well as you can to enable each area to be assigned to just one school. (Adding this restriction may force you to fudge on some other constraints.) How much does this increase the total bussing cost?
C D.
(Geometry: The Rectangle2D class) Define the Rectangle2D class that contains: ? Two float data fields named x and y that specify the center of the rectangle with get/set methods. (Assume that the rectangle sides are parallel to x- or yaxes.) ? The data fields width and height with get/set methods. ? A constructor that creates a rectangle with the specified x, y, width, and height with default values 0. ? A method getArea() that returns the area of the rectangle. ? A method getPerimeter() that returns the perimeter of the rectangle. ? A method containsPoint(x, y) that returns True if the specified point (x, y) is inside this rectangle (see Figure 8.11a). ? A method contains(Rectangle2D) that returns True if the specified rectangle is inside this rectangle (see Figure 8.11b). ? A method overlaps(Rectangle2D) that returns True if the specified rectangle overlaps with this rectangle (see Figure 8.11c). ? Implement the _ _contains_ _(another) method that returns True if this rectangle is contained in another rectangle. ? Implement the _ _cmp_ _, _ _lt_ _, _ _le_ _, _ _eq_ _, _ _ne_ _, _ _gt_ _, _ _ge_ _ methods that compare two circles based on their areas. (a) A point is inside the rectangle. (b) A rectangle is inside another rectangle. (c) A rectangle overlaps another rectangle. Draw the UML diagram for the class, and then implement the class. Write a test program that prompts the user to enter two rectangles with center x-, y-coordinates, width, and height, creates two Rectangle2D objects r1 and r2, displays their areas and perimeters, and displays the result of r1.containsPoint(r2.getX(), r2.getY()), r1.contains(r2), and r1.overlaps(r2). Here is a sample run:
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD