Question: Objective: After completion of this lab, you will be able to define and use your own C++ class. Lab Exercises Create a new project named

Objective:

After completion of this lab, you will be able to

  • define and use your own C++ class.

Lab Exercises

  1. Create a new project named lab5 and create a class named Student to store student information. Information that will be relevant to store are name, id number, and GPA.
    1. Define a member function named summary() that prints a summary of the students information. You can choose how this data is formatted to the screen (something readable please).
    2. Create setter and getter functions for the private member variables of the Student class that are needed to run the program.
      1. Make sure that the setters for id and GPA only take positive numbers.
    3. Create a set() function, which allows you to set all member variables at once.
    4. Create a default constructor that sets the default values of Student class to (Unknown, 9999, 0).

Test your class with the driver program given below. If you find any problems with the driver program, fix them.

//--- Test driver for class Student #include  #include  #include "Student.h" using namespace std; int main() { Student alicia, benji, carmen, david; alicia.set("Alicia", 1234, 4.0); benji.set("Benji", 5678, 3.8); carmen.set("Carmen", 9012, 3.5); alicia.summary(); alicia.setGPA(3.9); alicia.summary(); cout << "Benjis ID: " << benji.getID() << " "; benji.setID(5679); benji.summary(); carmen.summary(); alicia.setGPA(-3.6); alicia.summary(); david.summary(); return 0; }

Sample Run (User input in bold):

Name: Alicia ID: 1234 GPA: 4.00 Name: Alicia ID: 1234 GPA: 3.90 Benji's ID: 5678 Name: Benji ID: 5679 GPA: 3.80 Name: Carmen ID: 9012 GPA: 3.50 Error: GPA must be a positive value. Name: Alicia ID: 1234 GPA: 3.90 Name: Unknown ID: 9999 GPA: 0.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!