#K91272. University GPA Calculation

    ID: 37939 Type: Default 1000ms 256MiB

University GPA Calculation

University GPA Calculation

You are required to implement a University management system. In this system, you must support three operations:

  1. register: Register a new student. Each registration generates a unique student ID which is printed to stdout.
  2. assign: Assign a grade to a student for a specific course. A student may receive multiple grades for the same course; however, only the highest grade for each course is considered.
  3. calculate: Calculate and output the GPA of a student. The GPA is computed as the average of the highest grades in each course. In mathematical terms, if a student has enrolled in n courses with the highest grades \(g_1, g_2, \dots, g_n\), then the GPA is given by: \[ \text{GPA} = \frac{\sum_{i=1}^{n} g_i}{n} \] If a student has not received any grades, the GPA is considered to be 0.0.

The input is given via standard input, and all outputs must be printed to standard output.

inputFormat

The first line of input contains an integer T denoting the number of operations. Each of the following T lines contains one of the following commands:

  • register - Register a new student. No additional arguments.
  • assign student_id course_id grade - Assign a grade (a float) to the student with the given student_id for the specified course_id.
  • calculate student_id - Calculate and output the GPA of the student with the given student_id.

outputFormat

For each command that is expected to produce an output:

  • register: Print the generated student ID as an integer on a new line.
  • calculate: Print the GPA of the student as a floating point number. If the student has not received any grades, print 0.0.

No output is expected for the assign command.

## sample
6
register
register
assign 1 101 85.5
assign 1 101 90
assign 1 102 71
calculate 1
1

2 80.5

</p>