1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
//******************************************************************************
//MAIN PROGRAM
//******************************************************************************
/* Program: Name Lists
* Description: To create an unsorted list of strings, parse the strings, and
* use classes to inplement a list of names.
*/
# include <iostream>
# include <fstream>
# include <string>
# include <cctype>
using namespace std;
#include "list.cpp"
void getList (ifstream&, List&);
// uses EOF loop to extract list of names from data file...
void putList (ofstream&, List);
// uses call-by-value because iterators modify the class...
string parseInputString (string);
// will be called from GetList...
string parse2 (string first, string last);
int main ()
{
ifstream data;
ofstream out;
List mylist;
data.open ("name_list.txt"); //file for input...
if (!data)
{
cout << "ERROR!!! FAILURE TO OPEN name_list.text" << endl;
system ("pause");
return 1;
}
out.open ("out.txt"); //file for output...
if (!out)
{
cout << "ERROR!!! FAILURE TO OPEN out.text" << endl;
system ("pause");
return 1;
}
getList (data, mylist);
putList (out, mylist);
data.close ();
out.close ();
system ("pause");
return 0;
} // main
void getList (ifstream& data, List& mylist)
{
string first, last, result;
string oneline;
//data >> first;
while (data)
{
//data >> last;
result = parse2(first,last);
mylist.Insert(result);
getline (data, oneline);
// data >> first;
}
}
void putList (ofstream& outfile, List mylist)
{
string oneline;
//use iterators
mylist.ResetList ();
outfile << "Names: " << endl << endl;
while (mylist.HasNext ())
{
oneline = mylist.GetNextItem ();
outfile << oneline << endl;
}
}
string parse2 (string first, string last)
{
string personName;
personName = last + ", " + first + ".";
return personName;
}
//www.cplusplus.com/doc/tutorial/classes/
|