473,480 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Converting unsorted info from a file then alphabetically to a new file

14 New Member
I need to open a file that has unsorted list of names and birthdates formated like this: LASTNAME, FIRST$MM/DD/YYYY\n.It could have as much as 100 names. I will use a selection sort algorithm to alphabetize the list and store it in a new file named by the user. So how do I read the data from the file? Then take that information using a selection sort algorithm to alphabetize the list and store it in a new file? I know it's a 2D array
const int MAXNAMES=100;
const intLISTLENGTH=42;
NAMES[MAXNAMES][LISTLENGTH]

SOME psuedocode:
open file to be read
test to see if it opened
read data from file
sort data by alphabet
close file
open input file
input sorted data

ANY HINTS WOULD BE MUCH APPRECIATED!! Thanks
Apr 22 '07 #1
3 1607
Ganon11
3,652 Recognized Expert Specialist
All of this sounds good...have you come across any trouble yet?

When you are inputting data, you will have to separate each piece of information from the others. I would suggest making a Person class or struct that you can overload the < operator for - this will help immensely when doing your selection sort. Also, do you have to use selection sort? There are much quicker sorting algorithms out there - one such algorithm is the Quicksort.
Apr 22 '07 #2
gemacjr1201
14 New Member
[quote=Ganon11]All of this sounds good...have you come across any trouble yet?

When you are inputting data, you will have to separate each piece of information from the others. I would suggest making a Person class or struct that you can overload the < operator for - this will help immensely when doing your selection sort. Also, do you have to use selection sort? There are much quicker sorting algorithms out there - one such algorithm is the Quicksort.[/QUOTE


No I don'y have to use selection sort.
I am having trouble reading the data out of the unsorted file.
I know that I need to write a for loop and use:


ofstream outputfile
outputfile.open("namelist.txt")
if(outputfile.fail()==false)
for loop------
outputfile << name[MAXNAMES][LISTLGTH]; <Here is my problem I don't understand person class or struct
Apr 22 '07 #3
gemacjr1201
14 New Member
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int MAXNAMES=100;
const int LISTLENGTH=61;
const int pass=100;
void ShowArray (char Array[MAXNAMES][LISTLENGTH]);
void SortArray (char Array[MAXNAMES][LISTLENGTH], int pass);

int main()
{
ofstream outputData; // Create an input file stream object
char Array[MAXNAMES][LISTLENGTH];

outputData.open("outputest.txt"); // Open the file named outputtest.txt

if(outputData.fail() == false) // Test to see if file was successfully opened
{
ShowArray ( Array);
SortArray (Array, pass);
ShowArray ( Array);
outputData.close();
}
else // The file open was unsuccessful
{
cout << "\nError: unable to open file.\n";
}

return 0;
}

void ShowArray (char Array[MAXNAMES][LISTLENGTH])
{
for (int i=0; i<MAXNAMES; i++)
{
for (int j=0; j<LISTLENGTH; j++)
{
cout << Array[i][j];
}
cout << endl;
}
}
void SortArray (char Array[MAXNAMES][LISTLENGTH], int pass)
{
bool swap;
int temp[LISTLENGTH];

do
{
swap=false;
for (int i=0; i<MAXNAMES-1; i++)
{
if (Array[i][0]>Array[i+1][0])
{
for (int j=0; j<LISTLENGTH; j++)
{
temp[j]=Array[i][j];
Array[i][j]=Array[i+1][j];
Array[i+1][j]=temp[j];
swap=true;
}
}
}
} while(swap);
}
Hers is some of my test code
Apr 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5051
by: Rosy Moss | last post by:
I am in the process of cleaning up a database that our company uses to track jobs, time and expense, and customer information. We are running Windows 2000 Server with approximately 20 terminals...
9
1839
by: zjut | last post by:
I want to add a string to the file and the file is sort by letter! for examply: the follow file is a big file ////////////////////// abort black cabbage dog egg fly
5
2490
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
3
1847
by: Peter J Ross | last post by:
Greetings. I'm quite new to PHP and have very little knowledge of programming in general, so I may be missing something obvious, but I can't find a solution to the following difficulty in either...
7
8678
by: Brett Romero | last post by:
I have a dataset with one table, which has four columns. All are of type INT. I need to convert this dataset into a dataview so I can sort on the last three columns. I may sort one of the three...
2
2339
by: jkflens | last post by:
Hello, i convert one XML-document by using XSLT into another XML-document. First change all attributes to elements is no problem. Then i try to insert a new element into the new document by...
23
2613
by: Reggie | last post by:
Hi and TIA. I developed several A2K dbs which are now being run on my clients computer which have been upgraded to Access 03. I'm not sure exactly what they mean but of you know or could point me...
2
1656
by: lbscprogrammer | last post by:
Hi, I'm in trouble here... I need to get this program working to proceed with my application. The program is very complex, it works fine on a 10 year old system written in IBM C/2. I am showing...
1
1429
by: ndawson | last post by:
Hi all I use the XSD utility provided with visual studio 2008 to convert xsd files into a c# project file, we then call this DLL from an application written in Delphi to provide read/write...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6739
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.