C++ (C plusplus) Requirements: Use the given class “User” (below) All data members must be declared as “private” No multiple return statements within a function or method No global variable is allowed to be declared and used (constants are ok) Methods within the class and the requested functions cannot have “cin” or “cout” but they should make use of parameters and return value instead unless it is explicitly stated. “cin” and “cout” should be used in main() and testing functions You are required to provide main() and testing functions if any that contains testing code to show how you have tested your classes, methods, and functions. You must show at least one call for each method and function and print out its return values and results correctly.       Define a new exception class named “BadValueException” that must inherit from the exception class. It will manage and capture the general invalid integer and double value. It must be able to describe the reason for the error and save away the erroneous value. In another word, when the caller catches the exception and receives this object, it must know what the reason for the exception is and the actual bad value that caused the exception.     Define a new class named “Student” that must inherit from the given User class. This class manages student info: id (integer), name (string), and gpa (double). It must prevent the creation of a Student object with a negative ID or a GPA that is not between the range of 0.0 and 4.0 by generating a BadValueException error. This class will provide at least the following methods: toString method to return a string representation of the Student object in the format of “ID( ) NAME( ) GPA( )” Such as: ID(1234) NAME(John Smith) GPA(4.00) Note: the GPA must have 2 decimal places. isGPAGreater method that compares its gpa with another student’s gpa. It returns true if its gpa is greater than the other and false otherwise.     Define another new class named “GradStudent” that must inherit from the Student class. This GradStudent class will manage the following info: id, name, gpa, and graduation year (integer). This class should allow the creation of a GradStudent object with or without a given graduation year. If the year is not given, it will default to 2022. Its toString() method should return a string with the graduation year info such as: ID(3000) NAME(Nancy Brown) GPA(3.50) GRADUATION-YEAR(2022)     Write a function named “getLowest” that accepts a vector of pointers to Student objects. It will go through the list and return pointers to the Student or GradStudent with the lowest student ID and GPA. Please note that the vector contains pointers to either Student or GradStudent objects. Please show that you have tested with a vector of pointers of mixed Student and GradStudent objects (in the same vector). For example, if these students and grad students are in the list: Student(2000, "John Smith", 4.0) GradStudent(3000,"Nancy Brown", 3.5, 2021) ; Student(1000, "Bob Johnson", 3.0) ; GradStudent(4000, "Tim Jackson", 2.0, 2020)) ; It will return pointers to these two objects: Lowest ID: ID(1000) NAME(Bob Johnson) GPA(3.00) Lowest GPA: ID(4000) NAME(Tim Jackson) GPA(2.00) GRADUATIONYEAR(2020)     Write a function named “createOneStudent” that will read 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. ///////////////////////////////////////// Given class “User”: class User {  private:                   int m_id ;                   string m_name ;  public:                   User(int id, string name): m_id(id), m_name(name)                   {                   }                   virtual string toString()  {  stringstream ss;  ss << "ID(" << m_id << ") NAME("<< m_name << ")" ;  return ss.str() ;  }  bool isIDLarger(User & another)  {  return m_id > another.m_id ;  } }; Note: you cannot modify this given User class.  ///////////////////////////////////////// Expected result example (attached as a screenshot).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ (C plusplus)

Requirements:

  • Use the given class “User” (below)
  • All data members must be declared as “private”
  • No multiple return statements within a function or method
  • No global variable is allowed to be declared and used (constants are ok)
  • Methods within the class and the requested functions cannot have “cin” or “cout” but they should make use of parameters and return value instead unless it is explicitly stated.
  • “cin” and “cout” should be used in main() and testing functions
  • You are required to provide main() and testing functions if any that contains testing code to show how you have tested your classes, methods, and functions. You must show at least one call for each method and function and print out its return values and results correctly.

 

    Define a new exception class named “BadValueException” that must inherit from the exception class. It will manage and capture the general invalid integer and double value. It must be able to describe the reason for the error and save away the erroneous value. In another word, when the caller catches the exception and receives this object, it must know what the reason for the exception is and the actual bad value that caused the exception.

    Define a new class named “Student” that must inherit from the given User class. This class manages student info: id (integer), name (string), and gpa (double). It must prevent the creation of a Student object with a negative ID or a GPA that is not between the range of 0.0 and 4.0 by generating a BadValueException error.

This class will provide at least the following methods:

  • toString method to return a string representation of the Student object in the format of “ID( <id> ) NAME( <name> ) GPA( <gpa> )” Such as:

ID(1234) NAME(John Smith) GPA(4.00)

Note: the GPA must have 2 decimal places.

  • isGPAGreater method that compares its gpa with another student’s gpa. It returns true if its gpa is greater than the other and false otherwise.

    Define another new class named “GradStudent” that must inherit from the Student class. This GradStudent class will manage the following info: id, name, gpa, and graduation year (integer). This class should allow the creation of a GradStudent object with or without a given graduation year. If the year is not given, it will default to 2022. Its toString() method should return a string with the graduation year info such as:

ID(3000) NAME(Nancy Brown) GPA(3.50) GRADUATION-YEAR(2022)

    Write a function named “getLowest” that accepts a vector of pointers to Student objects. It will go through the list and return pointers to the Student or GradStudent with the lowest student ID and GPA. Please note that the vector contains pointers to either Student or GradStudent objects. Please show that you have tested with a vector of pointers of mixed Student and GradStudent objects (in the same vector).

For example, if these students and grad students are in the list:

Student(2000, "John Smith", 4.0)

GradStudent(3000,"Nancy Brown", 3.5, 2021) ;

Student(1000, "Bob Johnson", 3.0) ;

GradStudent(4000, "Tim Jackson", 2.0, 2020)) ;

It will return pointers to these two objects:

Lowest ID: ID(1000) NAME(Bob Johnson) GPA(3.00)

Lowest GPA: ID(4000) NAME(Tim Jackson) GPA(2.00) GRADUATIONYEAR(2020)

    Write a function named “createOneStudent” that will read 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.

/////////////////////////////////////////

Given class “User”:

class User

{

 private:

                  int m_id ;

                  string m_name ;

 public:

                  User(int id, string name): m_id(id), m_name(name)

                  {

                  }

                  virtual string toString()

 {

 stringstream ss;

 ss << "ID(" << m_id << ") NAME("<< m_name << ")" ;

 return ss.str() ;

 }

 bool isIDLarger(User & another)

 {

 return m_id > another.m_id ;

 }

};

Note: you cannot modify this given User class. 

/////////////////////////////////////////

Expected result example (attached as a screenshot).

 

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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education