Question: This small project is geared to get you started on writing Object Oriented program using either Java or C++. The AddressBook Class Create a class
This small project is geared to get you started on writing Object Oriented program using either Java or C++.
The AddressBook Class
Create a class called AddressBook that uses either
- Java - ArrayList
- 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
Java
- 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 if Person is not in the AddressBook
- void print();- Prints out the entire AddressBook
Similar program
:
//Person that will hold information about a single individual //Using array of objects & constructor delegating #include#include using namespace std; //Class's definition begin class Person{ //Data members string firstName; string lastName; string address; public: //Constructors Person(){ //Empty string this->firstName = ""; this->lastName = ""; this->address = ""; } Person(string first, string last) : Person() { //Constructor Delegation used here this->firstName = first; this->lastName = last; } Person(string first, string last, string address){ this->firstName = first; this->lastName = last; this->address = address; } //Setters for Person class void setFirstName(string first){ this->firstName = first; } void setLastName(string last){ this->lastName = last; } void setAddress(string address){ this->address = address; } //Getters for Person string getFirstName(){ return firstName; } string getLastName(){ return lastName; } string getAddress(){ return address; } }; //class 'person' ends here //fill out the array with information about people void getPeople(Person per[5]){ for(int i=0; i<5; i++){ cout<<"Input for Person "< Note:
You need to use one code path whenever possible. This means you must have delegating constructors. The working constructor can call a function if you wish. In other words, if you have a function that performs a task, you should call it instead of writing duplicate code.
Main
Create functions in main.cpp that will test each of the functions you created. I will leave it up to you as to how to test them but please make sure that I cannot easily force your functions to crash.
similar this assignment but I need it in the main.cpp, address.book.cpp, and address.book.h forms
Can you please write the coding in C++ forms
Can you write the c++ coding in three functions like this?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
