Question: Data Structures Using C++ 2nd Edition Chapter 3 Programming Exercise 9 Using classes, design an online address book to keep track of the names, addresses,

Data Structures Using C++ 2nd Edition

Chapter 3 Programming Exercise 9

Using classes, design an online address book to keep track of the names, addresses, phone numbers, and dates of birth of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries.

a. Define a class, addressType, that can store a street address, city, state, and zip code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the data members.

b. Define a class extPersonType using the class personType (as defined in Example 1-12, Chapter 1), the class dateType (as designed in Programming Exercise 2 of Chapter 2), and the class addressType. Add a data member to this class to classify the person as a family member, friend, or business associate. Also, add a data member to store the phone number. Add (or override) the functions to print and store the appropriate information. Use constructors to automatically initialize the data members.

c. Derive the class addressBookType from the class arrayListType, as defined in this chapter, so that an object of type addressBookType can store objects of type extPersonType. An object of type addressBookType should be able to process a maximum of 500 entries. Add necessary operations to the class addressBookType so that the program should perform the following operations:

i. Load the data into the address book from a disk.

ii. Search for a person by last name.

iii. Print the address, phone number, and date of birth (if it exists) of a given person.

iv. Print the names of the people whose birthdays are in a given month or between two given dates

v. Print the names of all the people having the same status, such as family, friend, or business.

vi. Print the names of all the people between two last names.

Here it what I have so far. I am getting an error in addressBookType.cpp: Line 64: binary '!=': no operator found which takes a left-hand operand of type 'std::basic_istream>' (or there is no acceptable conversion)

addressBookType.cpp

#include

#include "extPersonType.h"

#include "extPersonType.cpp"

#include "addressBookType.h"

void addressBookType::swap(int m, int n)

{

string str1, str2, str3, str4;

persons[m].getPerson(str1, str2);

persons[n].getPerson(str3, str4);

persons[m].setPerson(str3, str4);

persons[n].setPerson(str1, str2);

dateType bd1, bd2;

persons[m].getBirthDate(bd1);

persons[n].getBirthDate(bd2);

persons[m].setBirthDate(bd2);

persons[n].setBirthDate(bd1);

addressType add1, add2;

persons[m].getAddress(add1);

persons[n].getAddress(add2);

persons[m].setAddress(add2);

persons[n].setAddress(add1);

str1 = persons[m].getAssociation();

str2 = persons[n].getAssociation();

persons[m].setAssociation(str2);

persons[n].setAssociation(str1);

str1 = persons[m].getPhone();

str2 = persons[n].getPhone();

persons[m].setPhone(str2);

persons[n].setPhone(str1);

}

addressBookType::addressBookType()

{

ifstream inFile;

string fileName = " ";

cout << " \t Enter input file name:";

cin >> fileName;

inFile.open(fileName.c_str());

if (!inFile.is_open())

{

cout << " \tError reading in input file";

system("pause");

exit(0);

}

string strs[7];

int nums[4];

ind = 0;

while ((inFile >> strs[0] >> strs[1] >> nums[0] >> nums[1] >> nums[2] >> strs[2] >> strs[3] >> strs[4] >> nums[3] >> strs[5] >> strs[6]) != NULL) // the != in this while statement is throwing the error

{

persons[ind].setExtPerson(strs[0], strs[1], nums[0], nums[1], nums[2], strs[2], strs[3], strs[4], nums[3], strs[5], strs[6]);

ind++;

}

}

void addressBookType::sortByLastName()

{

int i, j, smallestInd;

string str1, str2, temp;

for (i = 0; i<(ind - 1); i++)

{

smallestInd = i;

for (j = i + 1; j

{

persons[j].getPerson(temp, str1);

persons[smallestInd].getPerson(temp, str2);

if (str1.compare(str2)<0)

smallestInd = j;

}

if (smallestInd != i)

swap(i, smallestInd);

}

}

void addressBookType::printAddressBook() const

{

for (int i = 0; i

{

cout << " \t";

persons[i].print();

}

}

int addressBookType::searchByName() const

{

string keyName, name, temp;

int count = 0;

cout << " \t Enter the last name to search:";

cin >> keyName;

for (int i = 0; i

{

persons[i].getPerson(temp, name);

if (keyName.compare(name) == 0)

return i;

}

return -1;

}

void addressBookType::printAPerson() const

{

int result = searchByName();

if (result == -1)

cout << " \t No person found as specified by you.";

else

{

cout << " \t";

persons[result].print();

}

}

void addressBookType::printByBirthday() const

{

dateType bd;

int month, count = 0;

cout << " \t Search address book for a given month of birthdays." << " \t Please remember name is case sensitive.";

cout << " \t Enter the month number (1...12):";

cin >> month;

for (int i = 0; i

{

persons[i].getBirthDate(bd);

if (bd.getMonth() == month)

{

cout << " \t";

persons[i].print();

count++;

}

}

if (count == 0)

cout << " \tNo person found as specified by you.";

}

void addressBookType::printNamesBetween() const

{

string keyName1, keyName2, name, temp;

int count = 0;

cout << " \tSearch address book between two given names." << " \tPlease remember name is case sensitive.";

cout << " \tEnter the last name1:";

cin >> keyName1;

cout << " \tEnter the last name2:";

cin >> keyName1;

if (keyName1.compare(keyName2)>0)

keyName1.swap(keyName2);

for (int i = 0; i

{

persons[i].getPerson(temp, name);

if ((keyName1.compare(name) <= 0) && (keyName2.compare(name) >= 0))

{

cout << " \t";

persons[i].print();

count++;

}

}

if (count == 0)

cout << " \tNo person found as specified by you.";

}

void addressBookType::printAssociation() const

{

string asso;

string types[3] = { "Family member", "Family friend", "Business Associate" };

int choice, count = 0;

cout << " \tSearch address book by association." << " \tPlease remember name is case sensitive.";

cout << " \tAssociatin Types";

cout << " \tFamily member : 1";

cout << " \tFamily friend : 2";

cout << " \tBusiness Associate : 3";

cout << " \tEnter the association type: ";

cin >> choice;

for (int i = 0; i

{

asso = persons[i].getAssociation();

if (asso.compare(types[choice - 1]) == 0)

{

cout << " \t";

persons[i].print();

count++;

}

}

if (count == 0)

cout << " \tNo person found as specified by you.";

}

addressBookType.h

#ifndef addressBookType_H

#define addressBookType_H

#include

#include

#include

#include

#include "extPersonType.h"

using namespace std;

const int MAX_ENTRIES = 500;

class addressBookType

{

public:

addressBookType();

void sortByLastName();

int searchByName() const;

void printAPerson() const;

void printAddressBook() const;

void printByBirthday() const;

void printNamesBetween() const;

void printAssociation() const;

private:

extPersonType persons[MAX_ENTRIES];

int ind;

void swap(int, int);

};

#endif

addressType.cpp

#include "addressType.h"

#include

void addressType::setStreet(string myStreet)

{

street = myStreet;

}

void addressType::setCity(string myCity)

{

city = myCity;

}

void addressType::setState(string myState)

{

state = myState;

}

void addressType::setZIP(int myZIP)

{

ZIP = myZIP;

}

string addressType::getStreet() const

{

return street;

}

string addressType::getCity() const

{

return city;

}

string addressType::getState() const

{

return state;

}

int addressType::getZIP() const // corrected

{

return ZIP;

}

void addressType::printAddress() const

{

cout << " \t" << getStreet() << ", " << getCity() << " \t" << getState() << "-" << getZIP();

}

addressType::addressType(string myStreet, string myCity, string myState, int myZIP)

{

setStreet(myStreet);

setCity(myCity);

setState(myState);

setZIP(myZIP); //corrected

}

addressType.h

#ifndef H_addressType

#define H_addressType

#include

#include

using namespace std;

class addressType

{

public:

void setStreet(string myStreet);

void setCity(string myCity);

void setState(string myState);

void setZIP(int myZIP);

string getStreet() const;

string getCity() const;

string getState() const;

int getZIP() const;

void printAddress() const;

addressType(string = " ", string = " ", string = " ", int = 0);

private:

string street;

string city;

string state;

int ZIP;

};

#endif

dateType.cpp

#include

#include "dateType.h"

void dateType::setDate(int month, int day, int year)

{

char dateStr[9];

_strdate_s(dateStr);

int thisYear = 2000 + (dateStr[6] - 48) * 10 + dateStr[7] - 48;

if ((year >= 1900) && (year <= thisYear))

dYear = year;

else

dYear = 1900;

if (month >= 1 && month <= 12)

dMonth = month;

else

dMonth = 1;

int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

if (dYear % 400 == 0 || (dYear % 100 != 0 && dYear % 4 == 0))

days[1]++;

if (day >= 1 && day <= days[dMonth - 1])

dDay = day;

else

dDay = 1;

}

void dateType::getDate(int& month, int& day, int& year) //corrected

{

dMonth = month;

dDay = day;

dYear = year;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

cout << " \t" << dMonth << "-" << dDay << "-" << dYear;

}

dateType::dateType(int month, int day, int year)

{

setDate(month, day, year);

}

void dateType::isLeapYear()

{

if (dYear % 400 == 0 || (dYear % 100 != 0 && dYear % 4 == 0))

cout << " \t Year" << dYear << "is a leap year.";

else

cout << " \tYear" << dYear << "is not a leap year.";

}

dateType.h

#ifndef dateType_H

#define dateType_H

#include

#include

using namespace std;

class dateType

{

public:

void setDate(int month, int day, int year);

void getDate(int& month, int& day, int& year);

int getDay() const;

int getMonth() const;

int getYear() const;

void isLeapYear();

void printDate() const;

dateType(int nonth = 1, int day = 1, int year = 1900);

private:

int dMonth;

int dDay;

int dYear;

};

#endif

extPersonType.cpp

#include "extPersonType.h"

#include "personType.h"

#include "dateType.h"

#include "dateType.cpp"

#include "personType.cpp"

#include "addressType.h"

#include "addressType.cpp"

void extPersonType::setBirthDate(const dateType myDate)

{

birthDate.setDate(myDate.getMonth(), myDate.getDay(), myDate.getYear()); //corrected bithDate misspelld

}

void extPersonType::getBirthDate(dateType& myDate) const

{

myDate.setDate(birthDate.getMonth(), birthDate.getDay(), birthDate.getYear());

}

void extPersonType::setAddress(const addressType address) //corrected

{

myAddress.setStreet(address.getStreet());

myAddress.setCity(address.getCity());

myAddress.setState(address.getState());

myAddress.setZIP(address.getZIP());

}

void extPersonType::getAddress(const addressType &address) //corrected

{

myAddress.setStreet(address.getStreet());

myAddress.setCity(address.getCity());

myAddress.setState(address.getState());

myAddress.setZIP(address.getZIP());

}

void extPersonType::print() const

{

birthDate.printDate();

person.print();

myAddress.printAddress();

cout << " \t" << association << ", " << phone;

}

void extPersonType::setPerson(const string first, const string last)

{

person.setFirstName(first);

person.setLastName(last);

}

void extPersonType::getPerson(string& first, string& last) const

{

first = person.getFirstName();

last = person.getLastName();

}

void extPersonType::setAssociation(const string myAssociation)

{

association = myAssociation;

}

void extPersonType::setPhone(const string myPhone)

{

phone = myPhone;

}

string extPersonType::getAssociation() const

{

return association;

}

string extPersonType::getPhone() const

{

return phone;

}

void extPersonType::setExtPerson(string first, string last, int month, int day, int year, string myStreet, string myCity, string myState, int myZIP, string asso, string ph)

{

person.setFirstName(first);

person.setLastName(last);

birthDate.setDate(month, day, year);

myAddress.setStreet(myStreet);

myAddress.setCity(myCity);

myAddress.setState(myState);

myAddress.setZIP(myZIP);

setAssociation(asso);

setPhone(ph);

}

extPersonType::extPersonType(string first, string last, int month, int day, int year, string myStreet, string myCity, string myState, int myZIP, string asso, string ph) :person(first, last), birthDate(month, day, year), myAddress(myStreet, myCity, myState, myZIP)

{

setAssociation(asso);

setPhone(ph);

}

extPersonType.h

#ifndef extPersonType_H

#define extPersonType_H

#include

#include

#include "addressType.h"

#include "personType.h"

#include "dateType.h"

using namespace std;

class extPersonType

{

public:

void print() const;

void setBirthDate(const dateType);

void getBirthDate(dateType&) const;

void setAddress(const addressType address);

void getAddress(const addressType& address);

void setPerson(const string, const string);

void getPerson(string&, string&) const;

void setAssociation(const string);

string getAssociation() const;

void setPhone(const string);

string getPhone() const;

void setExtPerson(string, string, int, int, int, string, string, string, int, string, string);

extPersonType(string = " ", string = " ", int = 1, int = 1, int = 1900, string = " ", string = " ", string = " ", int = 0, string = " ", string = " ");

private:

personType person;

dateType birthDate;

addressType myAddress;

string association;

string phone;

};

#endif

personType.cpp

#include

#include "personType.h"

void personType::setFirstName(string myFirstName)

{

firstName = myFirstName;

}

void personType::setLastName(string myLastName)

{

lastName = myLastName;

}

string personType::getFirstName() const

{

return firstName;

}

string personType::getLastName() const

{

return lastName;

}

void personType::print() const

{

cout << " \t" << firstName << " " << lastName;

}

personType::personType(string myFirstName, string myLastName)

{

setFirstName(myFirstName);

setLastName(myLastName);

}

personType.h

#ifndef personType_H

#define personType_H

#include

#include

//#include "dateType.h"

using namespace std;

class personType

{

public:

void setFirstName(string myFirstName);

void setLastName(string myLastName);

string getFirstName() const;

string getLastName() const;

void print() const;

personType(string = " ", string = " ");

private:

string firstName;

string lastName;

};

#endif

main.cpp

#include

#include "addressBookType.h"

#include "addressBookType.cpp"

using namespace std;

int main()

{

cout << " \tA program that works with addressBookType.";

addressBookType add1;

cout << " \tBefore sorting, the addresses are:";

add1.printAddressBook();

add1.sortByLastName();

cout << " \tAfter sorting, the addresses are:";

add1.printAddressBook();

if (add1.searchByName() == -1)

cout << " \tNo person found as specified by you.";

else

cout << " \tPerson found as specified by you.";

add1.printNamesBetween();

add1.printByBirthday();

add1.printAssociation();

return 0;

}

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!