|
-
Oct 5th, 2002, 04:13 PM
#1
Thread Starter
Addicted Member
Help with structures, another project
Project:
Consisting of creating a program that will read data from a file, place the data in an array of structures, sort the data, and write it to another file.
Specifics:
It should ask the user for the input file name and output file name. Input will consist of pairs of names and ssn #'s. The information should be read into an array of structures. Should be sorted in alphabetic order and sorted pairs should be written to output file.
Sample Input:
Johnson, Jay
123-45-6789
Kingston, Ken
543-43-2369
Sample Output:
Name: Bell, Bob
SSN: 354-23-5467
Name: Joe smoe
SSN: 344-55-3345
Requirements:
- Assume that there are no more then 100 name/number pairs in the input file
- Ensure that the input file exists and continuously re-prompt the user for an inpout file name until a valid one is entered
- Seperate functions should be used to read in the information, sort it, and write it out
PHP Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
struct record
{
char name[50]
char ssn[12];
};
int main(int argc, char* argv[])
{
char filename1[40],filename2[40];
while(true)
{
cout << "Please provide the input file name: ";
cin.getline(filename1,40);
ifstream temp;
temp.open(filename1);
if(temp)
{
temp.close();
break;
}
cout << "Invalid file name!" << endl;
}
cout << "Please provide the output file name: ";
cin.getline(filename2,40);
copy_file(filename1,filename2);
return 0;
}
[COLOR=limegreen]// Not Sure What Goes In These Functions Exactly[/COLOR]
void read_in(record items[], int & count, char src[]);
{
}
void write_out(record items[], int count, char dst[])
{
}
[COLOR=limegreen]// Not Sure Where This Sort Function Goes[/COLOR]
void sort (record items[], int count)
{
int min;
for (int =0; i<(count -1); i++)
min =i;
for(int j=1+1; j<count; j++)
if(strcmp(items[j].name, items[min].name) <0)
min=j;
record temp;
temp = items[i];
items[i] = items[min];
items[min] = temp;
}
return;
}
Thats all my code so far. Am I on the right track? Im not sure what to or what input to put in those blank functions.
Cornedbee, and ModMad I need ur help again! LOL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|