DESCRIPTION
Create a C++ program to manage phone contacts.
The program will allow the user to add new phone contacts, display
a list of all contacts, search for a specific contact by name,
delete a specific contact.
The program should provide the user with a console or command line
choice menu about possible actions that they can perform.
The choices should be the following:
1. Display list of all contacts.
2. Add a new contact.
3. Search for a contact given the contact’s first or last
name.
4. Delete a contact.
5. Edit contact
6. Exit program.
To represent a contact in your program, create the following
fields:
• firstName - string
• lastName - string
• phoneNumber - long
• phoneType – enum PhoneType
The PhoneType can be only one of the following: “CELL”, “HOME”,
“WORK”. When the program first loads, it reads all the saved
contacts (if any) from a file named database.txt into an Array.
While the program is running, the user can choose any of the 5
available options. When the user selects the option 5 (exit
program), the program stores the current contents of the Array to
the file (replacing the old contents) and exits.
During the program execution, if the user chooses to add or delete
items, only the Array will be updated. The database.txt file will
be updated automatically only when the program is about to exit. In
other words, when the user selects option 5, the program first
saves all the contents of the Array into the text file, and then
exits.
The format of the contents of the database.txt file should be in
human readable plain text, one record per line (note the ~
separator between different entries) For example:
Shawn~Seals~5124567890~0
Ted~Sheckler~2104567890~2
Chip~Chipperson~9404567890~1
For display, contacts should be printed to the console in the
following format.
Chip Chipperson, Home (940)456-7890
Shawn Seals, Cell (512)456-7890
Ted Sheckler, Work (210)456-7890
Your array will not be a fixed size. You will dynamically declare
an array that is the exact size you need. If you add a contact, you
will need to increase the array size. If you delete a contact, you
will need to decrease the array size.
Do not declare any value type Contact variables in your code.
Instead, declare reference (pointer) type Contact variables and
dynamically allocate memory for the actual Contact. For
example…
Contact contact; // DO NOT DO THIS ANYWHERE! This is a value type
variable.
Contact *contact = new Contact; // Do this instead. This is a
reference type variable.
You will no longer use a struct to represent a Contact. You will
use a class to represent a Contact.
Your Contact class will have its own .h (header) file and .cpp
(implementation) file. The Contact class will not be declared or
implemented in main.cpp.
Professor will provide the contents of the Contact.h file. You may
add to it if necessary. You will write the contents of the
Contact.cpp file.
The member variables (firstName, lastName, phoneNumber, phoneType)
of the Contact class must be private. The phoneNumber instance
variable needs to be changed from a type long to a type string. You
will provide getters and setters to access these variables.
Your setter for phoneNumber will only allow valid data to be set to
the Contact instance variable. If invalid data is passed into this
setter, it will return false.
You will add “UNKNOWN” to the PhoneType enum. This new value will
be placed at the end of the enum.
You will write a Contact constructor which takes firstName and
lastName as arguments to be used in the creation of a new Contact.
This constructor will set the phone number to the string “Unknown”
and the phoneType to UNKNOWN. You will NOT provide a default
constructor.
You will add an “Edit Contact” feature to the main menu of the
application. This feature will be option 5. “Exit” will be changed
to option
The “Edit Contact” feature will prompt the user to enter the last
name of the contact they would like to edit and then present the
user with a numbered list of all matching contacts. The user will
then select a contact from the list to edit. The user will then be
able to edit any of the contact’s fields.
//Contact.h provided by professor
#ifndef ASSIGNMENT4_H_CONTACT_H #define ASSIGNMENT4_H_CONTACT_H #include <string> using namespace std; enum PhoneType { CELL, HOME, WORK, UNKOWN }; class Contact { private: string firstName; string lastName; string phoneNumber; PhoneType phoneType; public: Contact(string firstName, string lastName); void setFirstName(string firstName); string getFirstName(); void setLastName(string lastName); string getLastName(); bool setPhoneNumber(string phoneNumber); string getPhoneNumber(); void setPhoneType(PhoneType phoneType); PhoneType getPhoneType(); }; #endif //ASSIGNMENT4_H_CONTACT_H
//Contact Manager
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>
enum class PhoneType {
CELL,
HOME,
WORK,
UNKOWN
};
class Contact{
private:
string firstName;
string lastName;
long int phoneNumber;
PhoneType phoneType;
public:
void getdata();
void showdata();
char *getname(){ return firstName; }
char *getphno(){ return phoneNumber; }
void update(char *nm,char *telno){
strcpy(firstName,nm);
strcpy(phoneNumber,telno);
}
};
void Contact :: getdata(){
cout<<"\nEnter Name : ";
cin>>firstName;
cin>>lastName;
cout<<"Enter Phone No. : ";
cin>>phoneNumber;
cout<<"Enter Phone Type";
cin>>phoneType;
PhoneType PT = PhoneType::phoneType;
}
void Contact :: showdata(){
cout<<"\n";
cout<<setw(20)<<firstName;
cout<<setw(15)<<phoneNumber;
cout<<setw(15)<<PT;
}
void main(){
Contact rec;
fstream file;
file.open("c:\\Contact.h", ios::ate | ios::in | ios::out |
ios::binary);
char ch,nm[20],telno[6];
int choice,found=0;
while(1){
clrscr();
cout<<"\n*****Contact Manager*****\n";
cout<<"1) Add New
Contact\n";
cout<<"2) Display
All Contacts\n";
cout<<"3) Search
Contact Number\n";
cout<<"4) Search
Person Name\n";
cout<<"5) Edit
Telephone No.\n";
cout<<"6)
Exit\n";
cout<<"Choose your
choice : ";
cin>>choice;
switch(choice){
case 1 : //New Record
rec.getdata();
cin.get(ch);
file.write((char *) &rec, sizeof(rec));
break;
case 2 : //Display All Records
file.seekg(0,ios::beg);
cout<<"\n\nRecords in Phone Book\n";
while(file){
file.read((char *) &rec, sizeof(rec));
if(!file.eof())
rec.showdata();
}
file.clear();
getch();
break;
case 3 : //Search Tel. no. when person name is known.
cout<<"\n\nEnter Name : ";
cin>>nm;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(nm,rec.getname())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
getch();
break;
case 4 : //Search name on basis of tel. no
cout<<"\n\nEnter Telephone No : ";
cin>>telno;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(telno,rec.getphno())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
getch();
break;
case 5 : //Update Telephone No.
cout<<"\n\nEnter Name : ";
cin>>nm;
file.seekg(0,ios::beg);
found=0;
int cnt=0;
while(file.read((char *) &rec, sizeof(rec)))
{
cnt++;
if(strcmp(nm,rec.getname())==0)
{
found=1;
break;
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
else
{
int location = (cnt-1) * sizeof(rec);
cin.get(ch);
if(file.eof())
file.clear();
cout<<"Enter New Telephone No : ";
cin>>telno;
file.seekp(location);
rec.update(nm,telno);
file.write((char *) &rec, sizeof(rec));
file.flush();
}
break;
case 6 : gotoout;
}
}
out:
file.close();
}
DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...
Need help working through CLion: Description: For this assignment you will create a program to manage phone contacts. Your program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. Your program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2....
Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
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...
a. Define the struct node that can store a name and up to 3 phone numbers (use an array for the phone numbers). The node struct will also store the address to the next node. b. Define a class contactList that will define a variable to keep track of the number of contacts in the list, a pointer to the first and last node of the list. c. Add the following methods to the class: i. Add a new contact....
(C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...
Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...
Please write this program in C++, thanks Task 9.3 Write a complete C++ program to create a music player Your program should read in several album names, each album has up to 5 tracks as well as a genre. First declare genre for the album as an enumeration with at least three entries. Then declare an album structure that has five elements to hold the album name, genre, number of tracks, name of those tracks and track location. You can...
language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...
Instructions We're going to create a program which will allow the user to add values to a list, print the values, and print the sum of all the values. Part of this program will be a simple user interface. 1. In the Program class, add a static list of doubles: private statie List<double> _values new List<double>) this is the list of doubles well be working with in the program. 2. Add ReadInteger (string prompt) , and ReadDouble(string prompt) to the...
This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone book using a linked list to keep people's names and phone numbers organized in alphabetical order. 1. Define a structure to hold the contact information including: name, phone number, a pointer to the next node in the list. Example: struct ContactNode { string name; string phoneNumber; ContactNode *next; } 2. Define a class containing the structure and the appropriate methods to update and retrieve...