Create a class called AddressBook that uses either C++ - Vector in the data section of the class. Since this is a template / generic type you need to make sure that you specify that ArrayList or vector  will hold a Person. You should use the Person class you created in Assignment 1.  Essentially, we are creating a collection class.  In other words, the AddressBook class will be a collection of Person classes.  Constructors AddressBook(); - default constructor. Should have no functionality.  AddressBook(string first, string last);  - Adds a Person class to the collection and sets address field to an empty string AddressBook(string first, string last, string address); - Adds a Person class to the collection. Mutators setPerson(string first, string last, string address); - Adds a Person to the collection Accessors C++  All accessors will return a pointer to a Person Person *getPerson(); - Returns the next Person in the collection. Each time this function is called it will return the next Person in the list or NULL if the  AddressBook is empty.  Once you get to the end of the list you should start from element 0 and return the first person.  Person *findPerson(string last); - returns the found Person or NULL if Person is not in the AddressBook Person *findPerson(string first, string last); -  returns the found Person or NULL of Person is not in the AddressBook void print();- Prints out the entire AddressBook

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create a class called AddressBook that uses either

  • C++ - Vector

in the data section of the class. Since this is a template / generic type you need to make sure that you specify that ArrayList or vector  will hold a Person. You should use the Person class you created in Assignment 1.  Essentially, we are creating a collection class.  In other words, the AddressBook class will be a collection of Person classes. 

Constructors

  • AddressBook(); - default constructor. Should have no functionality. 
  • AddressBook(string first, string last);  - Adds a Person class to the collection and sets address field to an empty string
  • AddressBook(string first, string last, string address); - Adds a Person class to the collection.

Mutators

setPerson(string first, string last, string address); - Adds a Person to the collection

Accessors

C++  All accessors will return a pointer to a Person

  • Person *getPerson(); - Returns the next Person in the collection. Each time this function is called it will return the next Person in the list or NULL if the  AddressBook is empty.  Once you get to the end of the list you should start from element 0 and return the first person. 
  • Person *findPerson(string last); - returns the found Person or NULL if Person is not in the AddressBook
  • Person *findPerson(string first, string last); -  returns the found Person or NULL of Person is not in the AddressBook
  • void print();- Prints out the entire AddressBook

 

Please can you write it in C++ coding form because I never took Java.

Can you help me solve this problem in C++ forms using the Classes / Constructors method like:

main.cpp

Person.h

Person.cpp

addressbook.cpp

addressbook.h

PLease write the coding in c++ forms.

Here is my coding to help you to understand the assigment.

Person.h

#include<iostream>
#include<string.h>
using namespace std;

//declare class person
class Person
{
    //declare data members of class
    private:
    string firstName;
    string lastName;
    string address;
    //declare member functions of class
    public:
    void help();
    Person();
    Person(string first, string last);
    Person(string first, string last, string address);
    void setFirstName(string first);
    void setLastName (string last);
    void setAddress (string address);
    string getFirstName();
    string getLastName();
    string getAddress();

};

Person.cpp

 

#include "Person.h"
#include<iostream>
#include<string.h>
using namespace std;


//function to reduce redundancy
void Person::help()
{
    //sets address to empty string
    address="";
}
//default constructor
Person::Person()
{
    //sets first and last name to empty string and calls help function to set address to empty string
    firstName="";
    lastName="";
    help();
}
//parameterized constructor
Person::Person(string first, string last)
{
    //set values of data members of the class
    firstName=first;
    lastName=last;
    help();
}
//another parameterized constructor
Person::Person(string first, string last, string address)
{
    //set values of data members of the class
    firstName=first;
    lastName=last;
    address=address;
}
void Person::setFirstName(string first)
{
    //set firstname
    firstName=first;
}
void Person::setLastName(string last)
{
    //set lastname
    lastName=last;
}
void Person::setAddress(string address)
{
    //set address
    this->address=address;
}
string Person::getFirstName()
{
    //return first name
    return firstName;
}
string Person::getLastName()
{
    //return lastname
    return lastName;
}
string Person::getAddress()
{
    //return address
    return address;
}

main.cpp

#include "Person.h"
#include<iostream>
#include<string.h>
using namespace std;

void getPeople(Person a[])
{
    int i;
    string f,l,add;
    //for every Person
    for(int i=0;i<5;i++)
    {
        cout<<"Enter details of Person "<<(i+1)<<endl;
        cout<<"Enter First Name ";
        //input firstname
        getline(cin,f);
        //set firstname by calling method of class
        a[i].setFirstName(f);
        cout<<"Enter Last Name ";
        //input lastname
        getline(cin,l);
        //set lastname by calling method of class
        a[i].setLastName(l);
        cout<<"Enter address ";
        //input address
        getline(cin,add);
        //set address by calling method of class
        a[i].setAddress(add);
    }
}

void printPeople(Person a[])
{
    int i;
    cout<<"FirstName\tLastName\tAddress\n"<<endl;
    //for every person
    for(int i=0;i<5;i++)
    {
        //print its details
        cout<<a[i].getFirstName()<<"\t\t"<<a[i].getLastName()<<"\t\t"<<a[i].getAddress();
        cout<<endl;
    }
}

int main()
{
    //declare array of class person of size 5
    Person p[5];
    //call function to get inputs
    getPeople(p);
    //call function to print array of class Person
    printPeople(p);
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Generic Type
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education