#C14346. Student Record Manager
Student Record Manager
Student Record Manager
You are given the task of implementing a data structure to manage student records. The data structure supports the following operations:
- ADD: Adds a new student record with a given student ID and name.
- REMOVE: Removes the student record with the given student ID. If the student exists, removal is successful.
- GET: Retrieves the name of the student with the provided ID. If the student does not exist, output
None
.
Internally, you should maintain a mapping from the student ID to the student name. You are required to implement the operations to support an interactive command based system. In your implementation, the commands will be provided from standard input and your output should be printed to standard output.
Formally, you need to implement a class (or equivalent) called StudentManager
with the following methods:
- \( add\_student(student\_id, student\_name) \): Adds a student record.
- \( remove\_student(student\_id) \): Removes the record and returns \( \texttt{True} \) if removal was successful or \( \texttt{False} \) if the student did not exist.
- \( get\_student(student\_id) \): Returns the student name if it exists or \( \texttt{None} \) otherwise.
inputFormat
The first line contains an integer \( n \) denoting the number of commands. Each of the following \( n \) lines contains a command. Each command is formatted as follows:
ADD [student_id] [student_name]
: wherestudent_id
is an integer andstudent_name
is a string (it may contain spaces).REMOVE [student_id]
: removes the student record with the given ID.GET [student_id]
: retrieves the record associated with the specified student ID.
For ADD
commands, no output is expected. For REMOVE
and GET
commands, print the result on a separate line.
outputFormat
For each REMOVE
and GET
command, output the result on a new line:
- For a
REMOVE
command, outputTrue
if a record was removed, otherwiseFalse
. - For a
GET
command, output the student's name if found; otherwise, outputNone
.
4
ADD 1 John
GET 1
REMOVE 1
GET 1
John
True
None
</p>