Question
The program must include this h file and cpp file: Here is the h file: #include using std::string; #ifndef PERSON_H #define PERSON_H class Person {
The program must include this h file and cpp file:
Here is the h file:
#include
using std::string;
#ifndef PERSON_H #define PERSON_H
class Person { private: string firstName; string lastName; string phone; string email;
public: Person();
// getters string getFirstName(); string getLastName(); string getPhone(); string getEmail();
// setters void setFirstName(string first); void setLastName(string last); void setPhone(string phone); void setEmail(string email); };
#endif // PERSON_H
/
Here is the cpp file:
#include "person.h"
Person::Person() { firstName = ""; lastName = ""; phone = ""; email = ""; }
// getters string Person::getFirstName() { return firstName; }
string Person::getLastName() { return lastName; }
string Person::getPhone() { return phone; }
string Person::getEmail() { return email; }
// setters void Person::setFirstName(string first) { firstName = first; }
void Person::setLastName(string last) { lastName = last; }
void Person::setPhone(string phone) { this->phone = phone; }
void Person::setEmail(string email) { this->email = email; }
Objectives: Continue practicing past concepts Practice using file input/output Practice using basic C++ classes Assignment: Create a program to utilize the given C++ class (do not change the class given to you). The program will use the Person class to aid in creating an address book to manage the user's contacts. The initial contact list will be loaded from a file. The file contacts.txt has been provided for you as a base point. Each row in the file should be organized like so: firstName lastName phoneNumber emailAddress Each item will be separated by a single space. Your main program should have four functions: main O Parameters: none 0 Return values: 0 Purpose: refer to main program guidelines below read Contacts O Parameters: contacts vector (by reference), opened file (by reference) o Return values: none Purpose: read the contents of the file in a loop. Populate a Person object with each appropriate item (hint: use the setters!). Once a line has been read into a Person object, add that person to your Contacts vector. addContacts O Parameters: contacts vector (by reference), string filename o Return values: none Purpose: get input from the user for first name, last name, phone number, and email. Create a Person object from this, and add it to your vector. Additionally, open your file (in append mode) and write the data to the file in the expected format (found above). Close your file once you're done display Contacts O Parameters: contacts vector (by reference) o Return values: none o Purpose: display your vector contents (hint: use your getters!) Main program: First, ask your user for a file (to read the contacts from). Your program should loop until they have entered a valid file to read from. Make sure you've created a vector of Person type (from the class) and stored the string filename. Once they have, call your readContacts function with your vector and opened input file. Then, display a menu to the user. Loop while they want to continue in the program. Exit o Exits the menu/program Display Contacts o Calls display function Add Contacts O Calls add contacts function Incorrect menu option O Displays error in case the user has entered an invalid option Hints: For the readContacts you'll need an open file in read mode (ifstream). To properly pass these, you must pass them by reference. The add contacts function needs the file name. This file name should be the same file you opened to read from -- now you'll just be using it in a different mode. Example Execution: Welcome to your address book manager! Please enter a file to read your contacts from (include extension): contacts That file doesn't exist. Try again. Please enter a file to read your contacts from (include extension): contacts.txt File opening .. File read. Closing the file from read node. Menu: 0. Exit 1. Display Address Book 2. Add Contact What would you like to do? 1 Address book: Contact 1: Name: Kortni Neal Phone number: 555-555-5555 Email address: kdd195emsstate.edu Contact 2: Name: Aubrey Knight Phone number: 444-444-4444 Email address: akk5@nsstate.edu Menu: 0. Exit 1. Display Address Book 2. Add Contact What would you like to do? 2 Here's where we'll gather the information. What is the first nane? Test What is the last name? Person What's the phone number (no spaces)? 345-744-2346 What's the email address? test@test.com Menu: 0. Exit 1. Display Address Book 2. Add Contact What would you like to do? 1 Address book: Contact 1: Name: Kortni Neal Phone number: 555-555-5555 Email address: kdd195@msstate.edu Contact 2: Name: Aubrey Knight Phone number: 444-444-4444 Email address: akk5@nsstate.edu Contact 3: Name: Test Person Phone number: 345-744-2346 Email address: test@test.com Menu: 0. Exit 1. Display Address Book 2. Add Contact What would you like to do? 0 Good-byeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started