to find best matches b/w two couples by comparing their answers...

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
PLZZZZ....HELP ME TO SOLVE THIS PROBLEM....I HAV TRIED BUT THEIR ARE MANY RUN TIME ERRORS...<br/>
<br/>
DEFINITION<br/>
Class Name: MatchMaker<br/>
Method Name: getBestMatches<br/>
Paramaters: String[], String, int<br/>
Returns: String[]<br/>
Method signature (be sure your method is public): String[]<br/>
getBestMatches(String[] members, String currentUser, int sf);<br/>
(be sure your method is public)<br/>
<br/>
PROBLEM STATEMENT<br/>
A new online match making company needs some software to help find the "perfect<br/>
couples". People who sign up answer a series of multiple-choice questions.<br/>
Then, when a member makes a "Get Best Mates" request, the software returns a<br/>
list of users whose gender matches the requested gender and whose answers to<br/>
the questions were equal to or greater than a similarity factor when compared<br/>
to the users answers.<br/>
<br/>
Implement a class MatchMaker, which contains a method getBestMatches. The<br/>
method takes as parameters a String[] members, String currentUser, and an int sf:<br/>
- members contains information about all the members. Elements of members are<br/>
of the form "NAME G D X X X X X X X X X X" <br/>
* NAME represents the members name<br/>
* G represents the gender of the current user.<br/>
* D represents the requested gender of the potential mate.<br/>
* Each X indicates the members answer to one of the multiple-choice<br/>
questions. The first X is the answer to the first question, the second is the<br/>
answer to the second question, et cetera.<br/>
- currentUser is the name of the user who made the "Get Best Mates" request.<br/>
- sf is an integer representing the similarity factor.<br/>
<br/>
The method returns a String[] consisting of members names who have at least sf<br/>
identical answers to currentUser and are of the requested gender. The names<br/>
should be returned in order from most identical answers to least. If two<br/>
members have the same number of identical answers as the currentUser, the names<br/>
should be returned in the same relative order they were inputted.<br/>
<br/>
Inputs are valid if all of<br/>
the following criteria are met:<br/>
- members will have between 1 and 50 elements, inclusive.<br/>
- Each element of members will have a length between 7 and 44, inclusive.<br/>
- NAME will have a length between 1 and 20, inclusive, and only contain<br/>
uppercase letters A-Z.<br/>
- G can be either an uppercase M or an uppercase F.<br/>
- D can be either an uppercase M or an uppercase F.<br/>
- Each X is a capital letter (A-D).<br/>
- The number of Xs in each element of the members is equal. The number of Xs<br/>
will be between 1 and 10, inclusive. <br/>
- No two elements will have the same NAME.<br/>
- Names are case sensitive.<br/>
- currentUser consists of between 1 and 20, inclusive, uppercase letters, A-Z,<br/>
and must be a member.<br/>
- sf is an int between 1 and 10, inclusive.<br/>
- sf must be less than or equal to the number of answers (Xs) of the members.<br/>
<br/>
NOTES<br/>
The currentUser should not be included in the returned list of potential mates.<br/>
<br/>
<br/>
EXAMPLES<br/>
<br/>
For the following examples, assume members =<br/>
{"BETTY F M A A C C",<br/>
"TOM M F A D C A",<br/>
"SUE F M D D D D",<br/>
"ELLEN F M A A C A",<br/>
"JOE M F A A C A",<br/>
"ED M F A D D A",<br/>
"SALLY F M C D A B",<br/>
"MARGE F M A A C C"}<br/>
<br/>
If currentUser="BETTY" and sf=2, BETTY and TOM have two identical answers and<br/>
BETTY and JOE have three identical answers, so the method should return<br/>
{"JOE","TOM"}.<br/>
<br/>
If currentUser="JOE" and sf=1, the method should return<br/>
{"ELLEN","BETTY","MARGE"}.<br/>
If currentUser="MARGE" and sf=4, the method should return [].....this z ma code:
#include<iostream><br/>
#include<string><br/>
using namespace std;<br/>
class matchMaker<br/>
{<br/>
<span style="white-space:pre public:<br/>
<span style="white-space:pre string[] getBestMatches(string members[], string currentUser, int sf)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre <span style="white-space:pre int i=0,scount=0,x;<br/>
<span style="white-space:pre <span style="white-space:pre string rtn[10]={0};<br/>
for(i=0;i<20 && scount<2;i++) <br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre if(currentUser!= && scount<2)<br/>
<span style="white-space:pre continue ;<br/>
<span style="white-space:pre else<br/>
<span style="white-space:pre <span style="white-space:pre scount++;<span style="white-space:pre
<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre int j=0;<br/>
<span style="white-space:pre for(j=0;j<6;j++)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre int a,sc=0,tsf=0;<br/>
<span style="white-space:pre for(a=0;a<20 && sc<2;a++)<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre if(members[j][a]!= && sc<2)<br/>
<span style="white-space:pre continue ;<br/>
<span style="white-space:pre else<br/>
<span style="white-space:pre <span style="white-space:pre sc++ ;<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre if(currentUser!=members[j][a])<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre int p;<br/>
<span style="white-space:pre int temp=a;<br/>
<span style="white-space:pre for(p=0;p<((members[j].length)-temp);p++)<span style="white-space:pre
<br/>
<span style="white-space:pre {<br/>
<span style="white-space:pre a=a+2;<br/>
<span style="white-space:pre i=i+2;<span style="white-space:pre
<br/>
<span style="white-space:pre if(currentUser==members[j][a])<br/>
<span style="white-space:pre tsf++;<span style="white-space:pre
<br/>
<span style="white-space:pre }<span style="white-space:pre
<span style="white-space:pre <br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre if(tsf==sf)<br/>
<span style="white-space:pre rtn[x]=members[j];<br/>
<span style="white-space:pre x++;<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre return rtn;<span style="white-space:pre
<br/>
}<br/>
};<br/>
int main()<br/>
{<br/>
matchMaker maObj;<br/>
string str[7]={ "TOM M F A D C A",<br/>
"SUE F M D D D D",<br/>
"ELLEN F M A A C A",<br/>
"JOE M F A A C A",<br/>
"ED M F A D D A",<br/>
"SALLY F M C D A B",<br/>
"MARGE F M A A C C"};<br/>
string user="BETTY F M A A C C";<br/>
maObj.getBestMatches(str,user,2);<br/>
getch();<br/>
return 0; <span style="white-space:pre <br/>
<span style="white-space:pre }<br/>

plz help!!!

View the full article
 
Back
Top