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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <iomanip>
// debug //
#include <iterator>
#include <algorithm>
//#include <sstream>
const int RANK = 1000;
int z;
using namespace std;
int main()
{
ifstream name;
name.open("E:\\homework\\babynames2012.txt");
string userName, boyName, girlName;
int rankArray[RANK];
int rankBoy = 0, rankGirl = 0, rankNum = 0, x;
string sucker;
string input = ""; // user input to begin search for baby name.//
string bArray[RANK], gArray[RANK]; // array for boys' & girls' names.//
bool fboy; // search for boys name.//
bool fgirl; // search for girls name.//
// debug check file //
/*
if (name.is_open())
{
cout << "file is open. \n";
istream_iterator< char > begin( name ) , end;
ostream_iterator< char > output( cout );
copy( begin , end , output );
}
else
cout << "file is NOT OPEN, please Exit Program.\n" ;
exit(1);
*/
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << '*' << setw(7) << "Welcome to Gotdayums Baby Name Registry!" << '*'
<< endl << endl << "Here you can search our database for the 1000 most popular baby names.\n"
<< "The most popular name is ranked #1, \n" << "whereas the least popular name in our list "
<< "is ranked #1000.\n\n" ;
cout << "Please enter you credit card number at the prompt:\n>" ;
getline(cin, sucker);
if (sucker.length() > 1)
cout << "Thanks sucker.\n" ;
else
cout << "Well played...\n";
do{
cout << "Please enter a first name for either a girl or boy: \n>";
getline(cin, input);
//lets check if the name was correctly entered.
if (input.empty())
{
cout << "What are you doing fool?.\n" ;
}
else
cout << "You entered: " << input << endl << endl;
}while (input.empty());
cout << "Please wait while we search our database..\n" ;
/// LOOK HERE /// AT THE WHILE LOOP /// HELP!!
while(name >> rankNum >> boyName >> girlName)
{
for (x=0; x < 1; x++)
rankArray[x] = rankNum;
bArray[x] = boyName;
gArray[x] = girlName;
}
for(z=0; z<RANK; z++)
{
if(input==bArray[z])
{
cout << input << " is ranked " << z << " in popularity among boys." << endl;
fboy=true;
}
if(input==gArray[z]){
cout << input << " is ranked " << z << " in popularity among girls." << endl;
fgirl=true;
}
}
if(fboy!=true) cout << input << " is not ranked among the top 1000 boy names." << endl;
if(fgirl!=true) cout << input << " is not ranked among the top 1000 girl names." << endl;
cin.get();
//return 0;
}
|