Question: #include #include #include using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float

#include  #include  #include  using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void Read(); private: int Uaid; string Name; float Gpa; }; Student::Student() { Uaid = 0; Name = "none"; Gpa = 0; } Student::Student(const Student & student) { Uaid = student.Uaid; Name = student.Name; Gpa = student.Gpa; } Student::~Student() { } void Student::Set(const int uaid, const string name, const float gpa) { Uaid = uaid; Name = name; Gpa = gpa; if (Gpa < 0.0) Gpa = 0.0; else if (Gpa > 4.0) Gpa = 4.0; } void Student::Get(int &uaid, string & name, float &gpa) const { uaid = Uaid; name = Name; gpa = Gpa; } void Student::Print() const { cout << Uaid << " " << Name << " " << Gpa << endl; } void Student::Read() { cin >> Uaid >> Name >> Gpa; if (Gpa < 0.0) Gpa = 0.0; else if (Gpa > 4.0) Gpa = 4.0; } class Course { public: Course(const int count=0); Course(const Course & course); ~Course(); void Print() const; void Read(); private: static const int MAX_STUDENTS = 100; Student students[MAX_STUDENTS]; int num_students; }; Course::Course(const int count) { // ADD HERE } Course::Course(const Course & course) { // ADD HERE } Course::~Course() { // ADD HERE } void Course::Print() const { // ADD HERE } void Course::Read() { // ADD HERE } int main() { cout << "Testing Student class "; Student student1; student1.Set(1234, "John", 2.5); student1.Print(); cout << "Testing Course class "; Course course(5); course.Print(); course.Read(); course.Print(); return 0; } 

Step 1: Copy this program into your C++ program editor, and compile it. Hopefully you will not get any error messages. When you run your program it should print the following familiar messages:

 

Testing Student class 1234 John 2.5 Testing Course class

Step 2: You probably noticed that the implementation of the Course methods were all empty except for a comment. Go back to your solution to lab12b, and copy/paste your implementation of these methods into your current program. Now when you compile and run the program, you should see:

 

Testing Student class 1234 John 2.5 Testing Course class Constructor Print 0 none 0 0 none 0 0 none 0 0 none 0 0 none 0 Read

The program is waiting for you to enter information for five students, so copy paste the following into your program input, and your program should print these values back out again.

 

1234 Susan 3.9 2345 John 3.2 3456 Laura 3.8 4567 Brian 3.5 5678 David 3.1

Step 3: So far, all we can do with the Course class is read and print information. Lets extend this class by adding a method called "TopStudents" that searches the array of Student objects to find and print all students with a GPA above a given value. Modify the Course class header to add your TopStudents method. Then, create a skeleton implementation of this method that simply prints out the name of the method. Finally, add the following call to TopStudents at the bottom of your main program. Make sure this code compiles before going on to the next step.

 

course.TopStudents(3.5);

Step 4: Now it is time to complete the implementation of the TopStudents method. Add a loop that processes the array of Students to find students with a GPA greater than or equal to than the input value. Remember, the private variables in the Student class are not visible in the Course class, so you will have to use the Student Get method.

Step 5: To test the TopStudents method, copy paste the student information above into a file called "students.txt". If your program is called "lab.exe" you can type "./lab.exe < student.txt" to run the program and the contents of student.txt will be read into the program. When you do this, you should see the following

 

Testing Student class 1234 John 2.5 Testing Course class Constructor Print 0 none 0 0 none 0 0 none 0 0 none 0 0 none 0 Read Print 1234 Susan 3.9 2345 John 3.2 3456 Laura 3.8 4567 Brian 3.5 5678 David 3.1 TopStudents 1234 Susan 3.9 3456 Laura 3.8 4567 Brian 3.5 Destructor

Now that you have added one method that processes the Student array it gives you a template to follow for any new methods you may add in the future, such as a method to find student with the highest GPA, or a method to find all students that should be on probation. This is one of the keys to successful incremental software development.

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!