(Online Address Book Revisited) Programming Exercise 9 in Chapter 3 could handle
ID: 667876 • Letter: #
Question
(Online Address Book Revisited) Programming Exercise 9 in Chapter 3 could handle a maximum of only 500 entries. Using linked list, redo the program to handle as many entries as required. Add the following operations to your program:
a. Add or delete a new entry to the address book.
b. When the program terminates, write the data in the address book to a disk.
# include <iostream>
# include <conio>
# include <stdio>
class addressbook
{
private :
char name[500];
long ph_num; //class addressType :public addressbook
char address[500];
int year;
int mounth;
int day;
char gender;
int d,Th,y;
char M,F,m,f;
// char freind[];
public:
addressbook();
void setName();
void getName();
void getphone();
long setphone();
void setAddress();
void getAddress();
float getAverage();
int setDay();
void getDay();
int setMounth();
void getMounth();
int setYear();
void getYear();
char setGender();
void getGender();
};
addressbook::addressbook() // constructor
{
name;
ph_num=0;
year=0;
mounth=0;
day=0;
}
int addressbook::setDay()
{
cout<<" Enter the day: ";
cin>>d;
day=(d>=1 && d<32)? d : 0 ;
return day;
}
int addressbook::setMounth()
{
cout<<" Enter the mounth: ";
cin>>m;
mounth=(Th>=1 && Th<13)? Th : 0 ;
return mounth;
}
int addressbook::setYear()
{
cout<<" Enter the year : ";
cin>>y;
year=(y>=1 && y<2008)? y : 0;
return year;
}
void addressbook::getMounth()
{
cout<<mounth<<"/";
}
void addressbook::getDay()
{
cout<<" BIRTH DAY : "<<day<<"/";
}
void addressbook::getYear()
{
cout<<year;
}
char addressbook::setGender()
{
int flag=0;
cout<<" Enter the gender,(F)for female (M)for male: ";
cin>>gender;
while(flag!=1)
{
if(gender==('F')||gender==('M')||gender==('m')||gender==('f'))
flag=1;
else
{
cout<<" error.....Try Again ";
cin>>gender;
}
}
}
void addressbook::getGender()
{
cout<<" Gender : "<<gender<<endl;
}
void addressbook::getAddress()
{
cout<<" Address : "<<address<<endl;
}
void addressbook::setAddress()
{
cout<<" Enter the address: ";
gets(address);
}
void addressbook::setName()
{
cout<<" Enter the name: ";
gets(name);
}
void addressbook::getName()
{
cout<<" Name : "<<name<<" "<<endl;
}
long addressbook::setphone()
{
cout<<" Enter the person number: ";
cin>>ph_num;
return ph_num;
}
void addressbook::getphone()
{
cout<<" Person # : "<<ph_num<<endl;
}
/*class addressType :public addressbook
{
do that
};*/
main()
{
int s;
cout<<" Enter number person max(500): ";
cin>>s;
addressbook book[10];
for(int i=1;i<2;i++)
{
book[i].setName();
book[i].setphone();
book[i].setAddress();
book[i].setDay();
book[i].setMounth();
book[i].setYear();
book[i].setGender();
cout<<" * ";
}
for(int u=0;u<2;u++)
{
book[u].getName();
book[u].getphone();
book[u].getAddress();
book[u].getGender();
book[u].getDay();
book[u].getMounth();
book[u].getYear();
}
getch();
}
Explanation / Answer
# include <iostream>
# include <conio>
# include <stdio>
#include<fstream>
class addressbook
{
private :
char name[500];
long ph_num; //class addressType :public addressbook
char address[500];
int year;
int mounth;
int day;
char gender;
int d,Th,y;
char M,F,m,f;
// char freind[];
public:
addressbook();
void setName();
void getName();
void getphone();
long setphone();
void setAddress();
void getAddress();
float getAverage();
int setDay();
void getDay();
int setMounth();
void getMounth();
int setYear();
void getYear();
char setGender();
void getGender();
};
addressbook::addressbook() // constructor
{
name;
ph_num=0;
year=0;
mounth=0;
day=0;
}
int addressbook::setDay()
{
cout<<" Enter the day: ";
cin>>d;
day=(d>=1 && d<32)? d : 0 ;
return day;
}
int addressbook::setMounth()
{
cout<<" Enter the mounth: ";
cin>>m;
mounth=(Th>=1 && Th<13)? Th : 0 ;
return mounth;
}
int addressbook::setYear()
{
cout<<" Enter the year : ";
cin>>y;
year=(y>=1 && y<2008)? y : 0;
return year;
}
void addressbook::getMounth()
{
cout<<mounth<<"/";
}
void addressbook::getDay()
{
cout<<" BIRTH DAY : "<<day<<"/";
}
void addressbook::getYear()
{
cout<<year;
}
char addressbook::setGender()
{
int flag=0;
cout<<" Enter the gender,(F)for female (M)for male: ";
cin>>gender;
while(flag!=1)
{
if(gender==('F')||gender==('M')||gender==('m')||gender==('f'))
flag=1;
else
{
cout<<" error.....Try Again ";
cin>>gender;
}
}
}
void addressbook::getGender()
{
cout<<" Gender : "<<gender<<endl;
}
void addressbook::getAddress()
{
cout<<" Address : "<<address<<endl;
}
void addressbook::setAddress()
{
cout<<" Enter the address: ";
gets(address);
}
void addressbook::setName()
{
cout<<" Enter the name: ";
gets(name);
}
void addressbook::getName()
{
cout<<" Name : "<<name<<" "<<endl;
}
long addressbook::setphone()
{
cout<<" Enter the person number: ";
cin>>ph_num;
return ph_num;
}
void addressbook::getphone()
{
cout<<" Person # : "<<ph_num<<endl;
}
/*class addressType :public addressbook
{
do that
};*/
main()
{
int s;
cout<<" Enter number person max(500): ";
cin>>s;
addressbook book[s];
for(int i=0;i<s;i++)
{
book[i].setName();
book[i].setphone();
book[i].setAddress();
book[i].setDay();
book[i].setMounth();
book[i].setYear();
book[i].setGender();
cout<<" * ";
}
ofstream outf("Addressbook");
for(int u=0;u<s;u++)
{
outf<<book[u].getName();
outf<<book[u].getphone();
outf<<book[u].getAddress();
outf<<book[u].getGender();
outf<<book[u].getDay();
outf<<book[u].getMounth();
outf<<book[u].getYear();
}
outf.close();
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.