Question: 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

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!