Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Record::getTitle': non-standard syntax; use '&' to create a pointer to member
- 'Record::getUsername': non-standard syntax; use '&' to create a pointer to member
- 'Record::getPassword': non-standard syntax; use '&' to create a pointer to member
- writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <map>
- #include <functional>
- using namespace std;
- string GetInput();
- void MainMenu();
- void Title();
- void AddRecord();
- void writeToFile(string title, string username, string password);
- class Record {
- private:
- string id;
- string title;
- string username;
- string password;
- static int numberOfRecords;
- public:
- void setTitle(string title) {
- this->title = title;
- }
- string getTitle() {
- return title;
- }
- void setUsername(string username) {
- this->username = username;
- }
- string getUsername() {
- return username;
- }
- void setPassword(string password) {
- this->password = password;
- }
- string getPassword() {
- return password;
- }
- static int GetNumberOfRecords() {
- return numberOfRecords;
- }
- };
- struct MenuAction {
- string description;
- function<void()> action;
- };
- static const map <string, MenuAction> actionTable{
- { "1",{ "Add entry", []() { AddRecord(); } } },
- { "2",{ "Edit entry", []() { cout << "Edit entry" << "n"; } } },
- { "q",{ "Quit", []() { cout << "Quit" << "n"; } } }
- };
- int main() {
- Title();
- MainMenu();
- return 0;
- }
- void Title() {
- cout << "======================================n"
- "| Database |n"
- "======================================nn";
- }
- void MainMenu() {
- for (auto const& x : actionTable) {
- cout << x.first << ". " << (x.second).description << "n";
- }
- string input;
- while (actionTable.count(input) == 0) {
- input = GetInput();
- }
- actionTable.at(input).action();
- }
- void AddRecord() {
- cout << "============= Add Record ============" << endl << endl;
- string id;
- string title;
- string username;
- string password;
- cout << "Title: ";
- getline(cin, title);
- cout << "Username: ";
- getline(cin, username);
- cout << "Password: ";
- getline(cin, password);
- Record firstRecord;
- firstRecord.setTitle(title);
- firstRecord.setUsername(username);
- firstRecord.setPassword(password);
- writeToFile(firstRecord.getTitle, firstRecord.getUsername, firstRecord.getPassword);
- }
- string GetInput() {
- string s = "";
- cout << ">> ";
- getline(cin, s);
- return s;
- }
- void writeToFile(string title, string username, string password) {
- ofstream outFile;
- outFile.open("database.txt", ios_base::app);
- outFile << title << "t" << username << "t" << password << "n";
- cout << "============= Record Added To Database ============" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement