I don't know how to do. PLEASE HELP!!

PROBLEM: Techi Gadgets Account Program. (20 pts)
Write the Techi Gadgets Account Program. The program will read a text file containing the following
account data:
AccountData.txt (placed in a 2D array format):

[0] [1] [2] [3] [4] [5] [6]
[0] bham@gnet.com Blake Ham squid62 1987 U Teacher
[1] jdark@att.net Jim Dark gymrat32 1985 A Master
[2] hgreen@lakes.net Hannah Green flower22 2007 U Apprentice
[3] tsmith@dna.com Tom Smith tuna20 2000 U Teacher
[4] jarrow@pnet.com James Arrow ahoy10 2005 U Apprentice
Column [0] will represent the user id, column [1] the user’s first name, column [2] the user’s last name,
column [3] the user’s password, column [4] the user’s initial membership year, column [5] the user’s
account access, U- General User and A – Administrator, and column [6] the user’s tech status,. An
Administrator will have the right to view all the user accounts; the output must be sorted in alphabetic
order by last name (see sample output) when viewed by the Administrator. General User’s will be able
to view their membership year and tech status.
When the Administrator view’s the user accounts, the data is automatically backed up to an output text
file named sortedBackup.txt.

HOW THE PROGRAM WORKS:
The program will first read in the file then ask the user to input their user name and password.
Depending on their account access, A or U, the program will display a welcome message with their
name, their initial membership year, their account access and their tech status if they are a General
User, if they are an Administrator, the program will display all the users in alphabetical order and also
backup the data file in alphabetical order to an output file called “sortedBackup.txt”. The program will
then loop back around and ask for the user name and password again, the program must reset the
username and password so that the last username and password used cannot be reused in the loop by
default. The user may type zero to exit. Please note that the user may type zero at any time to exit the
program.

Your program MUST use input validation.
Input Validation:
The program must check to see if the input file exists, if the input file does not exit it
must print an error message and exit the program correctly.


PSEUDO-CODE for main function (one of many ways you can do your program):
A. Declare Necessary Variables and 2D array to store data from input file.
B. Call the readFile function and capture the returned value.
C. Test if file was successfully read if so continue with program else exit with error message.
D. Do while….
a. Ask user to Enter User Name or Zero to Exit
b. Read in User Name
c. If User Name read in is “zero” Exit program.
d. Ask the user to Enter Their Password or Zero to Exit
e. Read in User Password
f. If User Password read in is “zero” Exit program
g. Call the Validate User function and capture the returned value
h. If returned value from the Validate User function is TRUE continue program to check
access code if U or A
i. If U – code appropriately
ii. If A – code appropriately
i. Else if returned value Not Valid from the Validate User function, FALSE, output message
username and password invalid

CONSTRAINTS:
• No global variables allowed. (Automatic -10)
Note: This means that all your arrays must be declared inside of main.
• You must use: int main()
• You must use input validation.
• The program must use local variables. (2 pts)
• You must use functions and they must be called by main. (2 pts)
• Output must be formatted properly and correct. (3 pts)
• Include a comment at the beginning of the program stating the purpose of the program, your
name, the date, and your class (1pt is for code organization and use of whitespace). (3 pts)
• The program must read in data from an input file. (2 pts)
• The program must output the results both to the console and to an output file. (1 pts)
• This program MUST use the following functions: (7 pts)

NAME YOUR FUNCTIONS AS SHOWN BELOW (- 10 if not named correctly):
void showAll (string theAccounts[5][7]) - (1 pts) is passed.the array which stores all the account
data and prints all the account data. This function returns nothing.
void sortInput (string theAccounts[5][7]) - (2 pts) is passed the array which stores all the
account data and sorts the account data by last name. This function returns nothing.
bool validateUser (string theAccounts[5][7], string username, string password, int &saveRow); -
(2 pts) is passed the array which stores all the account data, the user name, the user entered
password and the reference to an integer to save the row where the user account will be found
in the function. The function checks to see if the user name entered and the password matches,
then returns true or false. It also saves the row where it found the user information in saveRow.
bool readFile(string theAccounts[5][7]) - (2 pts) is passed the array which will store all the data
which will be read from the file. This function will open the input file and read in the data from
the input file. You Must Validate that the input file exists. If the file was not read in the function
should return false and error message should be output in main that the program will exit due
to an error in reading the file.

HINTS:
You will need the <fstream> library to read and write data from a file. This library also allows you to
declare your file stream object, i.e.
ifstream inputFile; //an ifstream object – input file stream object
inputFile.open(“Customers.txt”); // the open member function opens the text file and links it with
// inputFile to read data from the Customers.txt file
//To close a file
inputFile.close( );
Use the index in the back of your book to look up “Files”, opening and closing, and additional coding
examples. The ofstream object works the same way as the ifstream object.
In your function to sort use an algorithm that has already been written for you in your book. Just
change it to fit your needs for this program. You may use any sorting algorithm you wish but Bubble
Sort is the simplest and since this problem is so small, it would be applicable for our problem.
Remember to use setw( ) specifier to format your tables (you must include the <iomanip> library).
Example:
cout << setw( 8 ) << myNum << endl;


#include<iostream>
#include<string>
#include<fstream>

using namespace std;
//function prototyping
void showAll(string theAccounts[5][7]);
void sortInput(string theAccounts[5][7]);
bool validateUser(string theAccounts[5][7], string username, string password, int& saveRow);
bool readFile(string theAccounts[5][7]);

int main()
{
	string accountData[5][7] = {" "};
	bool userGood, fileGood;
	
	//Call the readFile functionand capture the returned value.
	fileGood = readFile(accountData);
	//C.Test if file was successfully read if so continue with program else exit with error message.
	//D.Do while….
		//a.Ask user to Enter User Name or Zero to Exit
		//b.Read in User Name
		//c.If User Name read in is “zero” Exit program.
		//d.Ask the user to Enter Their Password or Zero to Exit
		//e.Read in User Password
		//f.If User Password read in is “zero” Exit program
		//g.Call the Validate User function and capture the returned value
		//h.If returned value from the Validate User function is TRUE continue program to check access code if U or A
			//i.If U – code appropriately
			//ii.If A – code appropriately
		//i.Else if returned value Not Valid from the Validate User function, FALSE, output message usernameand password invalid
	
	return 0;
}
//function definitions
void showAll(string theAccounts[5][7])
{
}

void sortInput(string theAccounts[5][7])
{
}

bool validateUser(string theAccounts[5][7], string username, string password, int& saveRow)
{
	bool passed = false;
	//code the test to see if username and password match what is stored in theAcounts
	return passed;
}

bool readFile(string theAccounts[5][7])
{
	bool fileRead = false;
	ifstream inputFile; //an ifstream object – input file stream object
	inputFile.open("AccountData.txt"); // the open member function opens the text file and links it with
									   // inputFile to read data from the Customers.txt file
	//need to do input validation to test if file opened
	//if the file opened then read strings into theAccounts array - reset fileRead to true
	inputFile.close();
	return fileRead;
}
Last edited on
I don't know how to do


Don't know how to do what? What have you done so far? What effort have you made? What don't you understand?
Topic archived. No new replies allowed.