Question
Exercise 1: The file dir.txt (provided) contains the details of several entries who are part of a team. Each line contains the information about one
Exercise 1:
The file dir.txt (provided) contains the details of several entries who are part of a team. Each line contains the information about one person and consists of space-separated fields i.e., two strings that are the first name and the last name, followed by the telephone number.
For example, the first two lines might contain:
Ahmed Badawi 508998024
Syes AlGhabra 6480235
- Write a class entry with the following data and function members:
- Three data members: first name, last name, phone number as described above.
- A default and parameter constructor with arguments (first name, last name and phone number).
- Overload != operator that compares name with first or last names.
- An overloaded input stream operator >> that reads input. You may consider converting names into lower case while saving.
- An overloaded output stream operator << that prints all three data members, separated by a space character.
- You may add getter functions as required.
- Write a generic a function print that can take any container (vector, list etc) and print the entries.
template
void print(ostream& os, container& cont)
- overload ostream that prints vector of entry. Call print function.
ostream& operator<<(ostream& os, vector
Write a main() function as below,
- Create a vector of entry and name it dir.
- Read all entries from the given text file and save them in the vector.
- Print dir.
use code below:
#include
//to make the search case insensitive string toLowerCase(string s) { for (unsigned int i = 0; i < s.size();i++) { s[i]=char(tolower(int(s[i]))); } return s; }
//Prelab class entry { private: string fName; string lName; uint64_t telNumber; public: entry( const string& f="", const string& l = "", uint64_t n = -999) {
}
bool operator!=(const string & name) {
} uint64_t getNumber(){return telNumber; }
friend ostream& operator<<(ostream& os, const entry& ent) { os << ent.fName << " " << ent.lName << " " << ent.telNumber << endl;
return out; } friend istream& operator>>(istream& is, entry& ent){ } };
//Generic function to print all the entries of the any container template
}
// to print all the elment of the telephone directory
ostream& operator<<(ostream& os, vector
//Lab //Generic funciton to find a key in a container template
// A generic fucntion to find all instances of a matching name (first or last) template
template
template
int main() { // open the file
ifstream fin("dir.txt");
string fName, lName, telNumber;
vector
// read lines from file
while (fin >> fName >> lName >> telNumber)
{
// make an entry object
entry e(fName, lName, telNumber);
// add it to vector
v1.push_back(e);
}
// print vector
cout << v1;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started