Your assignment is to write a program for a computer dating service. Each client
ID: 3532072 • Letter: Y
Question
Your assignment is to write a program for a computer dating service. Each client gives you his or her name, phone number, and a list of interests. It is your job to maintain lists of men and women using the service and to match up the compatible couples. You will find more details about the assignment, including the inputs, outputs, and deliverables in the course environment.
Data about current clients should be on file "Clients.mf". For each current client, the file contains the following information:
Sex 1 character, 'M' or 'F'
Name up to 20 characters, followed by comma
Phone Number 8 characters
Number of Interests an integer
List of Interests 10 characters each separated by commas with a period after the final interest.
Match up to 20 characters, followed by end-of-line.
From the keyboard: The user may enter on of the following commands.
Command
Processing
NEWCLIENT <sex> <name> <phone number><number of interests> <interests>
Add the client to the appropriate list by storing the appropriate information. Attempt to match this new client with a member of the opposite sex. A match occurs when the clients have three or more of the same interests. (You only have to find the first match for each new client.) Make sure you then designate both persons as matched, as described in the section on data structures above. Print the name of the new client, the name of his or her match, and both phone numbers. If no match is found, print an appropriate message.
UNMATCH <name>
Unmatch this name with his or her current match by removing <name> from the matched person.
PRINTMATCH
Print a list of all matched pairs.
PRINTFREE
Print the names and phone numbers of clients who are not currently matched.
QUIT
Stop processing
Echo print all screen input and output on file "Dates.out."
The problem requires you to maintain two lists of clients, one for men and one for women. When a new client is added to the list, he or she is added to the end of the appropriate list.
Each list element must include all the information for one client: name, phone number, number of interests (maximum number is 10), interests, and the name of this client's current match (empty string if not matched). You must use one of the list classes developed in Chapter 3.
Command
Processing
NEWCLIENT <sex> <name> <phone number><number of interests> <interests>
Add the client to the appropriate list by storing the appropriate information. Attempt to match this new client with a member of the opposite sex. A match occurs when the clients have three or more of the same interests. (You only have to find the first match for each new client.) Make sure you then designate both persons as matched, as described in the section on data structures above. Print the name of the new client, the name of his or her match, and both phone numbers. If no match is found, print an appropriate message.
UNMATCH <name>
Unmatch this name with his or her current match by removing <name> from the matched person.
PRINTMATCH
Print a list of all matched pairs.
PRINTFREE
Print the names and phone numbers of clients who are not currently matched.
QUIT
Stop processing
Explanation / Answer
this is dating.cpp
/*Input: The program will read the input from stard input. The program will crea!
the other of females, then match the individuals according to their interests.
Output: All written output goes to standard output. The program prompts a lis!
the corresponding commands output.
Preconditions: The list must have all of the required fields. All input must !
Postconditions:
*/
#include <iostream>
using namespace std;
#include <fstream>
#include <string>
#include "ListA.cpp"
const int MALE = 0 ;
const int FEMALE = 1 ;
int genderID = 0;
ifstream clientLists ("clients.txt") ;
int matchLoc = 0 ;
/*
Function name: NEWCLIENT
Input: the new clients information
Preconditions: Trys to find a female match when entered
Postconditions: Must print out new client and match or no match
Callers:doCommands
Callees:
*/
void getNextClient( ListItemType clientLists , ifstream & comndFile)
{
}
/*
Function name: UNMATCH
Input: The last and first name of client
Output: The two matches "current match" fields are set to zero
Preconditions: Must have <last name> <first name>
Postconitions: Changes both matches
Callers: doCommands
Callees:
*/
clientRecType item ;
void getMainData ( clientRecType & item , char & gender , ifstream inFile)
{
inFile >> gender ;
cout << gender ;
inFile >> item.lastName ;
cout << item.lastName ;
inFile >> item.firstName ;
cout << item.firstName ;
inFile >> item.phoneNum ;
cout << item.phoneNum ;
inFile >> item.numIntrs ;
cout << item.numIntrs ;
int j = 0 ;
int numIntrs = item.numIntrs ;
for ( j=0;j<=numIntrs;j++) {
inFile >> item.interest[j] ;
cout << item.interest[j] ;
}
inFile >> item.matchLoc ;
cout << item.matchLoc ;
}
void putClientInList(clientRecType & item , char gender , ListItemType & clientLists) {
int which = 0 ;
int pos ;
char M ;
char F ;
if (gender == M) which = MALE ;
else which = FEMALE ;
clientLists[which] insert(pos,item, success) ;
pos = clientLists[which].getLength() + 1 ;
clientRecType client ;
clientRecType candidate ;
}
void isMatch (clientRecType client, clientRecType candidate){
bool result ;
if (candidate.matchLoc != 0) result=false ;
else{
int numMatchs = 0 ;
int j ;
for (j = 0;j<=numIntrs - 1;j++){
if (client.interest= candidate.interest)numMatchs++ ;
}
if (numMatchs>=3) result=true;
}
}
void makeMatch( ListItemType clientLists, int genderID, int matchLoc, int oppLoc){
int client ;
int oppClient ;
int oppID =( 1 - genderID) ;
}
void doMatch( ListItemType clientLists , int genderID , int pos , int numOpp) {
int oppSex = (1 - genderID) ;
numOpp = clientLists[oppSex].getLength() ;
int posFound = 0 ;
for ( pos=1; pos<=clientLists[oppSex].getLength();pos++){
}
if (posFound !=0) makeMatch();
else if(posFound=0) cout << "no match" ;
}
void unMatch()
{
cout <<"last and first name are entered, if paired their match number ";
}
/*
Function name: PRINTMATCH
Input: list of paired clients
Output: prints out paired clients
Preconditions: prints only paired clients
Postconditions: non
Callers: doCommands
Callees:
*/
void printMatch()
{
cout <<"reads lists and finds clients with client match > 0 and prints";
}
/*
Function name: PRINTFREE
Input: list of clients
Output: prints list of clients who aren't matched
Preconditions: prints full name and phone numbers
Postconditions: non
Callers: doCommands
Callee:
*/
void printFree(ListItemType clientList)
{
int pos ;
int oppSex = genderID - 1;
for ( pos=1; pos<=clientLists[oppSex].getLength();pos++){
cout << clientList[oppSex];
}
}
/*
Function name: QUIT
Input: quit
output: prints out quit and then "Have a good day."
Preconditions: none
Postconditions: none
Callers: doCommands
Callees: none
*/
void quit()
{
cout <<"received QUIT command, exiting. Have a good day. then ends program" ;
}
/* function name: DOCOMMANDS
Input: select command from menu
Output: prints out the command selected and the output of that command
Preconditions: must select specific command or else it reasks
Postconditions: none
Callers: main
Callees: commands
*/
void doCommands()
{
if (inFile = "PUTCLIENTINLIST") putClientInList();
else if(inFile = "UNMATCH") unMatch();
else if(inFile = "PRINTMATCH") printMatch();
else if(inFile = "PRINTFREE") printFree();
else if(inFile = "QUIT") quit();
}
void getNextClient( clientRecType & item , char & gender , ifstream inFile){
}
void dumpLists()
{
cout << "puts the lists into two lists male and female" << endl;
}
void buildLists()
{
}
int main(){
cout << "hi" << endl;
buildLists();
doCommands();
dumpLists();
quit();
printFree(ListItemType clientList);
printMatch();
unMatch();
}
this is LISTA.cpp
// *********************************************************
// Implementation file ListA.cpp for the ADT list
// Array-based implementation
// *********************************************************
#include "ListA.h" //header file
List::List() : size(0)
{
} // end default constructor
bool List::isEmpty() const
{
return size == 0;
} // end isEmpty
int List::getLength() const
{
return size;
} // end getLength
void List::insert(int index, ListItemType newItem,
bool& success)
{
success = (index >= 1) &&
(index <= size + 1) &&
(size < MAX_LIST);
if (success)
{ // make room for new item by shifting all items at
// positions >= index toward the end of the
// list (no shift if index == size+1)
for (int pos = size; pos >= index; --pos)
items[translate(pos+1)] = items[translate(pos)];
// insert new item
items[translate(index)] = newItem;
++size; // increase the size of the list by one
} // end if
} // end insert
void List::remove(int index, bool& success)
{
success = (index >= 1) && (index <= size) ;
if (success)
{ // delete item by shifting all items at positions >
// index toward the beginning of the list
// (no shift if index == size)
for (int fromPosition = index+1;
fromPosition <= size; ++fromPosition)
items[translate(fromPosition-1)] = items[translate(fromPosition)];
--size; // decrease the size of the list by one
} // end if
} // end remove
void List::retrieve(int index, ListItemType& dataItem,
bool& success) const
{
success = bool( (index >= 1) && (index <= size) );
if (success)
dataItem = items[translate(index)];
} // end retrieve
int List::translate(int index) const
{
return index-1;
} // end translate
// End of implementation file.
THIS IS LIST.h
// *********************************************************
// Header file ListA.h for the ADT list
// Array-based implementation
// *********************************************************
#include "clientRec.h"
const int MAX_LIST = 100 ;
typedef clientRecType ListItemType;
class List
{
public:
List(); // default constructor
// destructor is supplied by compiler
// list operations:
bool isEmpty() const;
// Determines whether a list is empty.
// Precondition: None.
// Postcondition: Returns true if the list is empty;
// otherwise returns false.
int getLength() const;
// Determines the length of a list.
// Precondition: None.
// Postcondition: Returns the number of items
// that are currently in the list.
void insert(int index, ListItemType newItem,
bool& success);
// Inserts an item into the list at position index.
// Precondition: index indicates the position at which
// the item should be inserted in the list.
// Postcondition: If insertion is successful, newItem is
// at position index in the list, and other items are
// renumbered accordingly, and success is true;
// otherwise success is false.
// Note: Insertion will not be successful if
// index < 1 or index > getLength()+1.
void remove(int index, bool& success);
// Deletes an item from the list at a given position.
// Precondition: index indicates where the deletion
// should occur.
// Postcondition: If 1 <= index <= getLength(),
// the item at position index in the list is
// deleted, other items are renumbered accordingly,
// and success is true; otherwise success is false.
void retrieve(int index, ListItemType& dataItem,
bool& success) const;
// Retrieves a list item by position.
// Precondition: index is the number of the item to
// be retrieved.
// Postcondition: If 1 <= index <= getLength(),
// dataItem is the value of the desired item and
// success is true; otherwise success is false.
private:
ListItemType items[MAX_LIST]; // array of list items
int size; // number of items in list
int translate(int index) const;
// Converts the position of an item in a list to the
// correct index within its array representation.
}; // end List class
// End of header file.
THIS IS CLIENTREC.h
#include <iostream>
#include <string>
using namespace std ;
#ifndef CLIENTREC_H
#define CLIENTREC_H
#define MAX_INTRS 10
struct clientRecType
{
string lastName ;
string firstName ;
string phoneNum ;
/* number of interests -- up to MAX_INTRS */
int numIntrs ;
/* storage for the interests */
string interest[MAX_INTRS] ;
/* location of this person's match
in the other list, or zero */
int matchLoc ;
} ;
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.