Question: // Student.cpp #include student.h #include #include #include using std::string; using std::ostream; using std::istream; using std::setw; void Initialize(Student& student){ for (size_t i = 0; i <

// Student.cpp

#include "student.h"

#include
#include
#include
using std::string;
using std::ostream;
using std::istream;
using std::setw;
void Initialize(Student& student){
for (size_t i = 0; i < MAX_GRADES; i++)
student.grades[i] = 0;
}
void WriteStudent(const Student& student, ostream& out){
out << setw(8) << student.id << setw(15) << student.name;
for (size_t i=0; i < MAX_GRADES; i++)
out << setw(5) << student.grades[i];
}
void ReadStudent(Student& student, istream& in){
in >> student.id >> student.name;
for (size_t i=0; i < MAX_GRADES; i++)
in >> student.grades[i];
}
int GetGrade(const Student& student, size_t index){
if (index >= MAX_GRADES)
return -1;
return student.grades[index];
}
bool SetGrade(Student& student, size_t index, int grade){
if (index >= MAX_GRADES)
return false;
student.grades[index] = grade;
return true;
}
int GetAverage(const Student& student){
int average = 0;
for (size_t i=0; i < MAX_GRADES; i++)
average += student.grades[i];
return average / MAX_GRADES;
}

// StudentList.cpp

#include "student.h"

#include "studentlist.h"
#include
#include
using std::string;
using std::ostream;
using std::endl;
void Initialize(StudentList& list){
list.size = 0;
}
bool AddStudent(StudentList& list, const Student& student){
if (list.size == MAX_STUDENTS)
return false;
list.roster[list.size] = student;
list.size++;
return true;
}
void SortStudents(StudentList& list){
if (list.size <= 1)
return;
for (size_t i = 0; i < list.size; i++)
for (size_t j = 0; j < list.size - i - 1; j++)
if (list.roster[j].id > list.roster[j + 1].id){ // Swap
Student temporal = list.roster[j];
list.roster[j] = list.roster[j + 1];
list.roster[j + 1] = temporal;
}
}
void WriteStudentList(const StudentList& list, ostream& out){
for (size_t i = 0; i < list.size; i++){
WriteStudent(list.roster[i], out);
out << endl;
}

write two additional functions to the StudentList interface:

// This function tries to retrieve the student at position index // if the position is invalid the function returns false // if the position is valid it copies the student to the parameter // student and returns true bool GetStudent(const StudentList& list, size_t index, Student& student); // This function takes in an id, tries to find that id in the roster // to retrieve the id it will use the GetStudentId function describe ahead // The function will return the position of the student if it finds it // it will return -1 if there are no students with that id int FindStudent(const StudentList& list, const string& id);

Add an additional function to the Student interface:

// This function purpose is to return the id of the student sent as parameter string GetStudentId(const Student& student); 

Once this functions are implemented, add an additional option to the menu: Search student, the user will input an id, the program will look for that student, if it finds it, the program will display the student information, if it doesn't find it, it will print a message telling the used that that id was not found.

Important: Instead of using linear search on FindStudent, use binary search, remember to validate that the list is sorted

}

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!