Write a program in C++:
Using classes, design an online address book to keep track of the names first and last, addresses, phone numbers, and dates of birth.
The menu driven program should perform the following operations:
Sample of a record
Steve Brown 4592 Raleigh Seathle WA 98001
Record format
CODE:
#include<iostream> //for cin and cout
#include<fstream> //for ifstream and cfstream to work with
files
using namespace std;
//record class consists of attributes of person and next
pointer
class record{
public:
string fname,lname,bnumber,stname,city,phone,bdate;
struct record *next;
};
//addressBook class has all the operations to be done on
records
class addressBook{
public:
record *root;
addressBook(){
root=NULL;
}
//loads Data from file and generates linked list
void loadData(){
ifstream in;
in.open("input.txt");
if(in==NULL){
cout<<"error: unable to open input file";
return;
}
record *dummy=NULL;
root=new record;
dummy = root;
while(true){
record *p=NULL;
p=new record;
if(in>>p->fname>>p->lname>>p->bnumber>>p->stname>>p->city>>p->phone>>p->bdate){
dummy->next = p;
p->next=NULL;
dummy = p;
}else break;
}
root = root->next;
in.close();
cout<<"Data loaded!!";
}
//writes data from linked list to file
void writeData(){
ofstream out;
out.open("input.txt");
if(out==NULL){
cout<<"error: unable to open file to write data";
return;
}
record *p = root;
while(p){
out<<p->fname<<' '<<p->lname<<'
'<<p->bnumber<<' ';
out<<p->stname<<' '<<p->city<<'
'<<p->phone<<'
'<<p->bdate<<'\n';
p=p->next;
}
out.close();
cout<<"Data written into file successfully";
}
//search for the string in the linked list
void search(string s){
record *p = root;
while(p){
if(p->lname==s||p->phone==s){
cout<<"Name: "<<p->fname<<'
'<<p->lname<<endl;
cout<<"Building number:
"<<p->bnumber<<endl;
cout<<"Street name: "<<p->stname<<endl;
cout<<"City: "<<p->city<<endl;
cout<<"Phone number: "<<p->phone<<endl;
cout<<"Birth date: "<<p->bdate<<endl;
return;
}
p=p->next;
}
cout<<"\nNo record found";
}
//adds new record to linked list
void add(){
record *p=NULL;
p=new record;
cout<<"Enter first name: ";
cin>>p->fname;
cout<<"Enter last name: ";
cin>>p->lname;
cout<<"Enter building number: ";
cin>>p->bnumber;
cout<<"Enter street name: ";
cin>>p->stname;
cout<<"Enter city: ";
cin>>p->city;
cout<<"Enter Phone number: ";
cin>>p->phone;
cout<<"Enter Birth date: ";
cin>>p->bdate;
p->next = root;
root=p;
cout<<"\nRecord added successfully";
}
//deletes record from linked list with lastname or phone number as
s
void delet(string s){
record *p=NULL,*c=root;
while(c&&(c->lname==s||c->phone==s)){
p=c;
c=c->next;
}
if(p&&c){
p=c->next;
cout<<"Record deleted successfully";
}else if(p==NULL){
root=root->next;
cout<<"Record deleted successfully";
}
else cout<<"No record found. Deletion failed";
}
};
//menu displays the options to user.
void menu()
{
cout<<"\n1. Search for a person by last name or phone
number\n";
cout<<"2. Add a new entry\n3. Delete an entry based on phone
number or lastname\n";
cout<<"4. exit\n";
}
//main function implementation
int main()
{
addressBook ab; //created an object for class addressBook
ab.loadData(); //calls loadData function initially
int choice=0; //to store the user input
while(choice!=4){ //until user enters 4 the loop continues
menu();
cout<<"Enter choice: ";
cin>>choice;
if(choice==1){
cout<<"Enter last name or phone number: ";
string s;
cin>>s;
ab.search(s);
}
else if(choice==2){
ab.add();
}
else if(choice==3){
cout<<"Enter last name or phone number: ";
string s;
cin>>s;
ab.delet(s);
}
}
ab.writeData(); //calls writeData function
cout<<"\nBye!!";
return 0;
}
//input.txt before execution

//input.txt after execution

//output screenshots


Write a program in C++: Using classes, design an online address book to keep track of the names f...
Lab #2 Address Book Unsorted List (C++) Using classes, design an online address book to keep track of the names (first and last), addresses, phone numbers, and dates of birth. The menu driven program should perform the following operations: Load the data into the address book from a file Write the data in the address book to a file Search for a person by last name or phone number (one function to do both) Add a new entry to the...
(JAVA)Using classes and inheritance, design an online address book to
keep track of the names, addresses, phone numbers and birthdays of
family members, friends and business associates. Your program
should be able to handle a maximum of 500 entries.Define the following classes: Class Address to store a street name, city, state and zip
code. Class Date to store the day, month and year. Class Person to store a person's last name and first name. Class ExtPerson that extends the class...
C++ program: Write an address book program that will accomplish the following: 1. Read name and address data from the user from the keyboard. 2. While reading the names and addresses, put the names into an appropriate data structure. 3. After reading names and addresses, allow user to search for names and change the names or addresses in the container data structure. 4. Allow user to write out the container data structure to a comma delimited file. The input file...
Please help!!
(C++ PROGRAM)
You will design an online contact list to keep track of names
and phone numbers.
·
a. Define a class contactList that can store a name and up to 3
phone numbers (use an array for the phone numbers). Use
constructors to automatically initialize the member variables.
b.Add the following operations to your program:
i. Add a new contact. Ask the user to enter the name and up to 3
phone numbers.
ii. Delete a contact...
In C++, Write a program that retrieves a phone number from a database of names and phone numbers. The program should ask the user to enter a name and then print the phone number of that person (or vice versa, number into name) The program should allow the user to repeat the operation as often as they would like to. The data is contained in two text files named "phoneNames.txt" and "phoneNums.txt". The files have one name or one phone...
In this assignment, you will write one (1) medium size C program. The program needs to be structured using multiple functions, i.e., you are required to organize your code into distinct logical units. The following set of instructions provide the specific requirements for the program. Make sure to test thoroughly before submitting. Write a program, named program1.c, that reads and processes employee records (data about an employee). Each employee record must be stored using a struct that contains the following ...
Write a C program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program...
Write a java project that reads a sequence of up to 25 pairs of names and postal (ZIP) codes, street address, city, state, and 10-digit phone number for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer), street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' . Assume each...
In C++, Write a program that retrieves a phone number from a txt files of names and phone numbers. The program should ask the user to enter a name and then print the phone number of that person (or vice versa, number into name) The program should allow the user to repeat the operation as often as they would like to. The data is contained in two text files named "phoneNames.txt" and "phoneNums.txt". The files have one name or one...
Using c++ Write a program that reads in a list of up to 25 first names from an input file nameData.txt and allows the user to display the name data, sort it in ascending or descending order, count the number of occurrences of a given name, or exit the program. The input file consists of a single names per line with each line terminated with an end of line (i.e. using Enter key to end the line). Your program should...