Hey all. I'm new to the community and I have found it very useful in the past.

I have a problem that I cannot find a solution to:
Here is the question

As a system administrator, your task is to write a computer program for the CompanyINFR1100 to manage its user’s records. The program should allow its user to:
- Read all the records from the database text file, MasterUserFile.txt.
- Add a new user.
- Remove a user, given his/her user ID.
- Change the priority of a user, given his/her user ID.
- Change the password of a user, given his/her user ID.
- Print all the data for a specific user, given his/her user ID.
- Print all the data for all users in the company.
- Write records to the database text file

Hint: Your program should read the data file, fill an array of structures (one structure for each user), and perform all operations (except the reading and writing operations) on the array of structures.


So i've broken it down.
1st step would be to open the file.. and read all of the information into an array. The array contains alphanumeric entries (passwords, names etc.)
Question 1: How can I get an array to read this kind of data into corresponding entries?


Heres what I have so far.. i'm totally clueless.

#include <cstdlib> 
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;

//Global Variables
int intIndex=5;
int intIndexSize=5;


struct  UserFields
{
	//Structure Fields
	char firstName [10];
	char lastName [10];
	char password[10];
	int priority[1];
	int user_id [10];
};

int main()
{
	// Declaration of the Array of Structs with size intIndex
	UserFields Users[intIndex];
	
	// Install the inStream  
	ifstream inStream;
 
	// CHECK TO SEE IF FILE WILL OPEN \\
	inStream.open("MasterUserFile.txt");
	
		if ( inStream.fail())
		{
			cout << "Cannot open MasterUserFile.txt for reading, aborting" << endl;
			exit(1);
		}
	


  }




	return 0;
}

If anyone else has suggestions as to where I should start and how I should go about doing this.. it would be more than appreciated. Group members are not helping :(

If anyone else has suggestions as to where I should start and how I should go about doing this.. it would be more than appreciated. Group members are not helping :(

What's your hurry! Don't expect immediate answers to your questions, sometimes it might take a few hours depending on when you post. Getting pushy as you have done in this thread usually backfires and no one will answer you -- ever.

>>1st step would be to open the file.. and read all of the information into an array
Wrong. The first step should be to write a menu that will allow the user to select a menu item. Only after you have that working you can go on to the next step. Which is to design a structure to hold all the information for one person. Then you will need an array, vector, or linked list to hold all the structures. Again, you will compile and correct all errors.

Now you are ready to implement each of the menu items one function at a time. Compile the function and test to make sure it works correctly before moving on to the next function.

(AD, I'm hoping he means classmates)
If your team members are not helping, I recommend a hardware approach - 3 foot 2x4 to their head or backside, whichever is softer.:twisted:

I would get the data reading done, then the menu. Without data, it's hard to test the rest. From there, implement one action at a time, test it well. The menu will also give you direction on what you need.

Also look at actions that will be common to multiple tasks, such as finding a given user. That should be one of your early projects.

I would get the data reading done, then the menu. Without data, it's hard to test the rest. From there, implement one action at a time, test it well. The menu will also give you direction on what you need.

But without the menu its impossible to call the function that reads the data. Well, not really, but if you do you will wind up rewriting part of the program. Besides, the menu is the simplest part of the whole program and should take no more than a few minutes to write.

AD, as I read the assignment, the data just needs to be read in automatically at program start - no user intervention. If successful, then run the menu and start doing admin tasks.

DC, back to your Question 1

How can I get an array to read this kind of data into corresponding entries?

Once you have the file opened, read in to a temporary string. If that's successful (meaning there is some record data available) in your loop copy the temp data to the first field of your record then read and store the rest of the record. Read into the temp string again to see if there's another record.....
Be sure to test that you still have room in the array to store a next record before going on.

Do you know how to access a field of the record, when the record is an element of the array?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.