14.21 LAB: Course size Complete the Course class by implementing the course_size() instance method, which returns the total number of students in the course. The file main.py contains: . The main function for testing the program. • Class Course represents a course, which contains a list of Student objects as a course roster. (Type your code in here.) • Class Student represents a classroom student, which has three attributes: first name, last name, and GPA. Note: For testing purposes, different student values will be used. Ex. For the following students: Henry Bendel 3.6 Johnny Min 2.9 the output is: Course size: 2

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
class Student:
definit__(self, first, last, gpa):
self.first = first # first name
self.last = last
self.gpa = gpa
if
def get_gpa(self):
return self.gpa
def get_last (self):
return self.last
class Course:
definit__(self):
self.roster =
def add_student (self, student):
self.roster.append(student)
def course_size(self):
# Your code goes here
11
#last name
#grade point average
_main__":
__name____ ==
course = Course()
course.add_student (Student('Henry', 'Bendel', 3.6))
course.add_student (Student('Johnny', 'Moin', 2.9))
print(f'Course size: { course.course_size() }')
Transcribed Image Text:class Student: definit__(self, first, last, gpa): self.first = first # first name self.last = last self.gpa = gpa if def get_gpa(self): return self.gpa def get_last (self): return self.last class Course: definit__(self): self.roster = def add_student (self, student): self.roster.append(student) def course_size(self): # Your code goes here 11 #last name #grade point average _main__": __name____ == course = Course() course.add_student (Student('Henry', 'Bendel', 3.6)) course.add_student (Student('Johnny', 'Moin', 2.9)) print(f'Course size: { course.course_size() }')
14.21 LAB: Course size
Complete the Course class by implementing the course_size() instance method, which returns the total number of students in the course.
The file main.py contains:
• The main function for testing the program.
Class Course represents a course, which contains a list of Student objects as a course roster. (Type your code in here.)
• Class Student represents a classroom student, which has three attributes: first name, last name, and GPA.
●
Note: For testing purposes, different student values will be used.
Ex. For the following students:
Henry Bendel 3.6
Johnny Min 2.9
the output is:
Course size: 2
Transcribed Image Text:14.21 LAB: Course size Complete the Course class by implementing the course_size() instance method, which returns the total number of students in the course. The file main.py contains: • The main function for testing the program. Class Course represents a course, which contains a list of Student objects as a course roster. (Type your code in here.) • Class Student represents a classroom student, which has three attributes: first name, last name, and GPA. ● Note: For testing purposes, different student values will be used. Ex. For the following students: Henry Bendel 3.6 Johnny Min 2.9 the output is: Course size: 2
Expert Solution
Step 1

The Algorithm of the code:-

1. Create a class Student with attributes first name, last name, and GPA.

2. Create a class Course with an attributes roster.

3. Define a constructor for the Student class with parameters first, last, and gpa.

4. Define get_gpa(), get_first(), get_last() methods for Student class.

5. Define a constructor for the Course class with a parameter roster.

6. Define add_student() and course_size() methods for Course class.

7. Define a print_roster() method for Course class which prints firstname, lastname and GPA of the student.

8. In the main function, create an instance of the Course class and add two student objects to the roster.

9. Call the print_roster() method of the Course class to print the details of the students in the roster.

10. Print the course size.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education