Reading a file and storing information into an array.

Okay so here is the literal assignment word for word down below. I have some of the code written but I am a feeling lost/stuck in where to go. I may have forgot some of the earlier lessons of C++ to remember fully all syntax to use, so I would really appreciate some hints, pointers, or just any kind of guide or help I can get right now. Here is the assignment.

"Write a program to read employee ID numbers from a file and count how many belong to each group.

The IDS are as follows:

100 – 299 Belong to group 01 - HR

300 – 499 Belong to group 02 – Purchasing

500 – 799 Belong to group 03 – IT

800 – 899 Belong to group 04 – Executive

Create one function to read the IDs from the file employee.dat and tally how many belong to reach group.

The function will need a temporary ID variable to read into and evaluate.

Create a separate function to display the total count per group:

For example:

10 Employees belong to group 01 – HR
15 Employees belong to group 02 – Purchasing
5 Employees belong to group 03 – IT
10 employees belong to group 04 – Executive

Only ONE ARRAY of size 4 is necessary to complete this project."



So that is the assignment. I have created a .dat file already with the list of information that is needed to be read. I have also created the .cpp file for the program. I know its not hardly much, but this is my code so far..


#include<iostream>
#include<iomanip>
#include<cmath>
#include<fstream>

using namespace std;



int main()
{
const int arraySize = 4;
int groups[arraySize] = {1, 2, 3 ,4 };

ifstream dataFile;
dataFile.open("employee_id.dat");

if (dataFile. is_open())
{
while (!dataFile.eof())
{

}


}
You begin just by printing the information in the file.
1
2
3
4
int id;
while ( dataFile >> id ) {
  cout << "Read ID=" << id << endl;
}

Make sure that's working.

Then you can start adding
1
2
if ( id >= 100 && id <= 299 ) {
}

Get the idea?
Topic archived. No new replies allowed.