Question: Language: C++ Instructions: Write a program that will manage a simple address book. The program should allow you to view and search existing entires as

Language: C++

Instructions:

Write a program that will manage a simple address book. The program should allow you to view and search existing entires as well as add new entries. The data should be stored in a file structured so that a person's first name, last name, and phone number are stored on one line separated by commas and the next line has their address.

Additional requirements:

The program should allow the user to make repeated requests until they choose to exit

The program should show multiple matches if present

The program should have an option to print out a list that just includes Name and Phone Number

The program should use at least two struct types and one enumerated type

---------------------------------------------------------------------------------------

Below is the code I have so far. The problem is that the code does not work correctly at all. I don't know how to store the data that is being input.

--------------------------------------------------------------------------------------

main.cpp

#include #include "header.h"

int maincounter = 0; int getcount = 0; using namespace std;

void addPerson(struct person &add); void getPerson(struct person &get); //void findPerson (struct person &find); //void findPerson (struct person &findlast, struct person &findfirst); void findPerson (struct Person &findMe, const char *firstName); void findPerson (struct Person &findMe); person bookArray[MaxPeople]; //This is the main "address book" array

int main() { char *last = new char[20]; char *first = new char[20]; char choice; person add; person getStruct; cout << "Address Book" << endl<< endl;

while (true){

cout << "Type 1 to add to the address book. " <

cout << endl << "Please make a selection: "; cin >> choice;

switch(choice) {

case '1': cout << "Enter First Name: "; cin >> add.first; cout << "Enter Last Name: "; cin >> add.last; cout << "Enter Address: "; cin >> add.address; cout << "Enter Number: "; cin >> add.number; cin.getline(add.address, 40); addPerson(add); break;

case '2': cout << "Getting the next person in the address book: " << endl << endl; cout << getStruct.first << " " << getStruct.last << endl; cout << getStruct.address << endl; cout << getStruct.number << endl; break;

case '3': cout << "Please enter the last name to search for: " << endl; cin >> last; //findPerson(last); break; case '4': cout << "Please enter the last name and then the first name to search for: " << endl; cout << "Last name: "; cin >> last; cout << "First name: "; cin >> first; //findPerson(last, first); break;

default: return 0; break; } } return 0; }

void addPerson(struct person &add) { bookArray[maincounter]=add; maincounter++; }

void getPerson(struct person &get) { if (getcount > maincounter) { getcount = 0; get = bookArray[getcount]; getcount++; } else { get = bookArray[getcount]; getcount++; } }

void findPerson(struct Person &findMe, const char *firstName) { // Walk the array and compare the value of findMe.first to // the value of firstName, and if the match, set findMe to that // entry and return. }

header.h:

const int MaxPeople = 10; struct person { char first[64]; char last[64]; char address[128]; char number[32]; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!