Create a list of three paramter field values and append it

Assignment Help Database Management System
Reference no: EM131054307

Database Assignment

Overview: We will create a basic database program.

Much of this assignment is conceptually similar to the earthquake example; look at that code (in the in-class examples) for guidance.

The earthquake example required a more complicated input, two splits were necessary. Only one split is needed for this assignment.

Description: Databases contain records. Each record contains information about an item. Each piece of information in a record is called a field.

You may choose the type of information you would like your database to store.

There must be at least three pieces of information stored for each record, you may store more.

Some possible databases are:

Phonebook:

Last name

First name

Phone number

Library:

Book title

Author

Subject/Category

Music:

Song title

Performer

Album

Other:

...

...

...

The description will be in terms of the Phonebook, make appropriate adjustments if you do something different.

Phonebook sample_data.

The program is comprised of 3 files (see below also):

1. database.py - The provided file. You may adjust this according to your database details if you want.

2. database_mod.py - The file that contains the functions you write. Put your functions in the file database_mod.py.

3. database.txt - The file that contains the phonebook data. Put your functions in the file database_mod.py.

The provided database program file:

database.py

When run the program will provide the user with a menu from which to choose an operation, carry out the selected operation, and repeat. The operations are:

• Look up a record by the last name
• Look up a record by the first name
• Look up a record by the phone number
• Output all records formatted nicely
• Add a record.

Also:

• When run the program will automatically load the data from a file.

• When done the program will automatically save the data to a file.

Development: Details for each function is provided in the next section.

In software development it is a good idea to get a simple version working that has rudimentary functionality, and then add functionality incrementally until the program performs as required.

Develop your program using the following steps.

1. Copy the contents of the provided database start file. You may adjust it as appropriate to your database later.

2. Get the provided file to execute without error.

Do this by adding a stub for each function in the

database_mod.py file.

A stub is a function definition that does simply outputs a message and/or returns a value.

For example:

def open_db(file_name):

print('open_db called', file_name)

With the print for each stub also print the value of each parameter.

As you add stubs for other functions and run your program you can see the values sent from the call to the definition on each call. The first value for the remaining calls will be None bacause the open_db function returns None by default.

Once you have stubs for each function that is called in the provided main function (except show_menu, the definition for it is provided) you can run the program without error.

Run your program, if you have not done so already. The program should run at this point but of course it will not bahave correctly because the functions do not do what they need to yet.

If there is an error message about a missing function you missed one, write a stub for the missing function and run the program again.

3. Implement a preliminary version of the open_db that simply inputs lines and ouputs the line that was input.

Run your program. You should see lines from your input file outputted.

4. Remove the print's from open_db.

Store the the lines that were input in the list, and return the list.

Look at the File I/O in the earthquake in-class examples.

Run your program. Since there is no way to get output yet it is hard to tell if the program is inputting correctly.

5. Implement the output_all method.

Initially the function should simply output each item in the db list.

Run your program, observe the outputted list.

You now know that the program is inputting from the file and that the list has the lines of the file in it.

6. Have the open db split each line on whatever splitter character you are using (the sample data above used a colon to separate the fields).

Use the strip on each of the values from the split.

Put the result of the split in the list that is returned so that the returned list is a list of lists.

Run your program, observe the outputted list is now a list of lists.

Get this to work.

You now have a good start.

7. Get the output_all function to work correctly

8. Implement the remaining functions.

The Functions: The program will contain the following (or similar) functions:

1. open_db(file_name)

Summary: This function opens the database and loads the data from a file.

Parameters:

• file_name - The name of the file that will be opened.

Return: Return the result list.

Implementation Notes:

This function, when complete, should:

• Open the file whose name is given in the parameter variable

• Create an empty result list

• Input each line from the file (use a loop)

• Use split on the line

• Use the strip method on each field. For example:

record[0] = record[0].strip()

This will remove leading and trailing whitespace so the

• comparisons in the search functions will work correctly. Append the list you get from the split to the result list

• When done inputting the file (after the loop) close the file and return the result list.

2. output_all(db)

Summary: This function outputs all data of the database in a nicely formatted manner

Parameters:

• db - The "database", the list of lists.

Return: No return is needed.

Implementation Notes:

• Use a loop to go through the db list and call the

output_record function.

3. output_record(db, idx)

Summary: This function outputs a single database record. This function is used so that output is consistent. It is also called in the provided code.

Parameters:

• db - The "database", the list of lists.

• idx - The index of the record to be output.

Return: No return is needed.

Implementation Notes:

• Output the item from the database list db at the given index.

• Use string formatting (the % formatting operator).

4. lookup_last_name(db, name)

Summary: Search the database for the given name.

Parameters:

• db - The "database", the list of lists.

• name - The name to search for.

Return: The index where the item was found. Return None if not found.

Implementation Notes:

• Search the database list, db, for the name in the parameter name. (Use a loop.)

• The search must be case insensitive. If the user enters a string that differs only in case then a match should be found.

5. lookup_first_name(db, name)

Summary: Search the database for the given name.

Parameters:

• db - The "database", the list of lists.

• name - The name to search for.

Return: The index where the item was found. Return None if not found.

Implementation Notes:

• Search the database list, db, for the name in the parameter name. (Use a loop.)

• This function is similar to the first search function, the difference is it is comparing the parameter value to a different item in the sub-list.

• The search must be case insensitive. If the user enters a string that differs only in case then a match should be found.

6. lookup_number(db, number)

Summary: Search the database for the given number.

Parameters:

• db - The "database", the list of lists.

• number - The number to search for.

Return: The index where the item was found. Return None if not found.

Implementation Notes:

• Search the database list, db, for the number in the parameter number. (Use a loop.)

• This function is similar to the first search function, the difference is it is comparing the parameter value to a different item in the sub-list.

• Note that the number is a string so it may have dashes in it if desired.

• The search must be case insensitive. If the user enters a string that differs only in case then a match should be found.

7. add_record(db, first_name, last_name, number)

Summary: Add a record to the database

Parameters:

• db - The "database", the list of lists.
• first_name - The first name for the record.
• last_name - The last name for the record.
• number - The number for the record.

Return: No return is needed.

Implementation Notes:

• Create a list of the three paramter field values and append it to the db list.

8. close_db(db, file_name)

Summary: This function saves the contents to a file, the same file that the open_db opens and reads from when the program starts.

Parameters:

• db - The "database", the list of lists.

• file_name - The name of the file that will be opened.

Return: No return is needed.

Implementation Notes:

• Open the file specified by the parameter file_name.
• Use a loop to output each database item to the file.
• Output the field separator also.
• When done outputing to the file (after the loop) close the file.

Make a backup copy of your input file.

When a file is opened for writing/saving its previous contents are erased. If your program fails after this the orginal contents will be lost. If you have a backup of the data (phonebook) file you can copy it in and save some typing in recreating the original data file.

Reference no: EM131054307

Questions Cloud

Average americans eat less fiber than is recommended : Why do you think average Americans eat less fiber than is recommended? What are some potential problems with a long-term low fiber intake? What good advice would you give someone about a practical way to increase fiber intake?
Recent events in the us airways and american airlines merger : Given the recent events in the US Airways and American Airlines merger, one has to wonder, is the airline industry monopolistic? Which is worse, monopolies or competition? Explain your answer.
Contribute to the overall meaning of the poem : Choose one poem from among this week's assigned readings except "The Chimney Sweeper," which was used as an example in this week's lecture. Post a response of at least 150 words.
Types of adjectives in english : There are at least two types of adjectives in English in terms of complement selection. Explain.
Create a list of three paramter field values and append it : Create a list of the three paramter field values and append it to the db list. The search must be case insensitive. If the user enters a string that differs only in case then a match should be found.
Persuade or conivence someone of your position : Persuasive essay is to persuade or conivence someone of your position, you must present strong reasons and evidence. The essay should be 5 paragraphs, and you should include in each of the three body paragraphs statistics, facts, expert opinion a..
Second main point-gain career development : Construct supporting paragraph that contains a topic sentence that shows main topic of the paragraph, supporting sentence that has details, facts and examples to support the main topic and a closing sentence that concludes the paragraph by restati..
What are you going to do to address your challenges : What is your position and what are you required to accomplish? What you are working on currently? What are your current challenges?
Write two thesis statements a simple thesis : In Week One, we studied the "thesis statement. " This assignment will test your ability to write thesis statements in the two forms (simple and oppositional) introduced in the Thesis Review handout.

Reviews

Write a Review

 

Database Management System Questions & Answers

  Activity-based costing approach

Compute the predetermined overhead rate under the current method, and determine the unit product cost of each product for the current year.

  Modify the structure of the payment table

PLUS also creates videos, animations, presentation packages, and slide shows-in short, anything of a visual nature that can be used in a judicial proceeding to make, clarify, or support a point.

  Data security and data integrity

There are six problems that can be minimized by using the database approach: Data redundancy, Data isolation, Data inconsistency and Data security

  Increase all employees'' salaries by 5%.

Choose a job_title_code in the job_title table. Increase the Minimum_salary and Maximum_salary for this job_title_code.

  Conduct a search online for tutorials about normalization

Conduct a search online for tutorials about normalization. Choose three tutorials that you think best teach you about normalization.

  Create data file grades with records of the form

Input names of students from the user, terminated by ZZZ, and create a data file GRADES with records of the form.

  Analyze how the data breach could have been prevented

Analyze how the data breach could have been prevented with better adherence to and compliance with regulatory requirements and guidelines, including management controls; include an explanation of the regulatory requirement (such as from FISMA, HIP..

  How linked data can be used in semantic web applications

Explain how linked data can be used in semantic web applications and give suggestions forhow linked data might be used with the representations you have created

  Torri manufacturing corporation -determine unit product cost

Determine the unit product cost of each of the company's two products under the traditional costing system

  Create an entity-relationship diagram

create an entity-relationship diagram (ERD) from the entity and attributes list for the database project you selected similar to what you did in the Discussion Board this week. Your submission should ensure the following

  Modify the database by adding an additional column

Modify the database by adding an additional column ("Deleted_Date") to those tables that represent entities that could contain data which can be deleted and justify your rationale in a short paragraph.

  Exchange commission edgar database

Select a publicly traded corporation for which you would like to work or are currently working. Research the corporation on its own Website, the public filings on the Securities and Exchange Commission EDGAR database and any other sources you can ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd