Lab 8

Lab 8: Arrays of Structs Again

Please download lab8.cpp and finish the lab following the instructions on both webpage and in sample code. 

 

In this lab, you will have more practice about arrays of structs.

We have a database contains peoples' genders, first and last names, their ranking for beach, food, and travel.

Gender    First Name    Last Name    Beach Interest    Food Interest    Travel Interest

M             Tom              Cruise            4                         5                        3

F              Jennifer         Aniston          2                         5                        4

...

...

Your mission is to find the closest match for the user. 

Besides using gender for narrow down the candidates, you should also find a good match for interests. 

The closeness of interest is defined by Minkowski Distance of order 1

------------------------------------------------------------------------------------------------------------------------------------------------------------------

  For a point (x1, x2, ...,xn) and a point (y1, y2, ...,yn), the Minkowski distance of order p (p-norm distance) is defined as:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

In other words:

closeness_score   =    absolute value of (person1.BeachInterest - person2.BeachInterest) 

                                 + absolute value of (person1.FoodInterest  -  person2.FoodInterest)

                                 + absolute value of (person1.TravelInterest - person2.TravelInterest)

The smaller the closeness score is, the closer person 1 and person 2 are. 

The person has smallest closeness score with user input, is the best match for the user. 

Note : You can find the absolute value of a number a using the function abs(a).

1 point:

Complete the struct to make the array definition we've given in main() work correctly.

Complete the "displayList" function to display the list of all people

2 points:

According to the user input, find the first closest match from the database and display it.

If there are more than one closest match in the database, simply choose the first one.

3 points:

If there are more than one closest match in the database, display all of them.