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

C++ MyProgrammingLab problem: Given a data type struct Person{ string name ; dou

ID: 3563123 • Letter: C

Question

C++ MyProgrammingLab problem:

Given a data type  
struct Person{string  name ; double height;};

and a function

bool lessThan(const Person & a, const Person & b)

define a function

void sort(Person people[], int length)

that sorts people in ascending order according to the lessThan() relation.

Notice that we are sorting the elements according to two "levels": the first level is by name and the second level is by height (within people of the same name ).

Note: The function lessThan() returns true if a's name is less than b's name and false if a's name is greater than b's name . If the names are equal , then it will return true if a's height is less then b's height and false otherwise.

This function is provided for you, so don't need to reimplement it here.

Also, do not write the entire program.

Explanation / Answer

void sort (Person people[], int length)

   {

      int min;

     Person temp;

       for (int index = 0; index < length-1; index++)

      {

         min = index;

         for (int scan = index+1; scan < list.length; scan++)

         if(lessThan(people[min],people[scan]))

               min = scan;

         // Swap the values

         temp = people[min];

         people[min] = people[index];

         people[index] = temp;

      }

   }

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