For this assignment your program will read in data from a file and store it in a
ID: 3687169 • Letter: F
Question
For this assignment your program will read in data from a file and store it in an array or arrays for lookup. The data file contains the top 200 boy and girl baby names for 2014. The data file is tab delimited which makes it feasible to use fscanf() for input rather than having to parse the input yourself. You should design the program to handle files with any number of baby names. DO NOT hard code the number 200. You need to count the number of lines in the file. The program will present a menu to the user with the options: 1. Search Boy Names 2. Search Girl Names 3. Display the Boy Names 4. Display the Girl Names 5. Quit The program will continue until option 5 is selected. The user will be asked to enter a name and then search the appropriate name type (boy or girl names) for a match. If the name is found the program will display on the screen: is in the top names for 2014 with the rank of . For example: Mary is in the top 200 girl names for 2014 with the rank of 152. If no match is found the program will display to the screen: is not in the top names for 2014. The output for displaying the boy names will look like: Top Boy Names for 2014 Rank Name 1 Boy Name 2 Boy Name 3 Boy Name until you reach the end. For this assignment your program will read in data from a file and store it in an array or arrays for lookup. The data file contains the top 200 boy and girl baby names for 2014. The data file is tab delimited which makes it feasible to use fscanf() for input rather than having to parse the input yourself. You should design the program to handle files with any number of baby names. DO NOT hard code the number 200. You need to count the number of lines in the file. The program will present a menu to the user with the options: 1. Search Boy Names 2. Search Girl Names 3. Display the Boy Names 4. Display the Girl Names 5. Quit The program will continue until option 5 is selected. The user will be asked to enter a name and then search the appropriate name type (boy or girl names) for a match. If the name is found the program will display on the screen: is in the top names for 2014 with the rank of . For example: Mary is in the top 200 girl names for 2014 with the rank of 152. If no match is found the program will display to the screen: is not in the top names for 2014. The output for displaying the boy names will look like: Top Boy Names for 2014 Rank Name 1 Boy Name 2 Boy Name 3 Boy Name until you reach the end. For this assignment your program will read in data from a file and store it in an array or arrays for lookup. The data file contains the top 200 boy and girl baby names for 2014. The data file is tab delimited which makes it feasible to use fscanf() for input rather than having to parse the input yourself. You should design the program to handle files with any number of baby names. DO NOT hard code the number 200. You need to count the number of lines in the file. The program will present a menu to the user with the options: 1. Search Boy Names 2. Search Girl Names 3. Display the Boy Names 4. Display the Girl Names 5. Quit The program will continue until option 5 is selected. The user will be asked to enter a name and then search the appropriate name type (boy or girl names) for a match. If the name is found the program will display on the screen: is in the top names for 2014 with the rank of . For example: Mary is in the top 200 girl names for 2014 with the rank of 152. If no match is found the program will display to the screen: is not in the top names for 2014. The output for displaying the boy names will look like: Top Boy Names for 2014 Rank Name 1 Boy Name 2 Boy Name 3 Boy Name until you reach the end.Explanation / Answer
Hi below i have written the sample code for your reference,
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
//ifstream in_put;
std::string enter_name;
char data;
int index = 0, count = 0;
bool isFoundB = false;
bool isFoundG = false;
string boynames[1000][2];
string girlnames[1000][2];
count = 0;
ifstream fileb("boynames.txt");
while (count < 1000 && fileb.is_open()){
fileb >> boynames[count][0];
fileb >> boynames[count][1];
count++;
}
count = 0;
ifstream fileg("girlnames.txt");
while (count < 1000 && fileg.is_open()){
fileg >> girlnames[count][0];
fileg >> girlnames[count][1];
count++;
}
cout << "Enter the first name that you would like to find the popularity of. "
<< "Be sure to capitalize the first letter of the name. ";
cin >> enter_name;
count = 0;
while(count < 1000){
if (boynames[count][0] == enter_name){
cout << boynames[count][0] << " is ranked " << count << " among boys with " << boynames[count][1] << " namings" << endl;
isFoundB = true;
}
if (girlnames[count][0] == enter_name){
cout << girlnames[count][0] << " is ranked " << count << " among girls with " << girlnames[count][1] << " namings" << endl;
isFoundG = true;
}
count++;
}
if(isFoundB == false){
cout << enter_name << " is not ranked among the top 1000 boy names." << endl;
}
if(isFoundG == false){
cout << enter_name << " is not ranked among the top 1000 girl names." << endl;
}
system("Pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.