Not a complicated program because i am a beginnner. write a program with some fo
ID: 3846874 • Letter: N
Question
Not a complicated program because i am a beginnner. write a program with some form of record management system. It needs comments throughout the program and these are the requrements:
Fully modularize your program
Use pass by reference parameters wherever appropriate
You must use record (structs) stored in an array or vector
Your program must be able to save the vector of input data to a file and reopen that file later.
Your program must be menu driven
The menu shall have following functionality:
Enter a single new record (same as example)
Enter many records one-after-the-other option (not in the example)
Edit and Delete records
Search for and display one record (part of this functionality is required for edit and delete suggesting that “search” is a function used by more than one process)
Display a listing of all records (truncate appropriately so that all important information appears on one line)
Sort by name or id of record
Sort by one other field of your choice
Save to file
Open file
Quit
Also, Fully describe the problem in your own words using point form.
Also, Fully describe the solution program using point form. This should be an external view of the program from the perspective of someone using it
Also, Variables and Constants (List in point form and describe the purpose of each)
Also, a flowchart and hierarchy chart.
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stdexcept>
#include <fstream>
#include <sstream>
using namespace std;
struct Account
{
string _username;
string _website;
string _password;
};
Account typedef acc;
vector<acc> creds;
/**
* Adds a new credential to the list.
* @param {string} w - Website name
* @param {string} u - Username
* @param {string} p - Password
* @param {vector} arr - Array that holds credentials.
*/
void add(
string w, string u,
string p, vector<acc> &arr)
{
acc a1{u, w, p};
arr.push_back(a1);
};
void write(string filename, vector<acc> &arr)
{
ofstream out(filename, ios_base::binary);
for (int i = 0; i < arr.size(); ++i)
{
// web user pass
out << arr.at(i)._website << " "
<< arr.at(i)._username << " "
<< arr.at(i)._password << endl;
}
out.close();
};
void read(string filename, vector<acc> &arr)
{
// cleanup
arr.clear();
ifstream in(filename, ios_base::binary);
acc a1{};
string line;
while (getline(in, line))
{
stringstream ss1{line};
// web user pass
ss1 >> a1._website
>> a1._username
>> a1._password;
arr.push_back(a1);
}
in.close();
};
/**
*
*/
void show_all(vector<acc> &arr)
{
cout << setw(10) << left << "Website"
<< setw(10) << right << "Username"
<< setw(20) << right << "Password" << endl;
for (int i = 0; i < arr.size(); ++i)
{
// web user pass
cout << setw(10) << left << arr.at(i)._website
<< setw(10) << right << arr.at(i)._username
<< setw(20) << right << arr.at(i)._password << endl;
}
};
int main()
{
// add("Rj", "google", "theChamp", creds);
// add("Dj", "fb", "Winner", creds);
read("somefile.txt", creds);
show_all(creds);
return 0;
}
Well I started developing it right now. A password manager. Will keep adding to this code on git hub under ramachandrajr as a project.
Cheers,
Primehero
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.