Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Neal Poole
- //Homework 6 - This program reads information from a file and then asks
- //the user for their username and password. Depending on their account priviledges
- //it will either shoe their personal info or show all the accounts
- //(General User or Admin)
- //COP2000
- //4-20-18
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <cstring>
- #include <vector>
- using namespace std;
- void showAll(string[5][7]);
- void sortInput(string[5][7]);
- bool readFile(string[5][7]);
- bool validateUser(string[5][7], string, string, int &);
- int main()
- {
- string username, password;
- int saveRow, position, userInput = 1;
- string accountData[5][7] = { " " };
- readFile(accountData);
- if (readFile(accountData))
- cout << "File Read Successfully..." << endl << endl;
- else
- {
- cout << "Invalid file, exiting.";
- return 0;
- }
- do
- {
- cout << endl << "Enter the following information or 0 to exit...";
- cout << endl << "Please Enter Your User Name > ";
- cin >> username;
- if (username == "zero")
- return 0;
- cout << "Please Enter Your User Password > ";
- cin >> password;
- if (password == "zero")
- return 0;
- validateUser(accountData, username, password, saveRow);
- if (validateUser(accountData, username, password, saveRow))
- {
- cout << endl << "Welcome Back" << accountData[saveRow][1];
- if (accountData[saveRow][5] == "A")
- {
- sortInput(accountData);
- showAll(accountData);
- ofstream outputFile;
- outputFile.open("sortedBackup.txt");
- for (int a = 0; a < 5; a++)
- {
- for (int b = 0; b < 7; b++)
- {
- outputFile << accountData[a][b];
- }
- cout << endl;
- }
- if (outputFile)
- {
- cout << endl << "Backup File Completed";
- continue;
- }
- else
- {
- cout << endl << "Error Saving File, exiting....";
- return 0;
- }
- }
- else
- {
- cout << endl << accountData[saveRow][1] << " " << accountData[saveRow][2] << " " << accountData[saveRow][4] << " " << accountData[saveRow][5] << " " << accountData[saveRow][6];
- continue;
- }
- }
- else
- {
- cout << endl << "Username and Password do not match... Please try Again";
- continue;
- }
- } while (userInput != 0);
- return 0;
- }
- void showAll(string theAccounts[5][7])
- {
- for (int x = 0; x < 5; x++)
- {
- for (int y = 0; y < 7; y++)
- {
- cout << setw(8) << theAccounts[x][y] << " ";
- }
- cout << endl;
- }
- }
- void sortInput(string theAccounts[5][7])
- {
- bool swap;
- string temp;
- do
- {
- swap = false;
- for (int x = 0; x < 4; x++)
- {
- if ((theAccounts[x][1]) > (theAccounts[x + 1][1]))
- {
- temp = theAccounts[x][1];
- theAccounts[x][1] = theAccounts[x + 1][1];
- theAccounts[x][0] = theAccounts[x + 1][0];
- theAccounts[x][2] = theAccounts[x + 1][2];
- theAccounts[x][3] = theAccounts[x + 1][3];
- theAccounts[x][4] = theAccounts[x + 1][4];
- theAccounts[x + 1][1] = temp;
- swap = true;
- }
- }
- } while (swap);
- }
- bool readFile(string theAccounts[5][7])
- {
- ifstream inputFile;
- inputFile.open("C:/Users/nealc/Desktop/AccountData.txt");
- if (inputFile)
- {
- for (int x = 0; x < 5; x++)
- {
- for (int y = 0; y < 7; y++)
- {
- inputFile >> theAccounts[x][y];
- }
- cout << endl;
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- bool validateUser(string theAccounts[5][7], string username, string password, int &saveRow)
- {
- int x, y;
- bool found = false;
- for (x = 0, y = 0; x < 5, y < 7; x++, y++)
- {
- for (y = 0; y < 7; y++)
- {
- if (theAccounts[x][y] == username)
- found = true;
- saveRow = x;
- break;
- }
- cout << endl;
- }
- cout << endl << x;
- switch (saveRow)
- {
- case 0:
- if (password == "squid62")
- {
- return true;
- }
- else
- return false;
- case 1:
- if (password == "gymrat32")
- {
- return true;
- }
- else
- return false;
- case 2:
- if (password == "flower22")
- {
- return true;
- }
- else
- return false;
- case 3:
- if (password == "tuna20")
- {
- return true;
- }
- else
- return false;
- case 4:
- if (password == "ahoy10")
- {
- return true;
- }
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement