create a program in C++ that reads in names from a txt file. Only the last names
ID: 3619665 • Letter: C
Question
create a program in C++ that reads in names from a txt file. Only the last names are in the txt file, one name per line.example:
Smith
Penn
Li
You are to read these names from which you construct an array of cstrings, sort the array in ascending order, display the sorted list of names, then prompt the user if he/she wants to search for a name. Give the user the option of searching again.
-need a 2 dimensional array of char
- assume there are no more than 100 names in the file
- assume no name will have more than 50 char
Explanation / Answer
#include #include #include using namespace std; int main () { string line;int count=0;int i,j; char file[1000]; coutfile; char str[100][50];char temp[50]; ifstream myfile (file); if (myfile.is_open()) { while (! myfile.eof() ) { myfile.getline(str[count++],50); //coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.