I'm in a Programming class in high school and we're learning C++. I have a graded lab that is due and I have little to no clue how to approach it. Any ideas? Any help would be greatly appreciated.
Overview:
Your job is to maintain a list of contact names and phone numbers in sorted order and allow the user to add or delete contacts.
Contacts –
A vector will be defined empty that will be used to hold the contacts. The contacts are stored as strings in the format LASTNAME, FIRSTNAME XXX-XXX-XXXX.
Your Job:
Write a program that will maintain the contacts so when a user enters a contact the list will be re sorted alphabetically from ‘a’ to ‘z’. And when a contact is deleted, the list is maintained in order and the size is reduced by 1.
Algorithm: (all function calls are from int main( ) except for the call to SearchinVector by FindandDeleteFromVector)
Write and call a void function called LoadVector( ). This function receives the vector
to be loaded. Ask the user for input and dynamically load the vector until a SENTINEL is
reached. Use constants where appropriate.
Display how many contacts are in vector. (This is done in int main( )).
Write and call a void function called SortVector( ). This function receives a vector and sorts the vector.
Write and call a void function called DisplayVector( ). This function receives a vector and displays the contents of the vector on a single line.
Ask the user which contact they would like to delete in format LASTNAME, FIRSTNAME. (This is done in int main( )).
*you may ask the user for the contact to be deleted by asking them for the
LASTNAME, FIRSTNAME XXX-XXX-XXXX. or by displaying a list and asking them for the one they would like to delete and then use that to move the value of the corresponding LASTNAME, FIRSTNAME XXX-XXX-XXXX into the string variable to search for.
Write and call a void function called FindandDeleteFromVector( ). This function
receives a vector and the contact to be deleted. It then calls SearchinVector( ),and once it gets the index position it will delete the contact and reduce the vector size by 1.
Write and call an int function SearchinVector( ). This function receives a vector and contact to be located and returns the index position location of contact.
Display how many contacts are in vector. (This is done in int main( )).
Write and call a void function called SortVector( ). This function receives a vector and sorts the vector.
Write and call a void function called DisplayVector( ). This function receives a vector and displays the contents of the vector on a single line.
Test Cases:
Run the program at least 2 times with multiple deletions demonstrating that it works properly.
How stupid is that to hold 3 fields in a single string, i.e.
Firtsname
Lastname
Phone number
Would be better to have a simple struct and have a string for each field:
1 2 3 4 5 6
struct data
{
string firstname;
string lastname;
string phone;
};
and then have a vector of these structs. Sometimes, you wonder if the teachers know themselves what they are attempting to teach, no wonder the students haven't got a clue what to do. Mind you some of these students don't appear to learn.