Complete the Course class by implementing the FindHighestStudent() member function, which returns the Student object with the highest GPA in the course. Assume that no two students have the same highest GPA. Given classes: Class Course represents a course, which contains a vector of Student objects as a course roster. (Type your code in here.) Class Student represents a classroom student, which has three private data members: first name, last name, and GPA. (Hint: GetGPA() returns a student's GPA.) Note: For testing purposes, different student values will be used. Ex. For the following students: Henry Nguyen 3.5 Brenda Stern 2.0 Lynda Robison 3.2 Sonya King 3.9 the output is: Top student: Sonya King (GPA: 3.9)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

23.16 LAB: Find student with highest GPA

Complete the Course class by implementing the FindHighestStudent() member function, which returns the Student object with the highest GPA in the course. Assume that no two students have the same highest GPA.

Given classes:

  • Class Course represents a course, which contains a vector of Student objects as a course roster. (Type your code in here.)
  • Class Student represents a classroom student, which has three private data members: first name, last name, and GPA. (Hint: GetGPA() returns a student's GPA.)

Note: For testing purposes, different student values will be used.

Ex. For the following students:

Henry Nguyen 3.5 Brenda Stern 2.0 Lynda Robison 3.2 Sonya King 3.9

the output is:

Top student: Sonya King (GPA: 3.9)
 
------
 
course.cpp
----

#include <iostream>
#include "Course.h"
using namespace std;

Student Course::FindStudentHighestGpa() {
/* Type your code here */
}

void Course::AddStudent(Student s) {
roster.push_back(s);
}

 

-----

course.h

------

#ifndef COURSE_H
#define COURSE_H

#include <vector>
#include "Student.h"

class Course {
public:
Student FindStudentHighestGpa();
void AddStudent(Student s);

private:
vector<Student> roster; //collection of Student objects
};

#endif

 

-----

main.cpp

------

#include <iostream>
#include <iomanip>
#include <string>
#include "Course.h"
using namespace std;

int main() {
Course course;
string fname;
string lname;
string gpa;

// Example students for testing
course.AddStudent(Student("Henry", "Nguyen", 3.5));
course.AddStudent(Student("Brenda", "Stern", 2.0));
course.AddStudent(Student("Lynda", "Robison", 3.2));
course.AddStudent(Student("Sonya", "King", 3.9));

Student student = course.FindStudentHighestGpa();
cout << "Top student: " << student.GetFirst() << " " << student.GetLast() << " (GPA: " << student.GetGPA() << ")" << endl;

return 0;
}

 

------

student.h

-------

#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

// Class representing a student
class Student {
public:
Student(string first, string last, double gpa);
double GetGPA() ;
string GetLast();
string GetFirst();

private:
string first; // first name
string last; // last name
double gpa; // grade point average
};

#endif

 

------

student.cpp

----

#include "Student.h"

// Student class constructor
Student::Student(string first, string last, double gpa) {
this->first = first; // first name
this->last = last; // last name
this->gpa = gpa; // grade point average
}

double Student::GetGPA() {
return gpa;
}

string Student::GetLast() {
return last;
}

string Student::GetFirst() {
return first;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY