Question

A cell phone has the ability to save contact information. In this assignment, you will simulate...

  • A cell phone has the ability to save contact information. In this assignment, you will simulate the contact list for a very simple cell phone.
  • Download lab8.py below, rename it according to the instructions above, and make sure you understand it.
  • Take the program above and modify it by adding the missing Contact class such that when the program is run, it produces this output.
  • Hint: for help on formatting output, revisit the online textbook's chapter 9.5.1

Grading - 10 points

  • 2 points - The constructor of the Contact class is correct.
  • 2 points - The reader methods of the Contact class are correct.
  • 2 points - The writer methods of the Contact class are correct.
  • 2 points - The print_entry method of the Contact class is correct.
  • 2 points - Your program's output matches the output format of the transcript above (1 point for each type of difference up to 2 points).

This is the provided lab8.py:

# -----------------------------------------------------
# CSCI 127, Lab 8
# March 12, 2020
# Your Name
# -----------------------------------------------------

# Your solution goes here...

  
# -----------------------------------------------------
# Do not change anything below this line
# -----------------------------------------------------

def print_directory(contacts):
print("MSU Contacts:")
print("----------------------------------------")
for person in contacts:
person.print_entry()
print("----------------------------------------\n")

# -----------------------------------------------------

def main():
  
prof_892 = MSUContact("first1", "last1", "###-###-####")
mascot = MSUContact("first2", "last2", "###-###-####")
director_CS = MSUContact("first3", "last3", "###-###-####")
president = MSUContact("first4", "last4", "###-###-####")
  
contacts = [prof_892, mascot, director_CS, president]
print_directory(contacts)

mascot.set_first_name("Champ")
  
prof_892.set_title("Instuctor")
director_CS.set_title("Director")
president.set_title("President")

print_directory(contacts)
  
contact = prof_892
print(contact.get_first_name() + "'s MSU phone line is", \
contact.get_line_number())

# -----------------------------------------------------

main()

This is the provided output, with numbers altered, but formatted the same:

MSU Contacts:
----------------------------------------
first1 last1                ###-###-####
first2 last2                ###-###-####
first3 last3                ###-###-####
first4 last4                ###-###-####
----------------------------------------

MSU Contacts:
----------------------------------------
Instuctor first1 last1      ###-###-####
Champ Bobcat                ###-###-####
Director first3 last3       ###-###-####
President first4 last4      ###-###-####
----------------------------------------

first1's MSU phone line is ####

In censorship of names and numbers, I hope the intent of the code was not lost. I need to create a class of some sort to create the intended output.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per given question description, here is the required source code for solution in text and image format:

Text:

class MSUContact:
def __init__(self,fname,lname,number):
self.fname = fname
self.lname = lname
self.number = number
self.title = None

def set_first_name(self,fname):
self.fname=fname
  
def set_title(self,title):
self.title = title
  
def print_entry(self):
if self.title==None:
print(self.fname+" "+self.lname+"\t"+self.number)
else:
print(self.title+" "+self.fname+" "+self.lname+"\t"+self.number)
  
def get_first_name(self):
return self.fname

def get_line_number(self):
return self.number
  
def print_directory(contacts):
print("MSU Contacts:")
print("----------------------------------------")
for person in contacts:
person.print_entry()
print("----------------------------------------\n")

def main():
prof_892 = MSUContact("first1", "last1", "###-###-####")
mascot = MSUContact("first2", "last2", "###-###-####")
director_CS = MSUContact("first3", "last3", "###-###-####")
president = MSUContact("first4", "last4", "###-###-####")
  
contacts = [prof_892, mascot, director_CS, president]
print_directory(contacts)
  
mascot.set_first_name("Champ")
  
prof_892.set_title("Instuctor")
director_CS.set_title("Director")
president.set_title("President")
  
print_directory(contacts)
  
contact = prof_892
print(contact.get_first_name() + "'s MSU phone line is", \
contact.get_line_number())

main()
  
Image:

Sample Output:

Add a comment
Know the answer?
Add Answer to:
A cell phone has the ability to save contact information. In this assignment, you will simulate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • This assignment was locked Mar 24 at 11:59pm. For this lab you will implement a phone...

    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...

  • C++ In this assignment, you will write a class that implements a contact book entry. For...

    C++ In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class. Your Contact...

  • This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of ...

    This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

  • linked list operation /*************************************************************************************** This function creates a new node with the information give as a...

    linked list operation /*************************************************************************************** This function creates a new node with the information give as a parameter and looks for the right place to insert it in order to keep the list organized ****************************************************************************************/ void insertNode(string first_name, string last_name, string phoneNumber) { ContactNode *newNode; ContactNode *nodePtr; ContactNode *previousNode = nullptr; newNode = new ContactNode; /***** assign new contact info to the new node here *****/ if (!head) // head points to nullptr meaning list is empty { head = newNode;...

  • My CSC 220 teacher has given this as a homework assignment and starting it has not...

    My CSC 220 teacher has given this as a homework assignment and starting it has not made much sense and am generally lost on this assignment help would be much appreciated. I put everything from the assignment power point slides she gave us in here so the expert has everything im working with as well. Dequeue Please implement your own Dequeue class which has following methods boolean add(E e)= void addLast(E e) void addFirst(E e) E getFirst( ) = E...

  • Part 1 The purpose of this part of the assignment is to give you practice in...

    Part 1 The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following member functions (details about each one are...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT