30 Day code challenge-python

Ganesh Uthiravasagam
2 min readMar 19, 2021

--

Day 12–Instances

Task

You are given two classes, Person and Student, where Person is the base class and Student is the derived class. Completed code for Person and a declaration for Student are provided for you in the editor. Observe that Student inherits all the properties of Person.

  • A Student class constructor, which has parameters:
  1. A string, firstName.
  2. A string, lastName.
  3. An integer, idNumber.
  4. An integer array (or vector) of test scores, scores.
  • A char calculate() method that calculates a Student object’s average and returns the grade character representative of their calculated average.
Sample input and output

Input Format

The first line contains firstName, lastName, and idNumber, separated by a space. The second line contains the number of test scores. The third line of space-separated integers describes scores.

Output Format

The Output will be correct if your Student class constructor and calculate() method are properly implemented.

Solution

Explanation

Line 38: Gets input from the user and splits the 3 values

Line 39–41: Assigns the values to the variables. Similarly, the score value is also created

Line 45: Calls the function printPerson which prints the firstName, lastName, idnumber

Line 46: Calls the class calculate

Line 10–13: Student class inherits the Person class.

Line 15–34: Based on the average score, the grade of a student is generated and gets displayed.

Bonus Tip: Using super() function the values of the parent class can be stored in the child class.

See you on day 13

--

--

No responses yet