I am doing a homework assignment. I do not want the complete answer, just a hint. I have to load a file of names into an array, display the names, then sort the names alphabetically, display them again, then list how many names start with certain letters. I have everything done but cannot for the life of me figure out how to display how many names start with a certain letter. Here are the names Collins, Bill
Smith, Bart
Allen, Jim
Griffin, Jim
Stamey, Marty
Rose, Geri
Taylor, Terri
Johnson, Jill Allison, Jeff
Looney, Joe
Wolfe, Bill
James, Jean
Weaver, Jim
Pore, Bob
Rutherford, Greg
Javens, Renee
Harrison, Rose
Setzer, Cathy
Pike, Gordon Holland, Beth
And here is the code I have so far. Any hints would be awesome :-)
thanks!
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
string name [20];
void load_name()
{
int i=0;
fstream in_file;
in_file.open("names.txt");
do
{
getline(in_file,name[i]);
i++;
}
while (i<=20);
}
void no_sort()
{
int i=0;
cout << "Here are the unsorted names:\n";
cout << "--------------------------\n";
do
{
cout << name[i];
cout << "\n";
i++;
}
while (i<=20);
}
void sorter()
{
string temp[20];
for(int i = 1; i <= 20; i++)
{
for (int j=0; j < (20 -1); j++)
{
if (name[j+1] < name[j])
{
temp[j] = name[j];
name[j] = name[j+1];
name[j+1] = temp[j];
}
}
}
}
void sorted()
{
int i=0;
cout << "Here are the sorted names:\n";
cout << "--------------------------\n";
do
{
cout << name[i];
cout << "\n";
i++;
}
while (i<=20);
}
void howmany()
{
}
int main ()
{
load_name();
no_sort();
sorter();
sorted();
howmany();
}