Question: C++ Create a struct named AddressBook that stores multiple Entry structs (that you created in the previous exercise). Your code must be saved in a

C++

Create a struct named AddressBook that stores multiple Entry structs (that you created in the previous exercise). Your code must be saved in a file named AddressBook.h and should reuse your code from Entry.h.

Member functions for AddressBook should be able to add an entry and print all the entries in the address book. Your code will be tested with the file addressBook.cpp, which reads in several entries from standard input, stores them in an AddressBook instance and prints them all out.

adressBook.cpp:

#include

#include "AddressBook.h"

int main(int argc, const char * argv[])

{

int n;

cin >> n;

string name, lastname, email;

cin >> name;

cin >> lastname;

cin >> email;

AddressBook * myAddressBook = new AddressBook(name, lastname, email);

AddressBook * current;

for (int i = 1; i < n; i++) {

cin >> name;

cin >> lastname;

cin >> email;

current = new AddressBook(name, lastname, email);

myAddressBook->add(current);

}

myAddressBook->print();

return 0;

}

Entry.h:

#define ENTRY_H

#include

#include

using namespace std;

struct Entry {

string name, last, mail;

void setName(const string first_name){

name = first_name; }

void setLastName(const string last_name){

last = last_name; }

void setEmail(const string email){

mail = email; }

void print(){

cout<

};

Input: 3 Bjarne Stroustrup bstroustrup@hotmail.com Guido Rossum grossum@hotmail.com Ada Lovelace alovelca@hotmail.com

Output: Bjarne,Stroustrup,bstroustrup@hotmail.com Guido,Rossum,grossum@hotmail.com Ada,Lovelace,alovelca@hotmail.com

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!