I am trying to read in a user entry for a fname lname and a phone number (number) into a function named accordingly in a private class. since i do not know how to read them directly from the input stream ( cin >> get_fname(); ) i do not know how i would go about defining how to get them read into the proper place
I honestly do not know how to go about this.
using namespace std;
string getResponse()
{
string response;
cout << endl << "What would you like to do?" << endl;
cout << "Add and entry (a),";
cout << "Sort list (s)," << endl;
cout << "Print the list (p),";
cout << "Find a name (f)," << endl;
cout << "Quit (q)?";
cin >> response;
return response;
}
void printEntry(Entry entry)
{
cout << entry.get_fname() << " " << entry.get_lname() << " " << entry.get_number() << endl;
}
void findName(const list<Entry>& data, string name)
{
for (list<Entry>::const_iterator iter = data.begin(); iter != data.end(); iter++){
if (name == iter->get_lname()){
printEntry(*iter);
}
}
}
Entry readEntry()
{
Entry entry;
cout << "Please enter a first name: ";
string fname;
cin >> fname;
entry.get_fname(fname);
cout << "Please enter a last name: ";
string lname;
cin >> lname;
entry.get_lname(lname);
cout << "Please enter a phone number: ";
string number;
cin >> number;
entry.get_number(number);
return entry;
}
class Entry {
private:
std::string fname;
std::string lname;
std::string number;
public:
std::string get_fname() const;
std::string get_lname() const;
std::string get_number() const;
};
#endif // ENTRY_H_INCLUDED
#include "entry.h"
std::string Entry::get_fname() const {
return fname;
}
std::string Entry::get_lname() const {
return lname;
}
std::string Entry::get_number() const {
return number;
}