Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Assignment

Goals

To learn about separate compilation, classes, and vector manipulation.

Your Assignment

In this assignment the main has been written for you in the file phone_book_main.cpp. You will also notice that a class called Person has been declared as well as several prototypes for functions. You will define all of these in a file called hw7.cpp. Note: When you download these files, right click on the link and then choose save link as (or save as. The exact wording depends on browser you are using.)

How the program is supposed to function.

When you first run the program it fills a vector called phone_book with some default values and then outputs the contents of the vector. After this it displays a "menu" where the user can input a number to run a function that will manipulate the phone_book vector in some manner.

1) Add people to the phone book.

2) Erase a person from the phone book.

3) Sort the phone book.

4) Shuffle the phone book.

5) Reverse the phone book.

6) Print the phone book.

7) Look up a person in the phone book.

8) Quit.

Add people to the phone book.

Selecting this option runs a function: void add_people (vector &phone_book); This function will ask a user to enter a name or Q to quit. Next it will ask for a phone number. Then the function constructs a person object using the data the user gave and add it to the end of the phone book. Then the user is again told to enter a name or Q to quit and so on.

Note: The function void add_people(vector &phone_book); requires both getline and cin to be used (getline for the name and cin for the number). The mixing of the two causes a technical problem with the new line character. There is an explanation in the book as well. Basically what happens is that after the cin there is still a newline left over and if we try to use a getline again to read a name, it gets tripped up by it. The solution is to read that newline into a dummy variable. So put another getline after the cin. cout << "Enter a phone number: "; cin >> number; string clear; getline(cin, clear); // after this the next getline will work!

Erase a person from the phone book

When a user selects this option, it first asks the user for a name (This is done in main so you are not responsible for it) then runs a function: void erase(vector &phone_book, string name); This function finds the entry in the phone book with the corresponding name and then erases it.

Sort the phone book.

Selecting this option runs a function: void sort(vector &phone_book); This function sorts the vector phone_book in lexicographical order using the name entry of the Person class.

Shuffle the phone book.

Selecting this option runs the function: void shuffle(vector &phonebook); This function works much like the shuffle function discussed in class.

Reverse the phone book.

Selecting this option runs the function: void reverse(vector &phonebook); This function reverses the vector.

Print the phone book.

Selecting this option runs the function: void print(vector &phone_book); This function outputs the contents of the vector.

Look up a person in the phone book.

When a user selects this option it first asks the user for a name (This is done in main so you are not responsible for it) then runs a function: int lookup(const vector &phonebook, string name); This function returns the phone number of the Person with the matching name. Once your function returns the phone number to the main it is then outputted to screen. (This is done in main and you are not responsible for it.)

Other instructions

You need to be careful with indices. If someone searches for a person in your phone book who is not there your program should not crash! Your function lookup should return -1, for example, when the user wants to find a phone number for a Person who is not in the phone book.
Helpful hints

You are only creating file hw7.cpp and using it in combination with the files phonebook.h and phone_book_main.cpp already provided for you.
You CANNOT change the files phonebook.h and phone_book_main.cpp!

Your first step should be to get a program that compiles without writing all the details of the functions quite yet.

You will not be able to compile until all the functions definitions have been written. Write empty function definitions with just return statements where needed.

Once the program compiles, start filling in the functions inside hw7.cpp

You may write helper functions like swap when needed.

You may use the sort function defined in the algorith library.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92078979
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Programming Language

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As