Question

In: Computer Science

Design a C++ program An address book is a book or a database used for saving...

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

Solutions

Expert Solution

#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:


Related Solutions

Problem: Design and write a C language program that can be used as a unit converter...
Problem: Design and write a C language program that can be used as a unit converter application. Your unit converter should contain at least four unit categories, for example: length, mass, temperature, and time. The program should display the main menu that contains unit categories that are available, and the user will be prompted to select a unit category first. After the unit category has been selected the program should then display another menu (i.e., a submenu) that contains at...
Database __________ which is the logical design of the database, and the database _______ which is...
Database __________ which is the logical design of the database, and the database _______ which is a snapshot of the data in the database at a given instant in time. a) Instance, Schema b) Relation, Schema c) Relation, Domain d) Schema, Instance
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
True or False: Logical database design is the process of modifying the physical database design to...
True or False: Logical database design is the process of modifying the physical database design to improve performance. The two major logical database design techniques are conversion of E-R diagrams to relational tables and data normalization. Multivalued attributes are not permitted in unnormalized data. A many-to-many binary relationship in an E-R diagram requires the creation of a total of three tables in a relational database. A one-to-one unary relationship in an E-R diagram requires the creation of a total of...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
Write a C program that creates a database of plant height samples. In this scenario a...
Write a C program that creates a database of plant height samples. In this scenario a researcher enters a name of a group/type of plants, and heights for each plant in the group/type Use input will be stored in a database file, which should be a file called database.csv and should be in the following formatPlant1, number_of_samples, sample1, sample2, sample3 ...Plant2, number_of_samples, sample1, sample2, sample3 ...Plant3, number_of_samples, sample1, sample2, sample3 ...Lines starts with the name of a plant type, then...
Creating a Database Design Lab 1: Creating a Database Design (Wk 3) - OR - Draw...
Creating a Database Design Lab 1: Creating a Database Design (Wk 3) - OR - Draw with pencil and paper diagram (take photo of it and submit) along with a summary of the diagram you prepared in a Word document. Use the scenario from Assignment 1: Business Rules and Data Models to complete the lab: Suppose a local college has tasked you to develop a database that will keep track of students and the courses that they have taken. In...
C++.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1)...
C++.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() - Outputs the item name and description Private data members string itemDescription -...
5) Name the data model that is only used to document a database design. 6) State...
5) Name the data model that is only used to document a database design. 6) State the most important characteristics regarding the output of any relational algebra operation. 7) Name the software system that permits the data in a distributed database to be transparent to others. 8) Use two words to distinguish a file based system and a database.
Design and construct a computer program in one of the approved languages (C, C++, C#, Java,...
Design and construct a computer program in one of the approved languages (C, C++, C#, Java, Pascal, Python, etc.) that will illustrate the use of a fourth-order explicit Runge-Kutta method of your own design. In other words, you will first have to solve the Runge-Kutta equations of condition for the coefficients of a fourth-order Runge-Kutta method. Then, you will use these coefficients in a computer program to solve the ordinary differential equation below. Be sure to follow the documentation and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT