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

Book: D. S. Malik Data Structures Using C++ 2nd Edition create a c++ program fro

ID: 3737068 • Letter: B

Question

Book: D. S. Malik

Data Structures Using C++

2nd Edition

create a c++ program from chapter 3 page 205 exercise 9

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, Your program should be able to handle a and certain business associates. maximum of 500 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 a. Also, use constructors to automatically initialize the data members. Define a class extPersonType using the class personType (as defined in Example 1-12, Chapter 1), the class dateType (as designed in Pro- gramming 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 informa- b. tion. Use constructors to automatically initialize the data members. Derive the class addres sBookType from the class arrayListType, as defined in this chapter, so that an object of type addressBookType can store c. 206 Chapter 3: Pointers and Array-Based Lists objects of type extPersonType. An object of type addressBookType should be able to process a maximum of 500 entries. Add n tions to the class addressBookType so that the program should performm the following operations: i. Load the data into the address book from a disk li. Search for a person by last name ii. Print the address, phone number, and date of birth (if it exists) of a ecessary opera- given person iv. Print the names of the people whose birthdays are in a given month or between two given dates. t the names of all the people having the same status, family, friend, or business. Print the names of all vi. the people between two last names

Explanation / Answer

#include<iostream.h>

#include<stdio.h>

#include<conio.h>

#include<string.h>

class dateType

{

protected:

int dd;

int mm;

int yy;

public:

dateType()

{

dd=mm=yy=0;

}

dateType(int d,int m ,int y)

{

dd=d;mm=m;yy=y;

}

int checkMonth(int m)

{ if(mm==m)

return 1;

else

return 0;

}

void showDate()

{

cout<<" "<<dd<<"\"<<mm<<"\"<<yy;

}

};

class personType : public dateType

{

private:

char ssn[20];

char fname[20];

char lname[30];

char gender[8];

public:

personType()

{

}

void getPerson()

{

int d,m,y;

cout<<" Enter SSN No:";

cin>>ssn;

cout<<" Enter First Name:";

cin>>fname;

cout<<" Enter Last Name";

cin>>lname;

cout<<" Enter Gender[male/female]";

cin>>gender;

cout<<" Enter date of Birth";

cin>>dd>>mm>>yy;

}

int findLname(char ln[])

{

if(strcmp(lname,ln)==0)

return 1;

else

return 0;

}

int findname(char fn[],char ln[])

{

if(strcmp(fname,fn)==0)

if(strcmp(lname,ln)==0)

return 1;

else

return 0;

}

void showPerson()

{

cout<<" SSN : "<<ssn;

cout<<" First Name"<<fname;

cout<<" Last Name"<<lname;

showDate();

}

};

class addressType

{

char street[30];

char city[20];

char state[20];

char zipc[10];

public:

addressType(){ }

void getAddress()

{

cout<<" Enter Street";

cin>>street;

cout<<" Enter City";

cin>>city;

cout<<" Enter State";

cin>>state;

cout<<" Enter ZipCode";

cin>>zipc;

}

void showAddress()

{

cout<<" Street Address:"<<street;

cout<<" City :"<<city;

cout<<" State: "<<state;

cout<<" Zip Code:"<<zipc;

}

};

class extPersonType: public personType, public addressType

{

char desig[3];

char assocto[20];

public:

extPersonType()

{

}

void getPersonDetails(){

getPerson();

getAddress();

cout<<" Enter Status[Friend(f),Family Friend(ff),Business Assoc(ba)";

cin>>desig;

cout<<" Your are Assciated To Person with SSN";

cin>>assocto;

}

int checkStatus(char st[])

{

if(strcmp(st,desig)==0)

return 1;

else

return 0;

}

void showAllDetails()

{

showPerson();

showAddress();

cout<<" Desig :"<<desig;

cout<<" Associated to :"<<assocto;

}

};

class AddressBookType : public extPersonType

{

public:

void getAddressEntry()

{

getPersonDetails();

}

void showAddBook()

{

showAllDetails();

}

};

void main()

{

AddressBookType entries[50];

int c=0;

char ch='y';

while(ch=='y' || ch=='Y')

{

cout<<" Address Book Entry ";

entries[c].getAddressEntry();

cout<<" Next entry[y/n]";

cin>>ch;

}

char ln[30];

cout<<" Enter last name to Find";

cin>>ln;

for(int i=0;i<c;++i)

{

if(entries[i].findLname(ln)==1)

{ entries[i].showAddBook();

break;

}

}

char fn[20];

cout<<" Enter Person name first name and last name to Find";

cin>>fn>>ln;

for(i=0;i<c;++i)

{

if(entries[i].findname(fn,ln)==1)

{ entries[i].showAddBook();

break;

}

}

int mnth;

cout<<" Enter Month to list names";

cin>>mnth;

for(i=0;i<c;++i)

{

if(entries[i].checkMonth(mnth)==1)

{ entries[i].showAddBook();

break;

}

}

cout<<" Which status do you want to Find Friend[f]/Family Friend[ff]/Bussiness Associate[ba]";

char stat[2];

cin>>stat;

for(i=0;i<c;++i)

{

if(entries[i].checkStatus(stat)==1)

{ entries[i].showAddBook();

break;

}

}

}