6.1 The Phone Book Application (Part 1 or 1)
Building the PhoneBook and PhoneEntry classes
You are going to build a simple phone book that uses two classes, PhoneEntry and PhoneBook.
You will be creating a PhoneEntry.h file, a PhoneEntry.cpp file, a PhoneBook.h file and a PhoneBook.cpp file.
Make sure your .h file include “include guards” and make sure you do NOT have any using statements in the .h files.
You can have #include statements in your .h file, but not any using statements. That means you will have to fully qualify any included classes.
For example, if you need the string class you will need a #include in the header file and you will have to declare your string as std::string.
You will also need an assignment3.cpp file (with your main function) that will test all of the functions of your new classes.
This code is really for you to test your PhoneEntry and PhoneBook classes. Make sure you call every member function in both of the classes.
PhoneEntry class
The PhoneEntry class contains two private fields, name and number. You need to create accessor functions and mutator functions for both of these fields. You will also need a copy constructor and an assignment operator. You will also need an equal’s operator. These are all going to be member functions in class PhoneEntry.
The signatures of these member functions (these are all defined in class PhoneEntry) must be:
The assignment operator must copy the name and number values from the right hand side (rhs) to the left hand side (the this pointer).
The operator== will return true only if both phone entries contain the same values for name, and the same values for number.
The operator< needs to first check the name values. if the left hand side name is less than the right hand side name return true. If the lhs name is greater than the rhs name return false. If they are the same return the <, =, or > values of the lhs number and the rhs number.
Once you have written operator== and operator< you can implement all of the other comparison operators using the == and < operators. See the section Relational operators in the cppreference.com web site for details.
You also need to write the standalone function for operator<< to output the contents of a phone entry to the output stream. This is NOT defined in class PhoneEntry, but must be included in the PhoneEntry.h file and implemented in the PhoneEntry.cpp file.
The output from operator<
Your PhoneEntry class will need 0 argument constructor, a two argument constructor, a copy constructor, and a destructor. Note that your destructor may not do anything, but I want you to code one. Make sure you initialize the data in your object in the constructors. The 0 argument constructor should set both the name and number values to "" (a string of length 0).
Note that you MUST not inline all of these functions. You can only inline a member function if it is 1 or 2 lines of code.
PhoneBook class
The PhoneBook class is more complicated. You must create two constructors, a copy constructor, and a destructor for the PhoneBook class. Make sure you initialize the data in your object in the constructors. In the private data for your PhoneBook class you will have an array of PhoneEntry objects. You must be able to support N phone entries (type PhoneEntry). If you use the 0 argument constructor the PhoneBook will need to have an array large enough to store 10 phone book entries (N will be 10).
The 2nd constructor will take an int parameter that specifies the maximum number of entries in the phone book (so the parameter value on the constructor is N).
In both constructors you will need to dynamically create the array of phone book entries of the appropriate size. You will use the new [] operator to do this. You also need to make sure you delete this array in the destructor. You must use a dynamically created array. You are not allowed to use the std::vector class for this assignment.
In your class do something similar to the following (you will need more that this in your class):
You also need private data to keep track of how many entries you are actually using in the array. You will need to set this to 0 in your constructor.
So, your PhoneBook class will have an array of PhoneEntry objects.
You will also need the following public member functions in your PhoneBook class.
Function add will fill in the next available PhoneEntry with the passed in name and number. If there are no more available entries the function should just return and not add the name and number to the phone book.
The findFirstByName function will return the index of the first entry with the specified name. The value -1 must be returned if the name is not found in the PhoneBook.
The findFirstByNumber function will return the index of the first entry with the specified number. The value -1 must be returned if the number is not found in the PhoneBook.
The findFirst function will return the index of the first entry with the specified PhoneEntry values. This will use the operator== defined in the PhoneEntry class. The value -1 must be returned if the phone entry is not found in the PhoneBook.
The removeByName function will remove the first entry in the phone book it finds that has a name that matches the passed in parameter. If no entry has that name the function does nothing.
You must remove the entry in the following way.
You move entries in the array around to fill in the now (removed) entry.
If, as an example, you find name in the entry with index 3 and you currently using 9 of the 10 entries in the array you will need to copy the entry from index 4 to index 3. You will then copy entry 5 to entry 4, entry 6 to entry 5, entry 7 to entry 6, and entry 8 to entry 7. You will then decrement the number of entries used from 9 to 8. Entries 0, 1 and 2 are not modified in any way.
The removeByNumber function removes the first entry in the phone book that contains the number specified by the input parameter. Like removeByName the function should return and do nothing if the number is not found. You will have to move around entries in the array as you did with removeByName.
The remove function removes the first entry in the phone book where the name and number match the value of the passing in PhoneEntry. Use the PhoneEntry operator== to do this comparison. You must implement the same removal logic used in the other remove functions. You may want to have a private member function that does this and is called by the three remove functions.
The getSize function returns the number of entries currently in use. This could be anywhere from 0 to the max size specified at creation time.
The getCapacity function returns the maximum number of entries the phone book can support. Depending on the constructor used this could be 10 or the number passed to the constructor.
Finally, the at and operator[] functions return the current entry at the index passed to the function via the position parameter. If position is > the current size you should return back the last valid entry. If position is valid, return back that entry. Note that there is a bug in this logic if there are no valid entries in the array. For now we will just live with the bug.
There area actually two versions of the at function and two versions of operator[]. One version of each returns a reference to the PhoneEntry and the other version returns a const reference.
The const version will not allow you to update the returned PhoneEntry object.
The non-const version is needed if you want to update the item returned by either at or operator[]. For example:
You should have the at function call the operator[] function if you don’t want to duplicate code in both functions.
The copy constructor and assignment operators need to make sure the object being copied from and being copied to are not the same object. You also have to make sure the left hand side of an assignment does not create a memory leak. You have to delete the left hand side array, create a new one, and copy the values from the right hand side to the left hand side. The only time you can reuse the left hand side array is if the maximum number of elements is exactly the same as the right hand side.
Again you can only inline functions that are 1 or 2 lines of code.
You need to define the PhoneEntry and PhoneBook classes in a header files and you need to put the implementation of the member functions in source files. Again, you must not inline all member functions. You should only inline a function if it is 1 or 2 lines of code.
Examples of code using the PhoneBook and PhoneEntry.
The following code snippets show the usage of the PhoneBook and PhoneEntry classes.
Building the main function.
You need to create a main function. The main needs to create a PhoneBook, add entries to the PhoneBook, and remove entries from the PhoneBook. You should also loop through the entries in the PhoneBook by using the getSize and phoneEntryAt functions and you should loop though the entries in the PhoneBook by using the getSize function and subscripts []. You can then display the name and number using the << operator you created.
You need to make sure you are using the copy constructor and the assignment operator for the PhoneBook and PhoneEntry classes.
Be very careful that you do not have any memory leaks in your program.
Put your main function in a file called assignment3.cpp.
Programming style
Make sure your variable names have meaningful names and that you have included appropriate comments in your application.
You need to ensure you have comments throughout your program and not just the comments at the top of the program.
Your program must have the name assignment3.cpp.
Grading:
20% of the grade will for comments you have in your program, for having meaningful variable names, and proper indentation.
80% will be for the program itself. Make sure you do all of the parts and that your output matches what is shown in the sample runs.
Compile command
We will use this command to compile your code
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme