Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:
  1. Three data members: first name, last name, phone number as described above.
  2. A default and parameter constructor with arguments (first name, last name and phone number).
  3. Overload != operator that compares name with first or last names.
  4. An overloaded input stream operator >> that reads input. You may consider converting names into lower case while saving.
  5. An overloaded output stream operator << that prints all three data members, separated by a space character.
  6. 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& dir)

Write a main() function as below,

  1. Create a vector of entry and name it dir.
  2. Read all entries from the given text file and save them in the vector.
  3. Print dir.

use code below:

#include #include #include using namespace std;

//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 void print(ostream& os, container& cont) { os << cont;

}

// to print all the elment of the telephone directory

ostream& operator<<(ostream& os, vector& dir) { print(os, dir); return os; }

//Lab //Generic funciton to find a key in a container template bool find(itType first, itType last, keyType name, itType& foundEntry) { }

// A generic fucntion to find all instances of a matching name (first or last) template void Search(container dir, keyType s) { }

template void eraseEntry(container& dir, keyType s) { }

template void editEntry(container& dir, keyType s) { }

int main() { // open the file

ifstream fin("dir.txt");

string fName, lName, telNumber;

vector v1;

// 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

=+ d. What happens to the economy in subsequent periods?

Answered: 1 week ago

Question

2 n + 1 = ( 2 n ) True False

Answered: 1 week ago

Question

1. Use only alpha numeric characters.

Answered: 1 week ago