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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
cout << "girls name returned from function before entering function " << girlsNames[0] << endl
// Name Search.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<fstream>
#include<vector>
#include<string>
using namespace std;
string getGirlName(string);
string getBoyName(string);
int girls(vector<string>);
int boys(vector<string>);
int girlCompare(vector<string>, string, int);
int boyCompare(vector<string>, string, int);
int main()
{
vector<string>girlsNames;
vector<string>boysNames;
string girlName, gName;
string boyName, bName;
int gnum, bnum;
gName = getGirlName(girlName);
cout << "Girls name from user input is :" << gName << endl;
system("pause");
bName = getBoyName(boyName);
cout << "Boyss name from user input is :" << bName << endl;
system("pause");
gnum = girls(girlsNames);
cout << "total girls names listed is " << gnum << endl;
system("pause");
bnum = boys(boysNames);
cout << "total name of boys listed is " << bnum << endl;
system("pause");
cout << "girls name returned from function before entering function " << girlsNames[0] << endl;
girlCompare(girlsNames, gName, gnum);
boyCompare(boysNames, bName, bnum);
system("pause");
return 0;
}
string getGirlName(string name)
{
string girlName;
cout << "Enter name of girl: ";
getline(cin, girlName);
return girlName;
}
string getBoyName(string name)
{
string boyName;
cout << "Enter name of boy: ";
getline(cin, boyName);
return boyName;
}
int girls(vector<string>girlsNames)
{
string girl;
ifstream girlsArray;
girlsArray.open("C:\\Users\\Visual Studio 2017\\Projects\\girlsNames.txt");
if (!girlsArray)
{
cout << "File did not open" << endl;
}
while (!girlsArray.eof())
{
girlsArray >> girl;
girlsNames.push_back(girl);
}
girlsArray.close();
int gnum = girlsNames.size();
for (int i = 0; i < (gnum - 1); i++)
{
//cout << girlsNames[i] << endl;
}
return gnum;
}
int boys(vector<string>boysNames)
{
cout << endl;
string boy;
ifstream boysArray;
boysArray.open("C:\\Users\\Visual Studio2017\\Projects\\boysNames.txt");
if (!boysArray)
{
cout << "File did not open" << endl;
}
while (!boysArray.eof())
{
boysArray >> boy;
boysNames.push_back(boy);
}
boysArray.close();
int num = boysNames.size();
for (int i = 0; i < (num - 1); i++)
{
//cout << boysNames[i] << endl;
}
return num;
}
int girlCompare(vector<string>girlsNames, string gName, int gnum)
{
cout << "gnum passed to function: " << gnum << endl;
system("pause");
cout << "girl name input by user passed to function: " << gName << endl;
system("pause");
for (int i = 0; i < gnum-1 ; ++i)
{
system("pause");
if (gName == girlsNames[i])
{
system("pause");
cout << girlsNames[i] << " is available in list" << endl;
}
else
{
cout << girlsNames[i] << " is not availalbe in list" << endl;
}
}
return gnum;
}
int boyCompare(vector<string>boysNames, string bName, int bnum)
{
for (int i = 0; i < bnum-1 ; ++i)
{
if (bName == boysNames[i])
{
cout << boysNames[i] << " is available in list" << endl;
}
else
{
cout << boysNames[i] << " is not availalbe in list" << endl;
}
}
return bnum;
}
|