Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. using namespace std;
  6.  
  7.  
  8. const int ROWS = 5;
  9. const int COLS = 7;
  10.  
  11. void showAll(string theAccounts[][COLS]);
  12. void sortInput(string theAccounts[][COLS]);
  13. bool validateUser(string theAccounts[][COLS], string username, string password, int &saveRow);
  14. bool readFile(string theAccounts[][COLS]);
  15.  
  16. int main() {
  17.  
  18. string accounts[ROWS][COLS];
  19. string username = " ";
  20. string password = " ";
  21. int saveRow = 0;
  22.  
  23. if (readFile(accounts) == false)
  24. {
  25. cout << "File not found" << endl;
  26. exit(0);
  27. }
  28. if (readFile(accounts) == true)
  29. {
  30. cout << "File opened successfully" << endl;
  31. }
  32.  
  33.  
  34. validateUser(accounts, username, password, saveRow);
  35. showAll(accounts);
  36. sortInput(accounts);
  37. showAll(accounts);
  38.  
  39. }
  40.  
  41. void showAll(string theAccounts[][COLS])
  42. {
  43. ofstream stream;
  44. stream.open("sortedBackup.txt");
  45.  
  46. for (int i = 0; i < ROWS; i++)
  47. {
  48. for (int j = 0; j < COLS; j++)
  49. {
  50. cout << setw(17) << theAccounts[i][j];
  51. stream << setw(17) << theAccounts[i][j];
  52. }
  53. cout << endl;
  54. stream << endl;
  55. }
  56. cout << endl;
  57.  
  58. stream.close();
  59. }
  60.  
  61. bool readFile(string theAccounts[][COLS])
  62. {
  63. ifstream stream;
  64. stream.open("AccountData.txt");
  65.  
  66. if (stream.is_open() == false) return false;
  67. if (stream.is_open() == true) return true;
  68.  
  69. for (int i = 0; i < ROWS; i++)
  70. {
  71. for (int j = 0; j < COLS; j++)
  72. {
  73. stream >> theAccounts[i][j];
  74. }
  75. }
  76.  
  77. stream.close();
  78.  
  79. }
  80. void sortInput(string theAccounts[][COLS])
  81. {
  82. bool swap;
  83. string temp;
  84. do
  85. {
  86. swap = false;
  87. for (int count = 0; count < (ROWS - 1); count++)
  88. {
  89. if (theAccounts[count][2] > theAccounts[count + 1][2])
  90. {
  91. for (int i = 0; i < COLS; i++)
  92. {
  93. temp = theAccounts[count][i];
  94. theAccounts[count][i] = theAccounts[count + 1][i];
  95. theAccounts[count + 1][i] = temp;
  96. }
  97. swap = true;
  98. }
  99. }
  100. } while (swap);
  101. }
  102. bool validateUser(string theAccounts[][COLS], string username, string password, int &saveRow)
  103. {
  104.  
  105.  
  106. cout << "Please enter the following information or 0 to exit" << endl;
  107. cout << "Please enter your username > ";
  108. cin >> username;
  109. cout << "Please enter your password > ";
  110. cin >> password;
  111.  
  112.  
  113. if (theAccounts[0][0] == username && theAccounts[0][3] == password) //username 1
  114.  
  115. {
  116. cout << "Welcome back " << theAccounts[0][1] << "!";
  117. saveRow = 0; return true;
  118. }
  119.  
  120.  
  121.  
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement