Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I test this code using constructors in my main program. // Code to find a student based on id // Returns a Student

How would I test this code using constructors in my main program.

// Code to find a student based on id

// Returns a Student object

Student Student::findStudent(int id) {

std::vector students;

students.push_back(*this);

for (int i = 0; i < students.size(); i++)

{

if (students[i].getId() == id) {

return students[i];

}

}

return Student();

}

// Code to list all students with gpa greater than the passed gpa value

// Displays appropriate message if no students are found

void Student::listStudents(double gpa) {

std::vector students;

students.push_back(*this);

for (int i = 0; i < students.size(); i++) {

if (students[i].getGpa() >= gpa) {

std::cout << "Student ID: " << students[i].getId() << " Name: " << students[i].getFirstName() << " "

<< students[i].getLastName() << " Major: " << students[i].getMajor() << " GPA: "

<< students[i].getGpa() << std::endl;

}

}

}

// Code to list all students with same major as one passed

// Displays appropriate message if no students are found

void Student::listStudents(string major) {

std::vector students;

students.push_back(*this);

for (int i = 0; i < students.size(); i++) {

if (students[i].getMajor() == major) {

std::cout << "Student ID: " << students[i].getId() << " Name: " << students[i].getFirstName() << " "

<< students[i].getLastName() << " Major: " << students[i].getMajor() << " GPA: "

<< students[i].getGpa() << std::endl;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions