Design and implement a simple phone book application that stores and manipulates contacts and their phone numbers using Phyton. Requirements specification: The system to be designed and implemented is a phone book that deals with contacts data and their phone numbers, similar in functionality to contacts apps found on smartphones. The system should be able to record and manipulate (add, update, delete, and search) data about contacts and their phone numbers. The data need to be stored in a text file. The following information and constraints should be captured in the application: 1. Each contact is uniquely identified in our phone book by ids. (e.g. 1, 2, 3,…). 2. Each contact has first and last name. (e.g. “John David”). 3. Each contact can have multiple phone numbers (up to three phone numbers). 4. The system should be able to support manipulation of contacts and their phone numbers: • Add (e.g. add/create contact with id 1, first name “John”, last name ”David”, and phone 1234567890). • Update (e.g. change the first name, last name or phone numbers). • Delete (e.g. remove contact with all data associated with that contact including id, first name, last name, and phone numbers). • Search (the system should be able to support querying contacts data based on the first name, last name, and phone numbers).
Here is the python class for the contact and phone book
import sys
class Contact:
def __init__(self, id, firstName, lastName, phone):
self.id = id
self.firstName = firstName
self.lastName = lastName
self.phone = phone
def __str__(self):
return 'Id: {}, Name: {} {}, Phone: {}'.format(self.id,
self.firstName, self.lastName, self.phone)
class PhoneBook:
def __init__(self):
self.contacts = []
def load_data(self):
fname = "phone.txt"
try:
fileobj = open(fname, 'r')
except IOError:
print("Could not read file:", fname)
return
for line in fileobj:
line = line.strip()
entry = line.split("\t")
if len(entry) == 4: # confirms a valid entry
c = Contact(entry[0],entry[1],entry[2],entry[3])
self.contacts.append(c)
def addContact(self, contact):
self.contacts.append(contact)
def getContact(self):
return contacts
def searchContact(self, id):
for c in self.contacts:
if c.id == id:
return c
return None
def removeContact(self, id):
c = self.searchContact(id)
if c is None:
return False
self.contacts.remove(c)
return True
def updateContact(self, id,firstName, lastName, phone):
c = self.searchContact(id)
if c is None:
return False
c.firstName = firstName
c.lastName = lastName
c.phone = phone
return True
def __str__(self):
contacts = [str(c) for c in self.contacts]
contacts.sort()
return 'Phone Book contacts \n{}' .format('\n'.join(contacts))
pb = PhoneBook();
pb.load_data();
print(pb)
def search_contact(word, by,choice):
global pb
fname = "phone.txt"
try:
fileobj = open(fname, 'r')
except IOError:
print("Could not read file:", fname)
sys.exit()
search_result = []
sstr =""
for rec in pb.contacts:
print(rec)
if by == 'f':
sstr = rec.firstName
elif by == 'l':
sstr = rec.lastName
elif by == 'p':
sstr = rec.phone
if sstr.lower() == word.lower():
search_result.append(rec)
#print(search_result)
if(len(search_result) > 0):
print("ID\tFirst\tLast\tPhone")
print("-"*60)
for s in search_result:
print(str(s.id)+"\t"+ s.firstName+"\t"+ s.lastName+"\t"+
s.phone+"\n")
print("-"*60)
print("Total matching Record Found :",len(search_result))
print("Delete Contact(d)\nUpdate Contact(u)\nBack(b)")
action = input("Enter your choice: ")
if action == "d" or action == "u":
action_id = int(input("Enter id of record please: "))
if action == "d":
if pb.removeContact(action_id):
print("Record deleted successfully")
# print contacts stored in phone book
print(pb)
else:
print("Error in deleting contact")
if action == "u":
first = input("Enter the First Name: ").strip()
second = input("Enter the Last Name: ").strip()
phone = input("Enter the Phone numbers separated by comma:
").strip()
if pb.updateContact(self, id,firstName, lastName, phone):
print("Record updated successfully")
# print contacts stored in phone book
print(pb)
else:
print("Error in updating contact")
else:
print("No record found")
print("Welcome to phone book application ")
# Show menu in loop
while (True):
print("Add Contact(a)")
print("Search Contact(s)")
print("Quit(q)")
#store the user choice
choice = input("Enter your option: ").strip().lower()
if choice not in ('a','s','q'):
print("Invalid option. Try again!")
else:
if choice == 'q':
break
elif choice == 's':
print("Which field to search?")
print("First Name (f)\nLast Name (l)\nOr phone (p)\n")
by = input("Enter your choice: ").strip().lower()
#if by not in ('f','l','p'):
word = input("Enter your search word please: ").strip()
search_contact(word,by,choice)
elif choice == 'a':
first = input("Enter the First Name: ").strip()
second = input("Enter the Last Name: ").strip()
phone = input("Enter the Phone numbers separated by comma:
").strip()
c = Contact(99,first,second,phone)
pb.addContact(c)
# print contacts stored in phone book
print(pb)
else:
print("wrong choice..")
print("Thank you!")
Code As image:




Program output:

phone.txt file image
import sys class Contact: def __init__(self, id, firstName, lastName, phone): self.id = id self.firstName = firstName self.lastName = lastName self.phone = phone def str__(self): return 'Name: {} {}, Phone: {}'.format(self.firstName, self.lastName, self.phone) class PhoneBook: def __init__(self): self.contacts = [] def load_data(self): fname = "phone.txt" try: fileobj = open(fname, 'r') except IOError: print("Could not read file:", fname) return for line in fileobj: line = line.strip). entry = line.split("\t") if len(entry) == 4: # confirms a valid entry C = Contact(entry[0], entry[1], entry[2], entry[3]) self.contacts.append(c) def addContact(self, contact): self.contacts.append( contact) def getContact(self): return contacts def searchContact(self, id): for c in self.contacts: if c.id == id: return c return None def removeContact(self, id): c = self.searchContact(id) if c is None: return false self.contacts.remove(c) return True
def updateContact(self, id, firstName, lastName, phone): C = self.search Contact(id) if cis None: return false c.firstName = firstName c.lastName = lastName c. phone = phone return True def_str_(self): contacts = [str(c) for c in self.contacts] contacts.sort() return 'Phone Book contacts {}' .format('\n'.join(contacts)) pb = PhoneBook(); pb. load_data(); print(pb) def search_contact(word, by, choice): global pb fname = "phone.txt" try: fileobj = open(fname, 'r') except IOError: print("Could not read file:", fname) sys.exit() search_result = [] # set the index column of the data file #open file in read mode #fileobj = open("data.txt", "r") # read file line by line #for line in fileobj: sstr =". for rec in pb.contacts: print (rec) if by == 'f': sstr = rec. firstName elif by == 'l': sstr = rec.lastName elif by == 'p': sstr = rec. phone if sstr. lower() == word. lower(): search_result.append(rec)
#print (search_result) if(len( search result) > 0): print("ID\tFirst\tLast\tPhone") print("-"*60) for sin search_result: print(s.id+" "+ S. firstName+" "+ s.lastName+"\t"+ s.phone+"\n") print("-"*60) print("Total matching Record Found :", len(search_result)) print("Delete Contact(d) \nUpdate Contact(u)n\Back(b)") action = input("Enter your choice: ") if action == "d" or action == "u": action_id = int(input("Enter id of record please: ")) if action == "d": if pb.removeContact(action_id): print("Record deleted successfully") else: print("Error in deleting contact") if action == "d": first = input("Enter the First Name: ").strip(). second = input("Enter the Last Name: ").strip(). phone = input ("Enter the phone numbers separated by comma: ").strip() if pb.updateContact(self, id, firstName, lastName, phone): print("Record updated successfully") else: print("Error in updating contact") else: print("No record found")
print("Welcome to phone book application") # Show menu in loop while (True): print("Add Contact(a)") print("Search Contact(s)") print("Quit(q)") #store the user choice choice = input("Enter your option: ").strip().lower(). if choice not in ('a', 's', 'q'): print("Invalid option. Try again!") else: if choice == 'g': break elif choice == 's': print("Which field to search?") print("First Name (f) \nLast Name (1) \nor phone (p) \n") by = input("Enter your choice: ").strip().lower(). #if by not in ('f', 'l', 'p'): word = input("Enter your search word please: ").strip() search_contact(word, by, choice) elif choice == 'a': first = input("Enter the First Name: ").strip(). second = input("Enter the Last Name:").strip) phone = input("Enter the phone numbers separated by comma: ").strip() c = Contact(99, first, secod, phone) pb.addContact(c) else: print("wrong choice..") print("Thank you!")
input Phone Book contacts Name: Garry Potter, Phone: 1234566,1234576,1234533 Name: Harry Potter, Phone: 1234567,1234577,1234534 Welcome to phone book application Add Contact(a) Search Contact(s) Quit(a) Enter your option: S Which field to search? First Name (f) Last Name (1) Or phone (p) Enter your choice: 1 Enter your search word please: potter Name: Harry Potter, Phone: 1234567,1234577,1234534 Name: Garry Potter, Phone: 1234566,1234576,1234533 ID First Last Phone 1 Harry Potter 1234567,1234577,1234534 Garry Potter 1234566,1234576,1234533 Total matching Record Found : 2 Delete Contact(d)
main.py phone.txt 1 1 Harry Potter 2 2 Garry Potter : 1234567,1234577,1234534 1234566,1234576,1234533
Design and implement a simple phone book application that stores and manipulates contacts and their phone...
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....
Phonebook. You want to have a phone book that allows you to manipulate Contacts. A contact is made up of First Name, Last Name, Phone, Address, Birthday Date. (On java) Options: 1. Set number of contacts to store 2. Enter contact 3. Show entered contacts 4. Sort by last name 5. Sort by birthday day 6. Exit
write a ContactBook in C++ ContactBook that holds 10 names with that names corresponding contact (last name and first name of the owner). Ask the user to input up to 10 Contacts (It may be less. The user should have the ability to stop inputting Contacts whenever he wishes). 3.This class will store a list of Contacts in a stack allocated array of default capacity 10. 4.You must be able to add new contacts to a list, delete old contacts,...
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...
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...
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...
I need help with this Java program: ** Note, the main function should be in its own class. The application simulates a mobile phone with a Contacts application. The mobile phone must be able to store, modify, query, and remove contact names. The Contacts class will contain the name. phone number, and email of contacts. Use composition to demonstrate the Mobile Phone class to contains an array of Contacts. The Mobile Phone class should provide a menu of options to...
You should implement several functions that the Phone Contacts program will need Each function with take in data through the parameters (i.e., variables names listed in parentheses) and make updates to data structure that holds the contact information, return, or print information for a particular contact. The parameters needed are listed in the table below and each function is described below that 1. Make an empty dictionary and call it 'contacts'. Where in your code would you implement this? Think...
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...
This assignment is about creating the Rolodex application that contains the contact information. Each contact information includes: First name Last name Middle name (optional) Phone number The Rolodex application will use SharedPreferences for data persistent operations: Retrieve Rolodex records Add a new Rolodex record Update the existing Rolodex record Delete the selected Rolodex record The Rolodex application uses Fragment and DialogFragment. In addition, the Rolodex records are displayed in the ListView view. The ListView view is set to be single-selection...