The text file babynames.txt, contains a list of the 1000 most popular boy and gi
ID: 3626848 • Letter: T
Question
The text file babynames.txt, contains a list of the 1000 most popular boy and girl names for the year 2004. This is a space delimited file of 1000 entries in which the rank is listed first, followed by the corresponding boy name and girl name. The most popular names are listed first and the least popular names are listed last. For example, the file begins with1 Jacob Emily
2 Michael Emma
3 Joshua Madison
This indicates that Jacob is the most popular boy name and Emily is the most popular girl name. Michael is the second most popular boy name and Emma is the second most popular girl name.
Write a program that allows the user to input a name. The program should then search for a matching name among the girls and boys. If a match is found, it should output the rank of the name. The program should also indicate if there is no match.
For example, if the user enters the name “Justice”, then the program should output:
Justice is ranked 406 in popularity among boys.
Justice is ranked 497 in popularity among girls.
If the user enters the name “Walter”, then the program should output:
Walter is ranked 366 in popularity among boys.
Walter is not ranked among the top 1000 girl names.
Your program should allow the user to enter names indefinitely but it should also provide an option for the user to quit.
Note: Your main function must consist of only variable declarations and functions calls.
please fix my code:
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
string array[1000];
string name;
ifstream infile;
infile.open("babynames.txt");
while (!infile)
{
cout << "unable to open the file" << endl;
return 1;
}
cout<< "Enter the nameyou want to find" << endl;
cin >> name;
int flag = 0;
int i;
for(i=0; i<1000; i++)
{
if (array[i] == name) // if match is found
{
flag = 1; // turn flag on
break ; // break out of for loop
}
}
if (flag)
{
cout << i <<". ";
}
else
{
cout<< "Sorry, I could not find your number in this array."<<endl<<endl;
}
return 0;
}
Explanation / Answer
hi there here is the program u want PLEASE RATE #include #include #include #include using namespace std; int main() { string arr[1000]; string name; ifstream infile; infile.open("test.txt"); while (!infile) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.