Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the Vector by creating a Person Class, an Employer Class and a Personal Info Class . Use the Employer and PersonalInfo classes as member

Modify the Vector by creating a Person Class, an Employer Class and a Personal Info Class. Use the Employer and PersonalInfo classes as member variables of a Person class. Modify the Vector class to hold People objects instead of Record objects. Modify the menu interface and input algorithms to accept data for the Employer and Personal Info classes via functions in the Person class. Modify the Output to print all the information in each Person object, associated Employer object, and associated Personal Info object. Make sure to separate the implementation of your classes from the header files. You should have a .cpp file and a .h file for each class you create.

header.h

#include #include #include using namespace std; class Record { private: int age;

long long int phone;

int record;

string first, last;

public: Record(); Record(int, string, string, int, int); void display(); void setData(int, string, string, int, int); }; Record::Record() { record = 0; age = 0; phone = 0;

} Record::Record(int rec, string first, string last, int ag, int phone) {

record = rec; first= first; last = last; age = ag; phone= phone; } void Record::setData(int rec, string first, string last, int ag, int phone) { record = rec;

first = first;

last = last;

age = ag;

phoner = phone; } void Record::display() { cout << " -------------------- Contact Information -------------------- ";

cout << "Record number: " << record << endl;

cout << "First name: " << first << endl;

cout << "Last name: " << last << endl;

cout << "Age: " << age << endl;

cout << "Phone number: " << phone << endl; } void menu() { cout << " ------------------------ Selection Menu ----------------------- ";

cout << " enter 1 to add contact" << endl;

cout << " enter 2 to display contacts" << endl;

cout << " enter 3 to end program" << endl; }

vector.cpp

#include #include #include "Header.h"

int main() { int count = 0; int record, age, choice; long long int phone; string first, last; int size = 10;

// vector is used instead of the array

vector rec(10); cout << " -------------| Vector |------------- ";

while (1) { menu(); cout << " input option: "; cin >> choice; if (choice == 1) { if (count ==1000) { cout << " The contacts are full" << endl; } else { //if choice to enter contact, gather information

cout << " enter record number: "; cin >> record; cout << " enter contact first name: "; cin.ignore(); getline(cin, first);

cout << " enter contact last name: ";

getline(cin, last);

cout << "enter contact age: "; cin >> age;

cout << "enter contact phone number: "; cin >> phone; rec[count].setData(record, first, last, age, phone); count++; } } else if (choice == 2) { //if choice 2 is used show records

if (count == 0) { cout << "No contacts" << endl; } else { for (int i = 0; i < count; i++) { rec[i].display(); } } } else if (choice == 3) { return 0; } else { //when wrong option is entered show

cout << "enter option from 1 to 3" << endl; }

} return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions