Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- using namespace std;
- const int ROWS = 5;
- const int COLS = 7;
- void showAll(string theAccounts[][COLS]);
- void sortInput(string theAccounts[][COLS]);
- bool validateUser(string theAccounts[][COLS], string username, string password, int &saveRow);
- bool readFile(string theAccounts[][COLS]);
- int main() {
- string accounts[ROWS][COLS];
- string username = " ";
- string password = " ";
- int saveRow = 0;
- if (readFile(accounts) == false)
- {
- cout << "File not found" << endl;
- exit(0);
- }
- if (readFile(accounts) == true)
- {
- cout << "File opened successfully" << endl;
- }
- validateUser(accounts, username, password, saveRow);
- showAll(accounts);
- sortInput(accounts);
- showAll(accounts);
- }
- void showAll(string theAccounts[][COLS])
- {
- ofstream stream;
- stream.open("sortedBackup.txt");
- for (int i = 0; i < ROWS; i++)
- {
- for (int j = 0; j < COLS; j++)
- {
- cout << setw(17) << theAccounts[i][j];
- stream << setw(17) << theAccounts[i][j];
- }
- cout << endl;
- stream << endl;
- }
- cout << endl;
- stream.close();
- }
- bool readFile(string theAccounts[][COLS])
- {
- ifstream stream;
- stream.open("AccountData.txt");
- if (stream.is_open() == false) return false;
- if (stream.is_open() == true) return true;
- for (int i = 0; i < ROWS; i++)
- {
- for (int j = 0; j < COLS; j++)
- {
- stream >> theAccounts[i][j];
- }
- }
- stream.close();
- }
- void sortInput(string theAccounts[][COLS])
- {
- bool swap;
- string temp;
- do
- {
- swap = false;
- for (int count = 0; count < (ROWS - 1); count++)
- {
- if (theAccounts[count][2] > theAccounts[count + 1][2])
- {
- for (int i = 0; i < COLS; i++)
- {
- temp = theAccounts[count][i];
- theAccounts[count][i] = theAccounts[count + 1][i];
- theAccounts[count + 1][i] = temp;
- }
- swap = true;
- }
- }
- } while (swap);
- }
- bool validateUser(string theAccounts[][COLS], string username, string password, int &saveRow)
- {
- cout << "Please enter the following information or 0 to exit" << endl;
- cout << "Please enter your username > ";
- cin >> username;
- cout << "Please enter your password > ";
- cin >> password;
- if (theAccounts[0][0] == username && theAccounts[0][3] == password) //username 1
- {
- cout << "Welcome back " << theAccounts[0][1] << "!";
- saveRow = 0; return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement