Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please search for the blue C++ programming book (blue book) and help

ID: 3583726 • Letter: C

Question

Can someone please search for the blue C++ programming book (blue book) and help me type the programming exercise #1 in chapter 17?

The question is:

Online Address Book revisited) Programming Exercise 5 in Chapter 11 could handle a maximum of only 500 entries. Using linked lists, redo the program to handle as many entries as required. Add the following operations to your program:

Add or delete a new entry to the address book.

Allow the user to save the data in the address book.

This is #5 from chapter 11:

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  entries.

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 member variables.

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

Define the class addressBookType using the previously defined classes. An object of the type addressBookType should be able to process a maximum of  entries.

The program should perform the following operations:

Load the data into the address book from a disk.

Sort the address book by last name.

Search for a person by last name.

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

Print the names of the people whose birthdays are in a given month.

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

Depending on the user’s request, print the names of all family members, friends, or business associates.

Explanation / Answer

main.cpp

#include <iostream>
#include <fstream>
#include "addressType.h"
#include "personType.h"
#include "dateType.h"
#include "extPersonType.h"
#include "addressBookType.h"
using namespace std;


const int MAX_ENTRIES = 500;

int main(){
    addressBookType addrObject;
    string searchV, first, last;
    int month;
    addrObject.setInfo("addrData.txt");
    addrObject.nameSort();
    cout << "Please enter your search: ";
    cin >> searchV;
    if(searchV == "bday"){
        cout << "Please enter your month: ";
        cin >> month;
        addrObject.bDaySearch(month);
    }
    if(searchV == "range"){
        cout << "Please enter the two names: ";
        cin >> first >> last;
        addrObject.printRange(first, last);
    }
    if(searchV == "family" || searchV == "friend"
        || searchV == "associate"){
        addrObject.printType(searchV);
    }
    else
        addrObject.nameSearch(searchV);

}

addressBookType.cpp

#include "addressBookType.h"

using namespace std;

addressBookType::addressBookType(){
}

void addressBookType::setInfo(string file){
    string fName, lName;
    int aMonth, aDay, aYear;
    string addr, cit, sta;
    int zip;
    string type;
    long int phone;
    inF.open(file.c_str());
    for(int i = 0; i < MAX_ENTRIES; i++){
        inF >> fName >> lName >> aMonth
        >> aDay >> aYear >> addr >> cit
        >> sta >> zip >> type >> phone;
        addrBook[i].setExtPersonType(fName, lName, aMonth, aDay, aYear,
                                     addr, cit, sta, zip, type, phone);
    }
    inF.close();
}

void addressBookType::printInfo() const{
    for(int i = 0; i < MAX_ENTRIES; i++){
        addrBook[i].printExtPersonType();
        cout << endl;
    }
}

void addressBookType::nameSort(){
    extPersonType temp;
    for(int i = 1; i < MAX_ENTRIES; i++){
        for(int j = 0; j < MAX_ENTRIES-1; j++){
            if(addrBook[j].getLastName() > addrBook[j+1].getLastName()){
                temp = addrBook[j];
                addrBook[j] = addrBook[j+1];
                addrBook[j+1] = temp;
            }
        }
    }
}

void addressBookType::nameSearch(string choice){
    cout << "Returning results for " << choice << ": "<< endl;
    for (int i = 0; i < MAX_ENTRIES; i++){
        if(addrBook[i].getLastName() == choice)
            addrBook[i].printExtPersonType();
    }
}

void addressBookType::bDaySearch(int month){
    for(int i = 0; i < MAX_ENTRIES; i++){
        if(addrBook[i].getBday() == month){
            addrBook[i].printNames();
            cout << endl;
        }
    }
}

void addressBookType::printRange(string first, string last) const{
    for(int i = 0; i < MAX_ENTRIES; i++){
        if(first <= addrBook[i].getLastName()
            && addrBook[i].getLastName() <= last){
            addrBook[i].printNames();
            cout << endl;
        }
    }
}

void addressBookType::printType(string choice) const{
    for(int i = 0; i < MAX_ENTRIES; i++){
            if(addrBook[i].getType() == choice){
                addrBook[i].printNames();
                cout << endl;
            }
    }
}


addressBookType.h

#ifndef ADDRESSBOOKTYPE_Hg
#define ADDRESSBOOKTYPE_H
#include <iostream>
#include <fstream>
#include "extPersonType.h"


class addressBookType: public extPersonType
{
    public:
        addressBookType();
        void setInfo(string);
        void nameSort();
        void nameSearch(string);
        void bDaySearch(int);
        void printInfo() const;
        void printNames() const;
        void printRange(string, string) const;
        void printType(string) const;
    private:
        static const int MAX_ENTRIES = 2;
        extPersonType addrBook[MAX_ENTRIES];
        ifstream inF;

};

#endif // ADDRESSBOOKTYPE_H


addressType.cpp

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

addressType::addressType(string addr, string cit,
                            string sta, int zip){
    setAddressType(addr, cit, sta, zip);
}

void addressType::setAddressType(string addr, string cit,
                            string sta, int zip){
    address = addr;
    city = cit;
    state = sta;
    zipCode = zip;
}

void addressType::getAddressType(string& addr, string& cit,
                            string& sta, int& zip){
    addr = address;
    cit = city;
    sta = state;
    zip = zipCode;
}

void addressType::setAddress(string addr){
    address = addr;
}

string addressType::getAddress() const{
    return address;
}

void addressType::setCity(string cit){
    city = cit;
}

string addressType::getCity() const{
    return city;
}

void addressType::setState(string sta){
    state = sta;
}

string addressType::getState() const{
    return state;
}

void addressType::setZip(int zip){
    zipCode = zip;
}

int addressType::getZip() const{
    return zipCode;
}

void addressType::print() const{
    cout << "Address: " << address << endl;
    cout << "City: " << city << endl;
    cout << "State: " << state << endl;
    cout << "Zip: " << zipCode << endl;
}


addressType.h

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

addressType::addressType(string addr, string cit,
                            string sta, int zip){
    setAddressType(addr, cit, sta, zip);
}

void addressType::setAddressType(string addr, string cit,
                            string sta, int zip){
    address = addr;
    city = cit;
    state = sta;
    zipCode = zip;
}

void addressType::getAddressType(string& addr, string& cit,
                            string& sta, int& zip){
    addr = address;
    cit = city;
    sta = state;
    zip = zipCode;
}

void addressType::setAddress(string addr){
    address = addr;
}

string addressType::getAddress() const{
    return address;
}

void addressType::setCity(string cit){
    city = cit;
}

string addressType::getCity() const{
    return city;
}

void addressType::setState(string sta){
    state = sta;
}

string addressType::getState() const{
    return state;
}

void addressType::setZip(int zip){
    zipCode = zip;
}

int addressType::getZip() const{
    return zipCode;
}

void addressType::print() const{
    cout << "Address: " << address << endl;
    cout << "City: " << city << endl;
    cout << "State: " << state << endl;
    cout << "Zip: " << zipCode << endl;
}


addressType.h

#ifndef ADDRESSTYPE_H
#define ADDRESSTYPE_H
#include <string>
using namespace std;

class addressType
{
    public:
        addressType(string = "", string = "", string = "", int = 0);
        void setAddressType(string, string, string, int);
        void getAddressType(string&, string&, string&, int&);
        void setAddress(string);
        string getAddress() const;
        void setCity(string);
        string getCity() const;
        void setState(string);
        string getState() const;
        void setZip(int);
        int getZip() const;
        void print() const;
    private:
        string address;
        string city;
        string state;
        int zipCode;
};

#endif

dateType.cpp

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

dateType::dateType(int month, int day, int year){
    setDate(month, day, year);
}

void dateType::setDate(int month, int day, int year){
    if(validDate(month, day, year)){
        dMonth = month;
        dDay = day;
        dYear = year;
    }
    else{
        dMonth = 0;
        dDay = 0;
        dYear = 0;
    }
}

int dateType::getDay() const{
    return dDay;
}

int dateType::getMonth() const{
    return dMonth;
}

int dateType::getYear() const{
    return dYear;
}

void dateType::print() const{
    cout << dMonth << "-" << dDay << "-" << dYear;
}

bool dateType::isLeapYear(int year) const{
    return (!(year%4) && (year % 100) || !(year % 400));
}

bool dateType::validDate(int month, int day, int year) const{
    int monthlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    if(!year || !month || !day || month > 12)
        return 0;
    if(isLeapYear(year) && month == 2)
        monthlen[1]++;
    if(day > monthlen[month-1])
        return 0;
    return 1;
}

dateType.h

#ifndef DATETYPE_H
#define DATETYPE_H


class dateType
{
    public:
        void setDate(int, int, int);
        int getDay() const;
        int getMonth() const;
        int getYear()const;
        void print() const;
        dateType(int month = 1, int day = 1, int year = 1900);
    private:
        bool isLeapYear(int) const;
        bool validDate(int, int, int) const;
        int dMonth;
        int dDay;
        int dYear;
};

#endif // DATETYPE_H

dateType.cpp

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

dateType::dateType(int month, int day, int year){
    setDate(month, day, year);
}

void dateType::setDate(int month, int day, int year){
    if(validDate(month, day, year)){
        dMonth = month;
        dDay = day;
        dYear = year;
    }
    else{
        dMonth = 0;
        dDay = 0;
        dYear = 0;
    }
}

int dateType::getDay() const{
    return dDay;
}

int dateType::getMonth() const{
    return dMonth;
}

int dateType::getYear() const{
    return dYear;
}

void dateType::print() const{
    cout << dMonth << "-" << dDay << "-" << dYear;
}

bool dateType::isLeapYear(int year) const{
    return (!(year%4) && (year % 100) || !(year % 400));
}

bool dateType::validDate(int month, int day, int year) const{
    int monthlen[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    if(!year || !month || !day || month > 12)
        return 0;
    if(isLeapYear(year) && month == 2)
        monthlen[1]++;
    if(day > monthlen[month-1])
        return 0;
    return 1;
}

dateType.h

#ifndef DATETYPE_H
#define DATETYPE_H


class dateType
{
    public:
        void setDate(int, int, int);
        int getDay() const;
        int getMonth() const;
        int getYear()const;
        void print() const;
        dateType(int month = 1, int day = 1, int year = 1900);
    private:
        bool isLeapYear(int) const;
        bool validDate(int, int, int) const;
        int dMonth;
        int dDay;
        int dYear;
};

#endif // DATETYPE_H

extPersonType.cpp

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

extPersonType::extPersonType(string first, string last,
                            int month, int day, int year,
                            string addr, string cit,
                            string sta, int zip, string pType,
                            long int phone)
        : name(first, last), birthday(month, day, year),
        address(addr, cit, sta, zip){
        type = pType;
        phoneNum = phone;
}

void extPersonType::setExtPersonType(string first, string last,
                                    int month, int day, int year,
                                    string addr, string cit,
                                    string sta, int zip, string pType,
                                    long int phone){
        name.setName(first, last);
        birthday.setDate(month, day, year);
        address.setAddressType(addr, cit, sta, zip);
        type = pType;
        phoneNum = phone;
}

void extPersonType::printExtPersonType() const{
    cout << "Name: ";
    name.print();
    cout << endl << "Birthdate: ";
    birthday.print();
    cout << endl;
    address.print();
    cout << "Type: " << type << endl;
    cout << "Phone #: " << phoneNum;
}

void extPersonType::printNames() const{
    name.print();
}

string extPersonType::getLastName() const{
    return name.getLastName();
}

int extPersonType::getBday() const{
    return birthday.getMonth();
}

string extPersonType::getType() const{
    return type;
}


extPersonType.h

#ifndef EXTPERSONTYPE_H
#define EXTPERSONTYPE_H
#include <string>
#include "personType.h"
#include "dateType.h"
#include "addressType.h"
using namespace std;

class extPersonType
{
    public:
        extPersonType(string first = "", string last = "",
                        int month = 0, int day = 0, int year = 0,
                        string addr = "", string cit = "",string sta = "",
                        int zip = 0, string pType = "", long int phone = 0);
        void setExtPersonType(string first, string last, int month,
                        int day, int year, string addr, string cit,
                        string sta, int zip, string pType, long int phone);
        void printExtPersonType() const;
        void printNames() const;
        string getLastName() const;
        string getType() const;
        int getBday() const;
    private:
        personType name;
        dateType birthday;
        addressType address;
        string type;
        long int phoneNum;
};

#endif

personType.cpp

#include <iostream>
#include "personType.h"

personType::personType(string first, string last){
    setName(first, last);
}

void personType::print() const{
    cout << firstName << " " << lastName;
}

void personType::setName(string first, string last){
    firstName = first;
    lastName = last;
}

string personType::getFirstName() const{
    return firstName;
}

string personType::getLastName() const{
    return lastName;
}


personType.h

#ifndef PERSONTYPE_H
#define PERSONTYPE_H
#include <string>
using namespace std;

class personType
{
    public:
        personType(string first = "", string last = "");
        void print() const;
        void setName(string first, string last);
        string getFirstName() const;
        string getLastName() const;
    private:
        string firstName;
        string lastName;
};

#endif


addrData.txt

Jamian Vieira 1 30 1991 21439GolondrinaSt. WoodlandHills California 91364 friend 8186357010 Brittany Lancaster 7 30 1992 14231CallahanSt.
PanoramaCity California 91402 family 8184780718