Question: Complete the missing codes for this cpp file: #include #include #include person.h #include list.h using namespace std; List::List ( ) { / /

Complete the missing codes for this cpp file:
#include
#include
#include "person.h"
#include "list.h"
using namespace std;
List::List(){
// start index when list is empty
lepos =0;
// initialize the list
for (int i =0; i < MAX_LIST; i++){
plist[i]= Person();
}
}
// add person to system list
void List::add(int id, string name, double salary){
Person p = Person(id, name, salary); // creates person
plist[lepos]= p; // adds person
lepos++; // increment lepos
}
//1. add person to system list at index
void List::addAt(int index, int id, string name, double salary){
// "REMEMBER"
/* You are adding a person to the list at index passed */
/* remove all the comments above/below in this block when you */
/* write codes */
//.................................
//.................................
// Write your codes here
//.................................
//.................................
if(lepos < MAX_LIST && index >0 && index < MAX_LIST){
for(int i = lepos; i >0 && i != index; i--){
plist[lepos +1]= plist[lepos];
}
Person newP(id, name, salary); //create person object
plist[index]= newP; //initialise object to the list
lepos++;
}
}
// removes a person from list by id
void List::remove(int id){
// locate the person
for (int i =0; i < lepos; i++){
// if a match is located
if (plist[i].getId()== id){
// once located, shift elements leftward to replace
// the person to be deleted
for (int j = i; j < lepos; j++){
plist[j]= plist[j +1];
}
cout <<"1 person removed successfully. "<< endl;
lepos--; // decrements list
i = lepos; // set to exit loop
}
}
}
//2. selection sort
void List::selectionSort(){
// "REMEMBER"
/* You are sorting people in the list */
/* remove all the comments above/below in this block when you */
/* write codes */
//.................................
//.................................
// Write your codes here
//.................................
//.................................
int i, j, minIndex;
for (i =0; i < MAX_LIST -1; i++){
minIndex = i;
for (j = i +1; j < MAX_LIST; j++){
// Compare based on some criteria (e.g., ID)
if (plist[j].getId()< plist[minIndex].getId()){
minIndex = j;
}
}
// Swap the Person objects
if (minIndex != i){
Person temp = plist[i];
plist[i]= plist[minIndex];
plist[minIndex]= temp;
}
}
}
//3. quick sort helper function
void quickSorting(Person person[], int left, int right){
// "REMEMBER"
/* You are sorting people in the list */
/* remove all the comments above/below in this block when you */
/* write codes */
//.................................
//.................................
// Write your codes here
//.................................
//.................................
int low = left, high = right, temp;
Person pivot = person[(low + high/2)];
while(low <= high){
while(person[low]< pivot)
low++;
while(person[high]> pivot)
high--;
if(low <= high){
swap(person[low], person[high]);
low++;
high--;
}
};
}
// quick sort root function
void List::quickSort(){// quick sort algorithm
quickSorting(plist,0, lepos -1); // call helper function
}
// searching for the person with largest salary
// using linear search algorithm
Person* List::personLargestSalary(){
// initial maximum salary
int maxindx =0;
// search the next
for (int i =1; i < lepos; i++){
if (plist[i].getSalary()> plist[maxindx].getSalary()){
maxindx = i;
}
}
return &plist[maxindx];
}
// return the people list of the system
Person* List::getList(){
return plist;
}
// returns the size of list showing number of people in list
int List::getLength() const {
return lepos;
}
//4. searches for a person by id using binary search and returns its
// reference if found, otherwise, returns a NULL
Person* List::searchPerson(int id){// binary search
// "REMEMBER"
/* You are searching for a person */
/* remove all the comments above/below in this block when you */
/* write codes */
//.................................
//.................................
// Write your codes here
//.................................
//.................................
int size = sizeof(plist)/sizeof(plist[0]);
int low =0, high = size -1;
int mid =(low + high)/2;
while(mid <= high){
if(plist[mid].getId()== id){

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 Programming Questions!