well i have a project here and i dont how to start it...
here is the specs of it.
what shall i do? binary search tree? but how? use a quick sort?..
please help me... thanks
Rating the Suitors
Pretty Polly has no shortage of gentlemen suitors who come courting. Indeed, her biggest problem is keeping track of who the best ones are. She is smart enough to realize that a program which ranks the men from most to least desirable would simplify her life. She is also persuasive enough to have talked you into writing the program.
Polly really likes to dance, and has determined the optimal partner height is 180 cm tall. Her first criteria is finding someone who is as close as possible to this height; whether they are little taller or shorter doesn’t matter. Among all candidates of the same height, she wants someone as close as possible to 75 kg without going over. If all equal-height candidates are over this limit, she will take the lightest of the bunch. If two or more people are identical by all these
characteristics , sort them by last name, then by first name if necessary to break the tie.
Polly is only interested in seeing the candidates ranked by name, so the input file:
George Bush 195 110
Harry Truman 180 75
Bill Clinton 180 75
John Kennedy 180 65
Ronald Reagan 165 110
Richard Nixon 170 70
Jimmy Carter 180 77
yields the following output:
Clinton, Bill
Truman, Harry
Kennedy, John
Carter, Jimmy
Nixon, Richard
Bush, George
Reagan, Ronald
Input: Assume input is in a file having the filename suitors.txt
Output: Standard console
Hint:
1. It would be better if you will not store the actual height and weight of the suitors, since Polly’s rating criteria for heights and weights are quite fussy, revolving around how these quantities compare to a reference height/weight instead of a usual linear order (i.e., increasing or decreasing). You can alter the height and weight appropriately so the quantities were linearly ordered by desirability.
2. You might want to use the qsort() function, which is part of cstdlib, to do the sorting.
here is the specs of it.
what shall i do? binary search tree? but how? use a quick sort?..
please help me... thanks
Rating the Suitors
Pretty Polly has no shortage of gentlemen suitors who come courting. Indeed, her biggest problem is keeping track of who the best ones are. She is smart enough to realize that a program which ranks the men from most to least desirable would simplify her life. She is also persuasive enough to have talked you into writing the program.
Polly really likes to dance, and has determined the optimal partner height is 180 cm tall. Her first criteria is finding someone who is as close as possible to this height; whether they are little taller or shorter doesn’t matter. Among all candidates of the same height, she wants someone as close as possible to 75 kg without going over. If all equal-height candidates are over this limit, she will take the lightest of the bunch. If two or more people are identical by all these
characteristics , sort them by last name, then by first name if necessary to break the tie.
Polly is only interested in seeing the candidates ranked by name, so the input file:
George Bush 195 110
Harry Truman 180 75
Bill Clinton 180 75
John Kennedy 180 65
Ronald Reagan 165 110
Richard Nixon 170 70
Jimmy Carter 180 77
yields the following output:
Clinton, Bill
Truman, Harry
Kennedy, John
Carter, Jimmy
Nixon, Richard
Bush, George
Reagan, Ronald
Input: Assume input is in a file having the filename suitors.txt
Output: Standard console
Hint:
1. It would be better if you will not store the actual height and weight of the suitors, since Polly’s rating criteria for heights and weights are quite fussy, revolving around how these quantities compare to a reference height/weight instead of a usual linear order (i.e., increasing or decreasing). You can alter the height and weight appropriately so the quantities were linearly ordered by desirability.
2. You might want to use the qsort() function, which is part of cstdlib, to do the sorting.
Comment