In: Computer Science
Design a C++ program
An address book is a book or a database used for saving and
storing contacts which may usually
consists of a few standard fields (for example: first name, last
name, company name, address,
telephone number, e-mail address, fax number, mobile phone
number).
Design an online address book to keep track of the details of
family members, close friends and
certain business associates. Details which your designed address
book will keep should be like
names (first name, last name), gender, addresses (street address,
city, province/state, zip code),
phone numbers, and dates of birth (date, month, year). Your program
should be able to handle a
maximum of 150 entries.
There should be TWO MAJOR MODULES of your program one should allow
the user to add, update
delete the entries and classify the entered person as a family
member, friend, or business associate
and another module should maintain one address book which must be
able to process a maximum
of 150 entries and also should perform the following
operations:
Load the data into the address book from a disk.
Search for a person by last name.
Print the gender, address details, phone number, and date of
birth of a given person.
Print the names of the people whose birthdays are in a given
month or between two given
dates.
Print the names of all the people having the same status, such as
family, friend, or
business.
Print the names of all the people having the same status, such as
family, friend, or
business.
Print the names of all the people between two last names.
Print the details of all people with same gender.
Make a C++ file on Microsoft visual and answer with the proper code
#include <iostream>
#include <fstream>
using namespace std;
//defining a structure to holds the address in one place
typedef struct Address{
string street;
string city;
string state;
int zipcode;
}Address;
//to hold date properlly
typedef struct Date{
int dd, mm, yyyy;
}Date;
//to hold the entire info in one place
typedef struct Record{
string fname, lname;
string gender;
Address address;
long phone;
Date dob;
string status;
}Record;
//utility function to search a record with lname
//n: number of records
Record searchByLastName(Record * records, string name, int n){
for(int i = 0; i < n; i++){
if(records[i].lname == name){
return records[i];
}
}
//if not fount return an empty record
return {"","","",{"","","",0},0,{0,0,0}};
}
//print info properly
void printInfo(Record record){
//if record is not a empty record
if(record.fname != ""){
cout<<"Name: "<<record.fname<<" "<<record.lname<<endl;
cout<<"Gender: "<<record.gender<<endl;
cout<<"Address: "<<record.address.street<<","<<record.address.state<<","<<record.address.zipcode<<endl;
cout<<"Phone: "<<record.phone<<endl;
cout<<"DOB: "<<record.dob.dd<<"/"<<record.dob.mm<<"/"<<record.dob.yyyy<<endl;
}else{
cout<<"Info not available"<<endl;
}
}
void update(Record * records, string name, int n, Record updated){
for(int i = 0; i < n; i++){
if(records[i].fname == name){
records[i] = updated;
}
}
}
void printPersonsWithBdayMonth(Record * records, int mm, int n){
cout<<"Persons with bday in Month "<<mm<<endl;
for(int i = 0; i < n; i++){
if(records[i].dob.mm == mm){
cout<<records[i].fname<<" "<<records[i].lname<<endl;
}
}
}
void printStatusWithSameStatus(Record * records, string status, int n){
cout<<"Persons with status: "<<status<<endl;
for(int i = 0; i < n; i++){
if(records[i].status == status){
cout<<records[i].fname<<" "<<records[i].lname<<endl;
}
}
}
void printPeopleBetweenTwoName(Record * records, string fname, string sname, int n){
cout<<"Persons between "<<fname<<" and"<<sname<<endl;
for(int i = 0; i < n; i++){
if(records[i].lname < sname && records[i].lname > fname){
cout<<records[i].fname<<" "<<records[i].lname<<endl;
}
}
}
void printPeopleWithSameGender(Record * records, string gender, int n){
cout<<"Persons with Gender : "<<gender<<endl;
for(int i = 0; i < n; i++){
if(records[i].gender == gender){
cout<<records[i].fname<<" "<<records[i].lname<<endl;
}
}
}
int main() {
ifstream fin("data.txt");
Record records[150];
int i = 0;
while(fin>>records[i].fname>>records[i].lname>>records[i].gender>>records[i].address.street>>records[i].address.city>>records[i].address.state>>records[i].address.zipcode>>records[i].phone>>records[i].dob.dd>>records[i].dob.mm>>records[i].dob.yyyy>>records[i].status){
i++;
}
Record record = searchByLastName(records, "doe", i);
printInfo(record);
Record updaed = {
"updatedjohn",
"updateddoe",
record.gender,
record.address,
record.phone,
record.dob,
record.status
};
update(records, "john", i, updaed);
cout<<"After updation!!\n";
record = searchByLastName(records, "updateddoe", i);
printInfo(record);
cout<<endl;
printPersonsWithBdayMonth(records, 03, i);
cout<<endl;
printPeopleWithSameGender(records, "male", i);
cout<<endl;
printStatusWithSameStatus(records, "family", i);
}
data.txt
john doe male 101BeverlyHills Boston US 100112 73562365 02 03
1998 family
john1 doe female 1012BeverlyHills Boston US 100112 73562365 02 03
1998 business
john2 doe female 1013BeverlyHills Boston US 100112 73562365 02 03
1998 friend
john3 doe male 1014BeverlyHills Boston US 100112 73562365 02 03
1998 family
screenshots: