473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Dating service program in c++ using text file, and linked lists

Hello, I'm VERY new to programming, and I'm working on my second c++ program right now. Its a dating service where you read data from an input .txt file and store into a linked list, so then you can search, and modify the data. The text file is in this format:

M Dr.Gregory House,237-8732 7 Vicodin,Guitar,Piano,Motorcycles,Television,Food,W hiteboards.endl; (all on a single line).

First, is the sex (M or F), then the person's name, phone number, number of interests, then a list of their interests (with commas between each one, and a period at the end.) and then if they have a match you put their name there and put endl; after.

The main problem I'm having is setting up the link list, I have no idea how to get it to read those as variables in the text, I know you have to use delimiters, but I can't quite figure out how to use them. You also have to keep two lists, one for males, and one for females in the output file. How do I do this? Is that a double linked list?

Any help would really be appreciated. Thank you!

Here is the code so far (I know it isn't much..)

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <limits>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. //Functions
  10. void echoPrint();
  11. void newClient();
  12. void unMatch();
  13. void printMatch();
  14. void printFree();
  15. void quitAsking();
  16. void processing();
  17.  
  18. //Initialize Variables
  19. string command = ""; // User command answer
  20. std::string clientSex;
  21. std::string clientName;
  22. std::string clientPhone;
  23. std::string clientNumInt;
  24. std::string clientInterests;
  25. std::string match;
  26.  
  27.  
  28. ifstream inputfile;
  29. char Clients[] = "Clients.mf.txt"; // Input file
  30. ofstream outputfile;
  31. char Dates[] = "Dates.out.txt"; // Output file
  32.  
  33.  
  34. int main(){
  35.  
  36. inputfile.open(Clients, ios::in);
  37. //If input file can't open, read out this
  38. if (!inputfile) {
  39.    cerr << "Can't open input file " << Clients << endl; 
  40.    exit(1);
  41. }
  42.  
  43. outputfile.open(Dates, ios::out);
  44.  // If output file can't open, read out this
  45. if (!outputfile){
  46.     cerr << "Can't open output file " << Dates << endl;
  47.     exit(1);
  48. }
  49.  
  50.     //Questions & command list
  51.     cout << "Hello, how may I help you today?" << endl;
  52.     cout << endl;
  53.     cout << "Here are a list of commands I can do:" << endl;
  54.     cout << endl;
  55.     cout << "NEWCLIENT- Add a new client to my database" << endl;
  56.     cout << "UNMATCH- Remove client's current match" << endl;
  57.     cout << "PRINTMATCH- Print a list of all matched clients" << endl;
  58.     cout << "PRINTFREE- Prints the names and numbers of all clients without matches" << endl;
  59.     cout << "QUIT- This will exit the program." << endl;
  60.     cout << endl;
  61.     cout << "Please choose a command from above." << endl;
  62.  
  63.     //Sends program to processing function
  64.     processing(); 
  65.  
  66. do{
  67.     cout << "What would you like to do now? Please enter another command." << endl;
  68.     // Sends program to processing function
  69.     processing();
  70. }while(command == "QUIT" || command == "quit");
  71.  
  72. }// Closes main
  73.  
  74.  
  75. void processing(){
  76. do{
  77.        cin >> command;
  78.  
  79.         if (command == "NEWCLIENT" || command == "newclient"){
  80.                 newClient();
  81.        }else if
  82.        (command == "UNMATCH" || command == "unmatch"){
  83.                 unMatch();
  84.        }else if
  85.        (command == "PRINTMATCH" || command == "printmatch"){
  86.                 printMatch();
  87.         }else if
  88.         (command == "PRINTFREE" || command == "printfree"){
  89.                 printFree();
  90.         }else if
  91.         (command == "QUIT" || command == "quit"){
  92.                 quitAsking();
  93.         }else 
  94.         {
  95.             cout <<"****ERROR**** Please choose a command from above." << endl;
  96.             // Only allows error message to print once
  97.             cin.ignore( numeric_limits<int>::max() , '\n' );
  98.         }
  99. }while(!(command == "NEWCLIENT" || command == "newclient" || command == "UNMATCH" || command == "unmatch" ||
  100.          command == "PRINTMATCH" || command == "printmatch" || command == "PRINTFREE" || command == "printfree" ||
  101.          command == "QUIT" || command == "quit"));
  102.  
  103. // ECHO PRINTING HERE
  104.  
  105. }// Closes processing
  106.  
  107.  
  108. void newClient(){
  109.  
  110.     //Client's Sex
  111.     cout << "Please enter client's sex, F for female, M for male." << endl; // Ask for client's sex
  112.     cin >> clientSex;
  113.  
  114.     //Client's Name
  115.     cout << "Please enter client's name, no more than 20 characters." << endl; // Ask for client's name
  116.     cin >> clientName;
  117.  
  118.     //Client's Phone
  119.     cout << "Please enter client's phone number in XXX-XXXX format." << endl; // Ask for client's phone number
  120.     cin >> clientPhone;
  121.  
  122.     //Client's Number of Interests
  123.     cout << "Please enter number of client's interests (Can have up to 10)." << endl;// Ask for number of interests
  124.     cin >> clientNumInt;
  125.  
  126.     //Client Interests
  127.     cout << "Please enter client's interests. Place ',' between each (10 characters each) and a '.' after the last one." << endl;
  128.     cin >> clientInterests;
  129.  
  130. }// Closes NEWCLIENT
  131.  
  132.  
  133. void unMatch(){
  134. char unClientName;
  135.  
  136.  
  137.     cout << "Please enter the client's name you would like to unmatch." << endl;
  138.     cin >> unClientName;
  139.  
  140.  
  141.  
  142. }
  143.  
  144. void printMatch(){}
  145.  
  146. void printFree(){}
  147.  
  148. void quitAsking(){}
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
Jun 16 '13 #1
2 3244
Please, any help at all?
Jun 16 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
Since you are using the C++ Standard Library, there is a linked list set up for you already. That means you don't need to design your own linked list.

Read up on #include <list>.

Next, the linked list does not read data. It just stores data in the order received.

So, write a function to read a record from your text file and have the function return it as a std::string.

Then, check the beginning of the string for M or F. Hint: std::string is implemented as an array, so [0] is the first element. If that element is M add the string to the male linked list. Otherwise, add it the female linked list.

Do the above two steps in a loop until the file is processed.

To add to a linked list:
Expand|Select|Wrap|Line Numbers
  1. //create your linked lists:
  2. list<string> Mlist;    //male list
  3. list<string> Flist;    /female list;
  4. string str;
  5. //code here to put a value in str;
  6.  
  7. //then add the string to a linked list:
  8.  
  9. if str[0] == "M"
  10.      Mlist.push_back(str];     //adds string str to the end of the list
  11.  
  12.  
OK. Enough hints...
Jun 17 '13 #3

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

Similar topics

17
by: Foodbank | last post by:
Hi, I have to write a program that will use linked lists to print the number of unique words, total words, and the most frequent word from a text file. I've gotten a decent amount of it done...
0
by: Shawn Ferguson | last post by:
With the help of you, I've been able to successfully load my database with the contents of a "comma" delimited file. It loads about 5000 records in about 3 seconds:) Now I have another problem. ...
4
by: stuart.jones | last post by:
Dear all I have a Windows Service that retrieves some data as XML, applies an XSLT to produce a CSV which is saved to the filesystem as a text file. This all works fine. Depending upon the...
4
by: vunet.us | last post by:
I want to know if this practice is effective and secure: I have been thinking about storing some data, which my users upload, in text files rather than database, since often I do not know how much...
0
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all I have a text file which has many words. I want that when i enter A in text box all items starts from A filtered to a combo box. It can be a database instead of a txt file. thanx
0
by: Phill W. | last post by:
rbr wrote: If the Request and Response are Serializable (and I think they ought to be), create a SoapFormatter and Serialize each object to a disk file. OK, it won't be the nicest thing to...
0
by: =?Utf-8?B?VEQgaXMgUFNQ?= | last post by:
From <Project><Propertiesin the Resources I added a text file. Now I want to load the data in that file at runtime into a string array. I tried using the ResourceManager but it doesn't seem to...
1
by: bmsbms | last post by:
I want to write a c program which uses a text file containing 2 columns, Using fopen() I opened the file but how to seperate the both columns in seperate arrays?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.