473,466 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rating the suitors?

4 New Member
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.
Mar 18 '07 #1
9 1897
DeMan
1,806 Top Contributor
There is more than one approach, but here is one idea.....
(I will assume for now that you know how to read input, and a reasonably familiar with most programming techniques and describe how, without giving code)
make a Data Structure that stores FirstName, Surname, HeightDifference, WeightDifference (where The HeightDifference is abs(180 - height) and similarly for weight) (we'll call this data structure Suitor...)

Create an Array to store the Suitors that you have made....

Now as I understand, to use the qSort, you need to implement a comparison function following a prototype something like:
Expand|Select|Wrap|Line Numbers
  1. int suitorCompare(const void* first, const void* second)
  2.  
this Comparator should return 0 if both items are equal, -1 if the first is less than the second and 1 if the first is greater than the second.

Casting first and second to a pointer to Suitor (defined earlier), means we can access the elements within the struncture, and the basic comparison would be (in pseudocode to show logic, I leave iot to you to implement):

Expand|Select|Wrap|Line Numbers
  1. if(((Suitor*)first->HeightDifference) > ((Suitor*)second->HeightDifference))
  2. {
  3.   return 1;
  4. }
  5. else if )((Suitor*)first->HeightDifference) == ((Suitor*)second->HeightDifference))
  6. {
  7.   if(((Suitor*)first->WeightDifference) > ((Suitor*)second->WeightDifference))
  8.   {
  9.     return 1;
  10.   }
  11.   else if(((Suitor*)first->WeightDifference) == ((Suitor*)second->WeightDifference))
  12.   {
  13.       /* Do comparisons for Surname then Name (you can use strcmp for this) 
  14.          You want to if surnames are then compare names otherwise return the
  15.          result of the strcmp */
  16.   }
  17.   /* If we get this far, then one of the comparisons failed so second is greater */
  18.   return -1;
  19. }
  20.  
Once you have your method implemented, you can call
Expand|Select|Wrap|Line Numbers
  1.  qsort (SuitorArray, numberOfSuitors, sizeof(Suitor), suitorCompare);
  2.  
where SuitorArray is replaced by whatever you called the array of suitors, numberOfSuitors is the size of the Array, sizeof(Suitor) will return the size of each Suitor element, and suitorCompare is the name of the function you have made for the comparison.
Mar 18 '07 #2
willakawill
1,646 Top Contributor
Hmmm. Looks like you both have stepped outside the posting guidelines with regard to assignments or projects. This will not benefit the reputation of TSDN within academic institutions.
Mar 19 '07 #3
DeMan
1,806 Top Contributor
Hmmmmm have I?
Mar 19 '07 #4
bluevega
4 New Member
thank you very much DeMan! thanks a lot for that....
i decided to do it in array of structure just like what you have said..
and somehow.. i'm making progress...
sorry for the trouble that i have caused you..

in your quicksort func you have given me 4 parameters... what i have developed has only 3 parameters.. can you tell me what is the inside of that function that you're telling me? does it still need partition?

thanks a lot...
Mar 19 '07 #5
willakawill
1,646 Top Contributor
Hmmmmm have I?
Well let's have a look:
If it appears that the question has just been pasted directly from a text book or coursework assignment our moderators have been instructed to meet this with a set response. This is a pre-written message asking you to make some attempt at the assignment yourself before asking questions about specific problems and referring you to this FAQ
Mar 19 '07 #6
bluevega
4 New Member
oh i'm sorry i'm not aware of that.. but of course.. my intention is that i'm just asking some other way than what i'm doing (i'm already doing it on my own before i ask this question) and i'll try to look on what approach it will better, their suggestion or my work.. again sorry for that..
Mar 19 '07 #7
DeMan
1,806 Top Contributor
Well let's have a look:
If it appears that the question has just been pasted directly from a text book or coursework assignment our moderators have been instructed to meet this with a set response. This is a pre-written message asking you to make some attempt at the assignment yourself before asking questions about specific problems and referring you to this FAQ
Firstly, If there is a problem here: "moderators have been instructed to meet this with a set response" Maybe your outside the Guidelines too....

Secondly, there is a clear question here.....
The poster has made no bones about the fact that this is an assignment he (or she) wants HELP STARTING. I have not posted a solution for him (or her), but have offered some suggestions on how he (or she) might address the problem on the way to finding a solution.

Please make sure you have asked an actual question worded in English outside of the text of your assignment that you have posted.
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?..


I'll concede that maybe I violated the letter of the law in the guidelines, but essentially the idea is to offer help not solutions....I have explained how this question might be approached, and what certain parts of the question may be, and don't believe I have breached the idea behind the guidelines. If you feel that there is a problem with any of this, perhaps you should bring this to the attention to Admin.
Mar 19 '07 #8
DeMan
1,806 Top Contributor
in your quicksort func you have given me 4 parameters... what i have developed has only 3 parameters.. can you tell me what is the inside of that function that you're telling me?
The qsort used above is the one mentioned in your original post...

2. You might want to use the qsort() function, which is part of cstdlib, to do the sorting.
which takes as parameters: the Array to be sorted, the number of elements in the array, the size of each element and Comparator function to use for the sorting.
Mar 19 '07 #9
bluevega
4 New Member
thanks again! =) somehow everything is ok... just having problems with the parameters of my functions and making the array of structures (it seems that what i'm doing is that it does not accept a structure nor making array of it)... some arguments.. sorry for the trouble again and thanks a lot =)
Mar 20 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jeremy | last post by:
this is probably a simple sql solution, but i could use some help. i've got one table that has rows of documents, and another table with any number of ratings for each of the documents. The rating...
2
by: alex | last post by:
I need a more advanced formula than just an average for calculating items rating. I have: raitng value is on scale 1 to 10. s - sum of all ratings for an item n - number of rates (votes)
0
by: soma | last post by:
I have a rating system on a forum I'm building. Users can rate a topic either good or bad. For each Good rating, one point is added to the topic's score. For every Bad rating, one point is subtracted...
8
by: kp87 | last post by:
I am a little bit stuck .... I want to play a bunch of soundfiles randomly, but i want to give each soundfile a rating (say 0-100) and have the likelihood that the file be chosen be tied to its...
2
by: Baron Samedi | last post by:
I am looking for a simple rating script whcih does not require SQL. Thanks in advance for any help.
4
by: bp90210 | last post by:
If you have a few minutes, I would like to see if anyone can help me out. I'm trying to modify a rating script. Currently, It allows you to vote over and over. What I want to do is after you vote...
4
by: clintonG | last post by:
I've been searching around and also ask for your recommendations for a rating solution, i.e. I'm a small potato and prefer C# open-source at no cost but also seek recommendations for commercial...
1
by: lamarant | last post by:
Hi...I'm trying to use the Rating Control in the Ajax Toolkit in a datalist. I have the control showing up in the list, with the logged in users current rating for each item in the list showing... ...
1
pradeepjain
by: pradeepjain | last post by:
Hii guys , I have several products in my mysql database and i wanna allow the authorized users to rate the products !! i am clear till this point like it has to be done with the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.