Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An input file is used as data source for a telephone directory program, the first line contains the full name of the phonebook owner, second

An input file is used as data source for a telephone directory program, the first line contains the full name of the phonebook owner, second line contains the number of contacts, each of the following line represent one contact and consists of the first name, followed by the last name and finally the phone number.

Create a structure called Person with the following data members:

ownerName

fName of type vector

lName of type vector

phone of type vector

Create the following functions:

void readFile(string filename,Person &p);

void saveFile(string filename,Person &p);

Int searchByfirstName(Person &p,string target), will return the index at which the contact last name target is found ( for simplicity search for the whole text == not find).

Int searchBylastName(Person& p,string target), same as above but will search in lName.

Int searchByPhone(Person &p,int phone), same as above but will search in phone.

Your main() should create an object of the Person structure and continuously ask the user for the required action from the following actions list:

1. Search by First Name.

2. Search by Last Name.

3. Delete by phone number.

4. Exit.

For the first 2 actions, your program should ask the user for the target and print the first name, last name and phone for the found contact, error message otherwise.

In Action 3, you should ask the user for a phone number and delete the contact who has it.

The last action is to save contact back into the file and exit the whole program.

A sample input file is shown below:

Johnny English

4

Ahmad Mohamad 0504432343

Orient West 0503235412

John Jack 0524359834

Kaled Ibrahim 064343234

Sample Output:

Wellcome to Johnny English PhoneBook

Menu

1. Search by First Name.

2. Search by Last Name.

3. delete by Phone.

4. Exit.

Enter your choice :1

Enter the searching target :Mohamad

No contact found

Menu

1. Search by First Name.

2. Search by Last Name.

3. delete by Phone.

4. Exit.

Enter your choice :1

Enter the searching target :Orient

Orient West 503235412

Menu

1. Search by First Name.

2. Search by Last Name.

3. delete by Phone.

4. Exit.

Enter your choice :2

Enter the searching target :Jack

John Jack 524359834

Menu

1. Search by First Name.

2. Search by Last Name.

3. delete by Phone.

4. Exit.

Enter your choice :3

Enter the searching target :524359834

Menu

1. Search by First Name.

2. Search by Last Name.

3. delete by Phone.

4. Exit.

Enter your choice :4

Press any key to continue . . .

Modified input file:

Johnny English

3

Ahmad Mohamad 504432343

Orient West 503235412

Kaled Ibrahim 64343234

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions