Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. 'Record::getTitle': non-standard syntax; use '&' to create a pointer to member
  2. 'Record::getUsername': non-standard syntax; use '&' to create a pointer to member
  3. 'Record::getPassword': non-standard syntax; use '&' to create a pointer to member
  4.  
  5. writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);
  6.  
  7. #include <iostream>
  8. #include <string>
  9. #include <fstream>
  10. #include <map>
  11. #include <functional>
  12. using namespace std;
  13.  
  14. string GetInput();
  15. void MainMenu();
  16. void Title();
  17. void AddRecord();
  18. void writeToFile(string title, string username, string password);
  19.  
  20. class Record {
  21.  
  22. private:
  23.  
  24. string id;
  25. string title;
  26. string username;
  27. string password;
  28. static int numberOfRecords;
  29.  
  30. public:
  31.  
  32. void setTitle(string title) {
  33. this->title = title;
  34. }
  35. string getTitle() {
  36. return title;
  37. }
  38.  
  39. void setUsername(string username) {
  40. this->username = username;
  41. }
  42. string getUsername() {
  43. return username;
  44. }
  45.  
  46. void setPassword(string password) {
  47. this->password = password;
  48. }
  49. string getPassword() {
  50. return password;
  51. }
  52.  
  53. static int GetNumberOfRecords() {
  54. return numberOfRecords;
  55. }
  56. };
  57.  
  58. struct MenuAction {
  59.  
  60. string description;
  61. function<void()> action;
  62. };
  63.  
  64. static const map <string, MenuAction> actionTable{
  65.  
  66. { "1",{ "Add entry", []() { AddRecord(); } } },
  67. { "2",{ "Edit entry", []() { cout << "Edit entry" << "n"; } } },
  68. { "q",{ "Quit", []() { cout << "Quit" << "n"; } } }
  69. };
  70.  
  71. int main() {
  72.  
  73. Title();
  74. MainMenu();
  75.  
  76. return 0;
  77. }
  78.  
  79. void Title() {
  80.  
  81. cout << "======================================n"
  82. "| Database |n"
  83. "======================================nn";
  84. }
  85.  
  86. void MainMenu() {
  87.  
  88. for (auto const& x : actionTable) {
  89. cout << x.first << ". " << (x.second).description << "n";
  90. }
  91.  
  92. string input;
  93.  
  94. while (actionTable.count(input) == 0) {
  95. input = GetInput();
  96. }
  97.  
  98. actionTable.at(input).action();
  99. }
  100.  
  101. void AddRecord() {
  102.  
  103. cout << "============= Add Record ============" << endl << endl;
  104.  
  105. string id;
  106. string title;
  107. string username;
  108. string password;
  109.  
  110. cout << "Title: ";
  111. getline(cin, title);
  112. cout << "Username: ";
  113. getline(cin, username);
  114. cout << "Password: ";
  115. getline(cin, password);
  116.  
  117. Record firstRecord;
  118. firstRecord.setTitle(title);
  119. firstRecord.setUsername(username);
  120. firstRecord.setPassword(password);
  121.  
  122. writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);
  123. }
  124.  
  125. string GetInput() {
  126.  
  127. string s = "";
  128.  
  129. cout << ">> ";
  130. getline(cin, s);
  131.  
  132. return s;
  133. }
  134.  
  135. void writeToFile(string title, string username, string password) {
  136.  
  137. ofstream outFile;
  138.  
  139. outFile.open("database.txt", ios_base::app);
  140. outFile << title << "t" << username << "t" << password << "n";
  141.  
  142. cout << "============= Record Added To Database ============" << endl;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement