#K13426. Student Grades Management
Student Grades Management
Student Grades Management
This problem requires you to implement a simple student grades management system that supports three operations. The system maintains a list of students and their grades. The supported operations are:
- ADD name grade: Add a student with the given name and grade (an integer) to the system. If the student already exists, their grade is updated.
- REMOVE name: Remove the student with the given name from the system. Print
True
if the removal is successful andFalse
if no such student exists. - AVERAGE: Compute and print the average grade of all students in the system using the formula $$\bar{x} = \frac{\sum_{i=1}^{n} x_i}{n}$$. The average should be printed as a floating point number with one decimal place. If there are no students, the average is 0.0.
Each command is read from standard input and the responses for REMOVE and AVERAGE commands should be printed to standard output.
inputFormat
The first line of input contains an integer T, the total number of operations. Each of the next T lines contains one of the following commands:
ADD name grade
REMOVE name
AVERAGE
Names are strings without spaces and grades are integers.
outputFormat
For each REMOVE
and AVERAGE
operation, print the result on a new line. For REMOVE
, print True
or False
(without quotes). For AVERAGE
, print the average grade as a floating point number rounded to one decimal place.
6
ADD Alice 90
ADD Bob 80
AVERAGE
REMOVE Alice
AVERAGE
REMOVE Bob
85.0
True
80.0
True
</p>