Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program which uses the capabilities of shelved objects. The program will maintain a telephone database. The commands to use the database are as

Write a program which uses the capabilities of shelved objects. The program will maintain a telephone database. The commands to use the database are as follows:

image text in transcribed

image text in transcribed

2. Write a program which uses the capabilities of shelved objects. The program will maintain a telephone database. The commands to use the database are as follows . 'whois phone-number' Find the information associated with a phone number 'add phone-number information' Add information to a phone number listing in the database . 'search keyword' Find all entries which include keyword . quit' Exit the application. some valid commands: a) add 2162215680 Fred Smith b) add 2063607788 Roberta Flores c) quit subsequent sessions might be: . a) whois 2162215680 b) search Flores c) search fred d) add 2162215680 Owes me $50 e) Quit commands are read in as strings and the line is parsed into command and arguments cscCSenesters CSCT 15111Projects Tel onsands are hois,add, search and quit :Python32 python.exe telefonedb.py onmand: add 345 Teddy Richter 678 Alice Carswell conmand: add 678 1ives in Cleveland, OH comsand: whos 578 : Alice car swell lives in Cleveland, a 678Alice Carswl ives in Cleveland, oH Teddy Richter lives in Canton, OH onsand: quit CSCCSenesters CSCI 15111Projects TelephoneDatabase dir Volume Serial Nunber is G035-33FB Directory of ECSCC,Senesters\CSCI 1511\Projects TelephoneDatabase 10/07 /2012 11:22 PM DIR 10/07/2012 11:22 PM OIR 10/07/2012 11:22 PM 34 phon infe.bak 62 phoneinfo.dat 34 phoneinto.dir 1, 292 tel "fanedb . 10/07 /2012 11:22PM 10/07/2012 11:07 PM 4 File(s) 2 Dir(s) ss) 980.813 ,9829240byttes free csCCSenesters CSct 1511\projects TelephoneDatabases Telephone Database Example 1 Psuedo Code import shelve main) try: ##open a shelved object except IOError: ## If there are problems opening that shelved name else: ## continue if successful phoneDB-shelve.open("SomeName") print() ## some error ## print the menu specified above as to the possible commands ## prompt user for command cmd input("Command: ") ## If the command is not 'quit' while cmd !-"quit" ## use the string split method to parse out the command words - cmd.split) ## get the operating command, the first word if words[0]'whois' try: ##just a non-specified block print(words[1], phoneDB[words[1]]) except: print an error elif words[0] ='add' ##use the get() function or the has-key() function ## for all the words in words from [21 add to the end of the ## value for that key tmpData - phoneDB.get(words[1], ">") for w in words[2:] tmpData tmpData""w phoneDB[words[1]] tmpData elif words[0] ='search': for w in phoneDB.keys() if phoneDB[w].find(words[1 ) >= 0: print(w, phoneDB[w]) else ## just print that there is no command by that name ##get another command cmd input("Command: ") close phoneDB return 2. Write a program which uses the capabilities of shelved objects. The program will maintain a telephone database. The commands to use the database are as follows . 'whois phone-number' Find the information associated with a phone number 'add phone-number information' Add information to a phone number listing in the database . 'search keyword' Find all entries which include keyword . quit' Exit the application. some valid commands: a) add 2162215680 Fred Smith b) add 2063607788 Roberta Flores c) quit subsequent sessions might be: . a) whois 2162215680 b) search Flores c) search fred d) add 2162215680 Owes me $50 e) Quit commands are read in as strings and the line is parsed into command and arguments cscCSenesters CSCT 15111Projects Tel onsands are hois,add, search and quit :Python32 python.exe telefonedb.py onmand: add 345 Teddy Richter 678 Alice Carswell conmand: add 678 1ives in Cleveland, OH comsand: whos 578 : Alice car swell lives in Cleveland, a 678Alice Carswl ives in Cleveland, oH Teddy Richter lives in Canton, OH onsand: quit CSCCSenesters CSCI 15111Projects TelephoneDatabase dir Volume Serial Nunber is G035-33FB Directory of ECSCC,Senesters\CSCI 1511\Projects TelephoneDatabase 10/07 /2012 11:22 PM DIR 10/07/2012 11:22 PM OIR 10/07/2012 11:22 PM 34 phon infe.bak 62 phoneinfo.dat 34 phoneinto.dir 1, 292 tel "fanedb . 10/07 /2012 11:22PM 10/07/2012 11:07 PM 4 File(s) 2 Dir(s) ss) 980.813 ,9829240byttes free csCCSenesters CSct 1511\projects TelephoneDatabases Telephone Database Example 1 Psuedo Code import shelve main) try: ##open a shelved object except IOError: ## If there are problems opening that shelved name else: ## continue if successful phoneDB-shelve.open("SomeName") print() ## some error ## print the menu specified above as to the possible commands ## prompt user for command cmd input("Command: ") ## If the command is not 'quit' while cmd !-"quit" ## use the string split method to parse out the command words - cmd.split) ## get the operating command, the first word if words[0]'whois' try: ##just a non-specified block print(words[1], phoneDB[words[1]]) except: print an error elif words[0] ='add' ##use the get() function or the has-key() function ## for all the words in words from [21 add to the end of the ## value for that key tmpData - phoneDB.get(words[1], ">") for w in words[2:] tmpData tmpData""w phoneDB[words[1]] tmpData elif words[0] ='search': for w in phoneDB.keys() if phoneDB[w].find(words[1 ) >= 0: print(w, phoneDB[w]) else ## just print that there is no command by that name ##get another command cmd input("Command: ") close phoneDB return

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions