Write a program that prints a sorted phone list from a database of names and pho
ID: 3634868 • Letter: W
Question
Write a program that prints a sorted phone list from a database of names and phonenumbers. The data is contained in two files named "phoneNames.txt" and
"phoneNums.txt". The files may contain up to 2000 names and phone numbers. The
files have one name or one phone number per line. To save paper, only print the first 50
lines of the output. Note: The first phone number in the phone number file corresponds to
the first name in the name file. The second phone number in the phone number file
corresponds to the second name in the name file. etc
this is what i have so far
int main()
{
using namespace std;
char num[2000][16];
char name[2000][26];
char temp[26];
const int size= 30;
int maxentries;
ifstream namestream;
ifstream numstream;
namestream.open("F:\phoneNames.txt");
if (namestream.fail())
{
cout<< "Input file opening failed.";
exit(1);
}
numstream.open("F:\phoneNums.txt");
if (numstream.fail())
{
cout<< "Input file opening failed.";
exit(1);
}
int j=0;
while (!namestream.eof())
{
namestream.getline (name[j],26) ;
if (namestream.eof())
break;
j++;
}
int i = 0;
while (!numstream.eof())
{
numstream.getline(num[i],16);
if (numstream.eof())
break;
i++;
}
for (int i = 0; i < maxentries; i++)
{
namestream.getline (name[i],size);
}
for (int i = 0; i < maxentries - 1; i++)
{
if (strcmp( name[i], name[i + 1]) > 0)
{
strcpy_s(temp, name[i]);
strcpy_s(name[i], name[i + 1]);
strcpy_s(name[i + 1], temp);
cout << "Here are the words in order." << endl;
for (int i = 0; i < maxentries; i++)
{
cout << name[i] << endl;
namestream.close();
numstream.close();
return 0;
}