in c++ Write a function named createOneStudent that will read in from the user the student info: id, name and gpa. It will use try-catch to handle the exception if the user provides a negative id or gpa that is out of bound (< 0.0 or > 4.0) by asking the user to re-enter them. It must provide the correct reason for the error and the actual error value. Then it will allow the user to try up to 3 times. This function will return the pointer of a newly created Student object or nullptr if the info is still incorrect. Note that this function can and will use cin and cout to read in values from the user. Here is an example of a run up to 3 times: Enter ID: -1 Enter GPA: 4.0 Enter name: John Smith Exception: negative id: -1 Enter ID: 1234 Enter GPA: 5.0 Enter name: John Smith Exception: out of bound gpa: 5.00 Enter ID: 1234 Enter GPA: 4.0 Enter name: John Smith ID(1234) NAME(John Smith) GPA(4.00) Here is an example of a run of 3 times and still not able to create it: Enter ID: 1234 Enter GPA: -1.25 Enter name: John Smith Exception: out of bound gpa: -1.25 Enter ID: 1234 Enter GPA: 5.5 Enter name: John Smith Exception: out of bound gpa: 5.50 Enter ID: -1234 Enter GPA: 4.0 Enter name: John Smith Exception: negative id: -1234 Unable to create student
in c++
Write a function named createOneStudent that will read in from the user the
student info: id, name and gpa.
It will use try-catch to handle the exception if the user provides a negative id or
gpa that is out of bound (< 0.0 or > 4.0) by asking the user to re-enter them. It
must provide the correct reason for the error and the actual error value. Then it
will allow the user to try up to 3 times. This function will return the pointer of a
newly created Student object or nullptr if the info is still incorrect.
Note that this function can and will use cin and cout to read in values from the
user.
Here is an example of a run up to 3 times:
Enter ID: -1
Enter GPA: 4.0
Enter name: John Smith
Exception: negative id: -1
Enter ID: 1234
Enter GPA: 5.0
Enter name: John Smith
Exception: out of bound gpa: 5.00
Enter ID: 1234
Enter GPA: 4.0
Enter name: John Smith
ID(1234) NAME(John Smith) GPA(4.00)
Here is an example of a run of 3 times and still not able to create it:
Enter ID: 1234
Enter GPA: -1.25
Enter name: John Smith
Exception: out of bound gpa: -1.25
Enter ID: 1234
Enter GPA: 5.5
Enter name: John Smith
Exception: out of bound gpa: 5.50
Enter ID: -1234
Enter GPA: 4.0
Enter name: John Smith
Exception: negative id: -1234
Unable to create student
Step by step
Solved in 4 steps with 3 images