Hi guys/gals,
Boy what an experience it has been searching and reading through these forums. I have learned so much!
I was given the task of pulling information from a database and entering it into a program that would sort the names.
I was able to get that step down using the bubble sort - my problem now is that I need to use arrays and modular programming to get this code to work properly.
I've linked a little bit below a posting of what I think will work and want to run it by you guys before I mess the code up ;)
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void getName(string[], int&);
void ascending(string[], int);
void output(string[], int);
int main()
{
string name[100];
int item;
// char choice;
// choice = getChoice();
// if (choice == 'a')
// ascending(name, item)
// if (choice == 'd')
// decending(name, item);
getName(name, item);
ascending(name, item);
output(name, item);
}
void getName(string name[], int& item)
{
ifstream fin;
string temp;
fin.open("d:\\p9.txt");
item = 0;
while (!fin.eof())
{
fin >> name[item];
item++;
}
}
void ascending(string name[], int item)
{
int i, j;
string temp;
for(j=0; j<item-1; j++)
for(i=0; i<item-1; i++)
if(name[i] > name[i+1])
{
temp = name[i];
name[i] = name[i+1];
name[i+1] = temp;
}
}
void output(string name[], int item)
{
int i;
for(i=0; i<item; i++)
cout << name[i] << endl;
cout << endl << endl;
}