Ok I am working on a project that says to write a program that inputs (at most 50) records from a sequential file. The file may contain fewer than 50 records. Then insert the records into an array of records (ordered by department code in alphabetical order). Last, print the records in alphabetical order by department code and compute the age for each employee.
This is my data file (sampledata.txt)
Its last name, first name, date of birth, salary, dept #, phone #
Smith Tom 03141989 59150.00 B 253-760-5811
Hall Debra 05061980 61500.00 C 253-850-6880
Gaines Sarah 11241958 65500.00 d 397-196-1420
Ritz Robert 03301970 80250.00 a 385-300-4068
Martin Kevin 07151990 75000.00 A 397-123-2410
Holloway Jason 12181985 72750.00 a 385-697-9713
Hoan Kimberly 05161991 53125.00 b 253-156-5195
Bryan Victor 01231989 41150.00 D 407-701-7022
Roberts Ben 01121989 55000.00 c 253-519-1818
Little Mary 01181991 40685.00 d 860-714-2039
Samson Rachel 02021981 70515.00 A 305-312-0600
Peach Mel 10301965 60016.00 c 397-142-4061
Carrs Brett 04261969 56250.00 B 253-804-2000
Walsh Edward 09211993 49080.00 d 204-241-3033
Austin Jacob 08131992 48130.00 D 385-402-5741
This is my code so far...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
//structure declaration
struct employee_struct
{
char last_name[15];
char first_name[15];
char date_of_birth[8]; //mmddyyyy
float annual_salary;
int age;
char dept_code;
char phone_number[12];
};
int main()
{
employee_struct employee;
const int size=15; //I have 15 records in my data file
double array[size];
int i = 0;
//open file
fstream inFile;
inFile.open("sampledata.txt");
//read data into array of records
for (i = 0; i < 50; i++)
{
input >> employee[i].last_name >> employee[i].first_name >> employee[i].date_of_birth >> employee[i].annual_salary >> employee[i].age >> employee[i].dept_code >> employee[i].phone_number;
}
//close file
inFile.close();
//sort array of records by dept_code
return 0;
}
|
PLEASE HELP!!! I'm just learning data structures and methods of sorting and searching. Could someone please give my code a look to see if I'm even starting correctly. I attempted the sorting but it wasn't going so well and I keep getting errors at line 41.