Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8:53 Back Hwrk06.pdf a Program6-15 through Program6-19 show the makings of a complete File Management System In Homework06, you will create a File Management System

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
8:53 Back Hwrk06.pdf a Program6-15 through Program6-19 show the makings of a complete File Management System In Homework06, you will create a File Management System that will monitor and control coffee inventory We will start off by demonstrating how to create the modules you will need by helping you do the first module. With Program6-15 we will do two things We will re-write Programb-15 as a Module called Lestnomefirstinitial coffee records.py esample, if me was Juan Valdethem for So your Module would have the We will create a driver program which will run this module called: YourName-Hwrk6 py .w" may want torefertoProgram S-38 as a sample of b-. nnises Modes. Program 6-15 Program 6-15 (add cofee record py) 2 the cottee.tat tile the loop- Program 6-15 Append the Appending records to a File. Program 6-15 Results Dashboard Calendar To Do Notifications Inbox Program Output (with input shown in bold) Enter the following coffee data: Description: Brazilian Dark Roast Quantity (in pounds) 18 Enter Do you want to enter another record? Yyes, anything else no: y Er Description: Sumatra Medium Roast Quantity (in pounda): 25 ter Do you want to enter another record? Y-yee, anything oise ne: n Cr Dats appended to coffee.txt Homework 06 Cont Now that we have one module, we are going to write the driver for this module: YourName-Hwrk06. Initially, this driver will just run this first module However, after you've got the first module working, you will be expanding this driver to include 4 additional modules. Below is the essence of the driving program which will run this File Management System to test and run the module LastnameFirstinitial coffee_ records.py YourName-Lab06 .py Nour Nome A Coffee Fle Management Pogram import Valdeal_coffee-records # Here's where we ingort the module that we just made. But it should have your ADD COFFLL CHOICE- stnamesnmitial Net valdez) Define Global constants for all your chaices del maind choice while thoice QUIT CHOICE choice intlirput'Enter your choice ADD COFFEE Valdeel_cenee_seceeds. add_coffeeO rindtmg the program .. prinError invalid selection. # we (all the bction add-comeedoruired in "roorted Modde LastnerefastintiuLeemee-records QUIT-CHOICE : def dsplay riJUAN WALDEZ COFFEE MANAGEMENT MIENU pine'1) Add more Coffee Choices to Lis pinet 6) Quit maing 8:53 Back Hwrk06.pdfa Once you have the first module up and running, now you will repeat what you did and add to the module, the second: Program 6-16, which contains the function show coffee) Then you will expand the driver program menu to include this additional module You will also import this module You will change the menu to include this module Once the second function is working, repeat the preceding 3 more times to include: Program 6-17, Program 6-18 and Program 6-19. From these three programs you will be adding the following program to accommodate these additi Program 6-16 iDisplaying all the records in a File. Program 6-17 allows the user to make search of a fle #Thi. To Do 8:53 Back Hwrk06.pdfa Once you have the first module up and running, now you will repeat what you did and add to the module, the second: Program 6-16, which contains the function show coffee) Then you will expand the driver program menu to include this additional module You will also import this module You will change the menu to include this module Once the second function is working, repeat the preceding 3 more times to include: Program 6-17, Program 6-18 and Program 6-19. From these three programs you will be adding the following program to accommodate these additi Program 6-16 iDisplaying all the records in a File. Program 6-17 allows the user to make search of a fle #Thi. To Do 8:54 Back Hwrk06.pdf Q Program 6-17 Program 6-18 Editing a File Strip the in write icher this recond to the cengorary Program 6-18 . Mtite the itid 0oard to the timp fila. a File cont. To Do 8:54 Back Hwrk06.pdf Q i Read the p file 4 Set the found fing to tr Program 6-19: Deleting a record from a file concluded ng tiie.close Homework 06 Concluded Here is what the Homework6 menu should look like. However, substitute your name for that of uan Vaildet dd more Coffee Choices to List Display all the Coffee Choices Search Coffee cChoices Modify Coffee Choices Delete a Coffee Choice nter your choice: To Do 5:28 K Back Hwrk06,pdf Q If we look closely at Program 6-15, we will notice that there are only two things that we must change if we wish to make it into a Module containing a function that we will use in the driver program. First we must change the name of the main function to another name. We will use the name: add_coffee() as the name of what was called main)- * The second thing we must do is to delete the very last line of this program ine 32, main()), as this module will not call this function, rather it will be the driver program which calls this function Once we have made these two changes, then the program which was labelled Program6-15, we will call module: Lastnomefirstinitial coffiee records.py, and it will contain a function, add coffee), that we will be using in the Driver program Program 6-15 (add coffee_record py) 1 This program adds coffee inventory records to 2 # th@ coffee. txt file 4 det nain) Create a variable to control the loop. another ' Opene coffee coffee tile open( coffee.txt. #Add records to the file 12 13 14 15 16 17 18 19 20 21 Get the coffee record data. print( Enter the folloving coffee datas"1 descr input ( Descriptions t Append the data to the file coffee file.write(descr' coffee file.writelatriqty) Appen Determine whether the user vants to add i another record to the file print Do you vant to add another reoord?") anotherInput( 'Y -yes, anything else 27 28 i Close the file. coffee_file.cloael) print( Data appended to coffee.txt 30 31 Call the main function Program 6-15 Results Dashboard Calendar To Do Notifications Inbox 5:28 Back Hwrk06.pdfa Program Output (with input shown in bold) Enter the folloving coffee data Description: Brazilian Dark Roast Quantity (in pounds) : 18r Do you want to enter another record2 xyes, anything else -nosy t Description: Sumatra Medium Roast Quantity (in pounds): 25 Do you want to enter another record? Y yes, anything else nos n Data appended to coftee.txt Homework 06 Cont. Now that we have one module, we are going to write the driver for this module: YourName-Hwrk06.py Initially, this driver will just run this first module. However, after you've got the first module working, you will be expanding this driver to include 4 additional modules. Below is the essence of the driving program which will run this File Management System to test and run the module LastnameFirstinitial coffee_records.py YourName-Lab06. nagement Program Calendar To Do Inbox 5:29 Back Hwrk06.pdf Q # Your Name # A Coffee File Management Program import Valdez)-coffee-records # Here's where we import th ADD COFFEE CHOICE 1 # Define Global constants fo # Which includes the choice QUIT_CHOICE 6 def main(): choice0 while choice!-QUIT_CHOICE: display menu() choice = int(input('Enter your choice:1) if choiceADD_COFFEE_CHOICE: Valdezl coffee recordsadd-coffee() print(Exiting the progra...) print('Error: invalid selection.') # We call the fun elif choice QUIT-CHOICE else: def display_menu0 print(JUAN VALDEZ COFFEE MANAGEMENT MENU) print'1) Add more Coffee Choices to List'T print(6) Quit') main() Home Once you have the first will repeat what you did Program 6-16, which co Then you will expand th this additional module Calendar To Do Inbox 5:29 Back Hwrk06.pdfa QUIT CHOICE linputfEnber your choice ADD COFFEE CHOE QUIT CHOICE ror: invalid selection VALDEZ COFFEE MANAGEMENT MENU more Coffee Choices to List Homework 06 Cont. Once you have the first module up and running, now you will repeat what you did and add to the module, the second Program 6-16, which contains the function show_coffee(). Then you will expand the driver program menu to include this additional module You will also import this module You will change the menu to indlude this module Once the second function is working, repeat the preceding 3 more times to include: Program 6-17, Program 6-18 and Program 6-19 From these three programs you will be adding the following functions to your module: LastnameFirstinitial coffee records search_coffee) modify_coffee) Modify your driver program to accommodate these additions progran dispiaye the oetfee.sxt ie Program 6-16 oed the EL Pcoreaerieion tinia. Displaying all the records i he tile quaity field. Calendar To Do Inbox 5:291 Back Hwrk06.pdfa Program 6-16 (show coffee, 1 This progran displays the records in the 2 coffee.txt file. 4 def sain): t Open the coffee.txt file. coffee file open( eoffee.tzt Read the fir t record's description field. descr coffee file.readline) 10 #Read the rest of the file hile deser 12 13 14 15 16 17 18 19 20 21 Read the quantsty seld. gty float(coffee file. readline)) # Strip the Vn from the description. descr descr.rstrip( La Display the record. print('Description:, descr) print 'Quantitysqty 23 24 25 26 27 28 29 Read the next description. descr coffee file.readline) l Close the file coffee tile.close Call the main function Program 6-1 This program allows the user to m Program 6-17 (search coffee_records.py) # This program allows the user to 2 coffee.txt file for records matc # description To Do Inbox 5:29 Back Hwrk06.pdfa This program allows the user to search the 2 coffee.txt file for records matching a 3 description. 5 def main) create a bool variable to use as a flag found -Palse t Get the search value 10 Bearchinput( 'Enter a description to search for: 12 13 14 15 16 17 18 # Open th@ coffee.txt file. coffee file open(coffee.txt Read the first record's deseription field. descr coffee file.readline) i Read the rest of the file Read the qoantity Eield. gey-float(eoftee file readlineD Strip the in fron the dencription. deser deser.rstript in Progra Determine vbether this record natches f the beareh value. Searc Dieplay the record. printl'Deseriptiom*deser) print('ouancitysqty) print) Set the found flag to Trve found Progran Output (wh input th descr- cotfee tile.readline) Close the fse. ga Output (with input eoftee file.elosetD * If the 0arets value was not found in th fil.e display Mssage print('7hst item was not found in thfile To Do Inbox 5:30 Back Hwrk06.pdfa Program 618 (modify c This progran allows the eser to modify the quantity 2in a record in the eoffee.txt file. 4 import os # Needed for the remove and renane functions 6 def main #create a bool variable to use as a flag found-Palse 10 Get the seareh value and the ev quantity search- input( 'Eater a desexiption to search for: nev qty float (input("Enter the neu quantity: 13 # open the original coffee.txt file. coffee tileopeal'coffee.txt" 16 17 Open the temporary file temp file open( temp.txt.) 19 Read the first record's deseription field. deser coffee file.readlinet) 21 t Read the rest of the file 24 25 26 27 28 t Read the quantity field. gty float(coffee file.readline0) # Strip the la fron the descriptio. deser deser.rstrip( Ln' 30 31 4 write either this record to the temporary fil i or the nev record if this is the one that is t to be nodified. if deserseazch: 35 36 write the modified record to the top fil temp-file-write(descr + *.) temp file.write(str(nev-gty) 38 set the found fla to true. found True To Do Inbox 5:30 Back Hwrk06.pdfa t to be nodified if descrsearch: 35 36 37 38 Write the modified record to the temp file tempt ile-write(descr + *ln') temp file.vrite(str(ev tya Set the found flag to True. found -True 41 # write the original record to the temp file temp file.vrite(descrn temp file.vrite(str(gty)+n 43 45 Read the next description. descr coffee file. readlileo ary ti 50 coffoe file.close) temp file.close( @ Delete the original coffee.txt tile. os. remove( coffee.txt Renane the temporary file. oa.rename( temp.txt. coffee.txt 57 If the earch value wan t found n the file 59 60 61 display a message if found: print( The file has been epdated. 63 else: print(That item vas not found in the file 65 66 Call the main function. 67 maia) Program Output (with input shown in bold Enter a deacription to aearch for: Brazillan Dark Roast Ene Enter the new quantity: 10 Tm The file has been updated Program 6-19: Deleting a Record from a File This progran allows the user to delete To Do Inbox 5:31 Back Hwrk06.pdf Q r a description to search fors Brazilian Dark Roast Entr r the new quantity: 10 Ee file has been updated Program 6-19: Deleting a Record from a File 1This progran allows the user to delete 2 t a record in the coffee.txt file. nport O@ Needed for the renovo and renan0 funetion8 Create a bool variable to use as &flag found-False # Get the coffee to delete. search-input("Which coffee do you vant to delete? 10 12 # open the original eottee.t ! ile. 14 coffee ile open('coffee.txt. 16 lOpen the tenporary file. tesp-file-open(.tesp.txt . , .v. 18 19 20 Read the firt record' description field. descr coffee file.readlinet) Program 6-19: Deleting a Record from a File Cont. #Road the rest of the file. while descr 23 24 25 26 27 28 29 30 31 32 Read the quantity field qty - float (coffee file.readline)) Strip the In from the description descrdescr.zstript La If this is not the record to delete, # write it to the terporary file if descr - search: #write the record to the temp file temp file.vrite(descra 34 Calendar To Do Inbox

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

11. Identify the stage of beyond duality in Gone With the Wind.

Answered: 1 week ago