Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following declaration: const int MAX_CHAR = 100; struct Student { char

ID: 3695067 • Letter: G

Question

Given the following declaration:

const int MAX_CHAR = 100;

struct Student

{

   char id[MAX_CHAR];

   float gpa;

};

const int MAX_CAP = 10;

class StudentList

{

public:

   int search(const char id[ ], Student& match) const;

   bool get(int index, Student& aStudent) const;

   bool remove(const char id[ ], Student& aStudent);

   …

private:

   Student    list[MAX_CAP];

   int        size;

};

Implement the function: bool StudentList::remove(const char id[ ], Student& aStudent);

The function removes a student object with “id” from the list and copies the deleted student into “aStudent.” It returns true if the operation is successful and false if no matching id could be found.

Explanation / Answer

bool StudentList::remove(const char id[ ], Student& aStudent)
{
bool flag = false;
for(int i=0;i<size;i++)
{
if(strcmp(id,list[i].id)==0)
{
flag = true;
size--;
break;
}
}
for(;i<size;i++)
{
list[i]=list[i+1];
}
return flag;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote