Name Sorting and Searching COSC 1437 – Lab #08 The attached file, CommonFemaleNa
ID: 3770410 • Letter: N
Question
Name Sorting and Searching
COSC 1437 – Lab #08
The attached file, CommonFemaleNames.txt, contains the top 1000 female names in the United States. The format is integer string where the integer is the popularity number (1 is most popular) and string is a female first name. The program is to read the list of names and create an array of objects. It then sorts the array in alphabetical order. The user enters a name, which the program searches for and then reports how common that name is. The program is to use two different search algorithms, a linear search and a binary search. It reports on how many nanoseconds it takes to find the name using each method.
Requirements
Each name and popularity number must be stored in a separate object.
The names on the list are all uppercase, but the program must find the name even if it is entered in
lower case. Do this by converting the entered name to all caps.
It must give an appropriate message if the name entered is not on the list.
Both a linear and a binary search are required, for each name entered and the time it takes for each
one reported.
Either the sort or the binary search must use a recursive method (Hint: a recursive binary search is
easier than a recursive sort).
Suggestions
Chapters 8 and 19 have example C++ code for sorting and searching arrays.
Here is an example of getting the current time in microseconds.
auto start_time = chromo::high_resolution_clock::now();
ord = namelist.findBinary(name);
auto end_time = chrono::high_resolution_clock::now();
cout << "Binary search took " <<
chrono::duration_cast<chrono::microseconds>(end_time -
start_time).count() << " microseconds" << endl;
One way to organize this is in the UML below.
Extra Credit
· Use quicksort to sort the name objects (5 points)
· Throw an exception when a name is not found. Handle it in the calling procedure (5 points)
Upload
Your source files (.h and .cpp) for this program as usual.
This is all I can get so far it keeps erroring on the file read, please help as soon as possible
#include <iostream>
#include<string>
#include<fstream>
#include <sstream>
using namespace std;
int main()
{
string arr[1000];
string name;
ifstream infile;
infile.open("CommonFemaleNames.txt");
while (!infile)
{
cout << "unable to open the file" << endl;
return 1;
}
cout<< "Enter the name you want to find" << endl;
cin >> name;
return 0;
}
Explanation / Answer
unable to open the file
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.