CS2303 LAB5/HW5: Student Class in C++ solved

$35.00 $21.00

Category: You will receive a download link of the .ZIP file upon Payment


5/5 - (1 vote)

Create a Student class in a new C++ project with the following private members:
first_ (type string)
last_ (type string)
gpa_ (type float)
id_ (type int)

Note: The use of trailing underscore for these private data member identifiers follows the Google style guide.

and the following public methods:
full_name() const: string
id() const: int
gpa() const: float
print_info() const: void
// print_info() should print in the format (GPA has 2 decimal places):
// Chris Jones, GPA: 3.50, ID: 20146

Use an initializer list in the Student constructor.
Write a function that returns a vector of failing students (those whose gpa is < 1.0). Here is part of the implementation:

* Takes a vector of Student objects, and returns a new vector
* with all Students whose GPA is < 1.0.
vector find_failing_students(const vector &students) {
vector failing_students;

// Iterates through the students vector, appending each student whose gpa is
// less than 1.0 to the failing_students vector.

return failing_students;

Write a function that prints all the students in the supplied vector:
* Takes a vector of Student objects and prints them to the screen.
void print_students(const vector &students) {
// Iterates through the students vector, calling print_info() for each student.

Here’s the main function, which is to be placed at the bottom of the source file:

* Allows the user to enter information for multiple students, then
* find those students whose GPA is below 1.0 and prints them to the
* screen.
int main() {
string first_name, last_name;
float gpa;
int id;
char repeat;
vector students;

do {
cout << “Enter student’s first name: “; cin >> first_name;
cout << “Enter student’s last name: “; cin >> last_name;
gpa = -1;
while (gpa < 0 || gpa > 4) {
cout << “Enter student’s GPA (0.0-4.0): “; cin >> gpa;
cout << “Enter student’s ID: “; cin >> id;
students.push_back(Student(first_name, last_name, gpa, id));
cout << “Add another student to database (Y/N)? “; cin >> repeat;
} while (repeat == ‘Y’ || repeat == ‘y’);

cout << endl << “All students:” << endl;

cout << endl << “Failing students:”;
// Print a space and the word ‘None’ on the same line if no students are
// failing.
// Otherwise, print each failing student on a separate line.

return 0;