Write a program stored in a file named rain

Assignment Help Database Management System
Reference no: EM131184719

Assignment

1. Rain

Write a program, stored in a file named rain.py, that performs the following task.

• The program prompts the user to input a file name. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

• The program prompts the user to input a nonnegative integer. If the input is not a nonnegative integer, then the program outputs an (arbitrary) error message and exits.

• The contents of the file consists of some number of lines, each line being a sequence of the same number of nonnegative integers separated by at least one space, with possibly spaces before and after the first and last number, respectively. These numbers represent the height in centimetres of a block with a square base of 10 square centimetres. For instance, the contents of the file land.txt can be represented as

2

2

2

2

2

1

3

4

3

2

2

3

5

3

2

2

4

1

1

2

and would represent a land covering an area of 50 centimetres by 40 centimetres, with a block of height 2 centimetres in each corner, etc. The number input by the user represents a quantity of rain in decilitres, to be poured down on the land.

• The program outputs the height in centimetres, with a precision of 2 digits after the decimal point, that is reached by the water.

Here is a possible interaction:

$cat land.txt
2 2 2 2 2
1 3 4 3 2
2 3 5 3 2
2 4 1 1 2
$python3 rain.py

Which data file do you want to use?land.txt

How many decilitres of water do you want to poor down?1 The water rises to 1.33 centimetres.

$ $ python3 rain.py

Which data file do you want to use? $land.txt

How many decilitres of water do you want to poor down?33 The water rises to 4.00 centimetres.

$ $ python3 rain.py

Which data file do you want to use? $land.txt

How many decilitres of water do you want to poor down?50 The water rises to 4.89 centimetres.

You can assume that the contents of any test file is as expected, you do not have to check that it is as expected.

2. Triangle

Write a program, stored in a file named triangle.py, that performs the following task.

• The program prompts the user to input a file name. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

• The contents of the file consists of some number of lines, each line being a sequence of integers separated by at least one space, with possibly spaces before and after the first and last number, respectively, the N th line having exactly N numbers. For instance, the contents of the file triangle_1.txt can be displayed as follows.

• The program outputs:

1165_Triangle.jpg

- the largest value than can be obtained by summing up all numbers on a path that starts from the top of the triangle, and at every level down to the penultimate level, goes down to the immediate left or right neighbour;

- the number of paths that yield this largest value;

- the leftmost such path, in the form of a list.

Here is a possible interaction:

$cat triangle_1.txt

2064_Triangle1.jpg

$python3 triangle.py

Which data file do you want to use?triangle_1.txt The largest sum is: 30

The number of paths yielding this sum is: 1

The leftmost path yielding this sum is: [7, 3, 8, 7, 5]

$cat triangle_2.txt

1932_Triangle2.jpg

$python3 triangle.py

Which data file do you want to use?triangle_2.txt The largest sum is: 10

The number of paths yielding this sum is: 6

The leftmost path yielding this sum is: [1, 2, 1, 2, 2, 2]

You can assume that the contents of any test file is as expected, you do not have to check that it is as expected.

3. Fishing towns

Write a program, stored in a file named fish.py, that performs the following task.

• The program prompts the user to input a file name. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

• The contents of the file consists of some number of lines, each line being a sequence of two nonnegative integers separated by at least one space, with possibly spaces before and after the first and second number, respectively, the first numbers listed from the first line to the last line forming a strictly increasing sequence. The first number represents the distance (say in kilometres) from a point on the coast to a fishing town further down the coast (so the towns are listed as if we were driving down the coast from some fixed point); the second number represents the quantity (say in kilos) of fish that has been caught during the early hours of the day by that town's fishermen. For instance, the contents of the file coast_1.txt can be displayed as

5 70
15 100
1200 20

which corresponds to the case where we have 3 towns, one situated 5 km south the point, a second one situated 15 km south the point, and a third one situated 1200 km south the point, with 70, 100 and 20 kilos of fish being caught by those town's fishermen, respectively.

• The aim is to maximise the quantity of fish available in all towns (the same in all towns) by possibly transporting fish from one town to another one, but unfortunately losing x kilos of fish per kilometre. For instance, if one decides to send 20 kilos of fish from the second town to the first one, then the second town ends up having 100-20 = 80 kilos of fish, whereas the first one ends up having 70+20-(15-5) = 80 kilos of fish too.

• The program outputs that maximum quantity of fish that all towns can have by possibly transporting fish in an optimal way.

Here is a possible interaction:

$cat coast_1.txt 5 70

15 100
1200 20

$python3 fish.py

Which data file do you want to use?coast_1.txt

The maximum quantity of fish that each town can have is 20.

$cat coast_2.txt 20 300

40 400
340 700
360 600

$python3 fish.py

Which data file do you want to use?coast_2.txt

The maximum quantity of fish that each town can have is 415.

You can assume that the contents of any test file is as expected, you do not have to check that it is as expected.

4. Partial orders

Write a program, stored in a file named nonredundant.py, that performs the following task.

• The program prompts the user to input a file name. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits.

• The contents of the file consists of lines with text of the form R(m,n) where m and n are integers (that just represent labels), with possibly spaces before and after the opening and closing parentheses, respectively. It represents a partial order relation R (so an asymmetric and transitive binary relation). For instance, the contents of the file partial_order.txt can be represented as:

884_State Diagram.jpg

It can be seen that two facts are redundant:

- the fact R(3, 1), which follows from the facts R(3, 5), R(5, 2) and R(2, 1);
- fhe fact R(4, 1), which follows from the facts R(4, 2) and R(2, 1).

• The program outputs the facts that are nonredundant, respecting the order in which they are listed in the file.

Here is a possible interaction:

$cat partial_order.txt R(3,5)

R(4,2)
R(5,2)
R(2,1)
R(3,1)
R(4,1)

$python3 nonredundant.py

Which data file do you want to use?partial_order.txt The nonredundant facts are:

R(3,5)
R(4,2)
R(5,2)
R(2,1)

You can assume that the contents of any test file is as expected, you do not have to check that it is as expected.

Attachment:- DSA_Assignment.rar

Reference no: EM131184719

Questions Cloud

What does a large audience add to your experience : Analyze and describe, in 525 words, responses to the following: What are the sounds and smells? What does a large audience add to your experience? Are there distractions
Describe write-through and write-back cache modification : Describe write-through and write-back cache modification as they are used in shared memory systems, and the advantages and disadvantages of both approaches.
How does our consumeristic society impact our approach : Evaluate/Assess your own enactment of Internet friendship, or that of someone you know (child, friend). Do you primarily use the Internet to collect new friends, maintain your friendships, or both? Apply ethical considerations regarding the inters..
What diagnostic possibilities does ben case present : What diagnostic possibilities does Ben's case present? (Must be diagnostic possibilities from DSM-5) and What have you read in the case history so far that presents these possibilities for you
Write a program stored in a file named rain : Write a program, stored in a file named rain.py, that performs the following task. If there is no file with that name in the working directory, then the program outputs an (arbitrary) error message and exits.
Draw a plot of the target impedance versus frequency : What is the minimum value for each of the individual decoupling capacitors?
Find the geometric means of the run times : Verify that the ratios of the means are consistent with the results obtained using the other two systems as reference systems.
Find exercise suggestions for an elderly patient : Using the website, find exercise suggestions for an elderly patient who wants to stay active or become more active. Give examples of types of moderate-intensity aerobic activity, muscle strengthening activities
What are the limitations of synthetic benchmarks : What are the limitations of synthetic benchmarks such as Whetstone and Dhrystone? Do you think that the concept of a synthetic benchmark could be extended to overcome these limitations? Explain your answer.

Reviews

Write a Review

 

Database Management System Questions & Answers

  Decompose the table into a set of 3nf tables.

Draw a dependence diagram. There are examples in the reading assignments of dependence diagrams.

  Database distribution strategy

Database Distribution Strategy. For this assignment, you will design and develop a distributed database infrastructure for an organization of your choice. You may use the database you created in another unit or you may choose to create a new datab..

  Explain efficient algorithm for edge-labeled graph

Explain efficient algorithm that, provided edge-labeled graph G with distinguished vertex v0 and sequence s = σ1, σ2, ..., σk of characters from Σ, returns path in G which begins at v0.

  Database for a library of a university

Each book has different ID (also each book of same name and same author (but number of copies) will have different ID), author name and any additional information you think it is important

  What does the resulting relation schema look like

Show the FDs in this resulting relation. Is it in 2NF Is it in 3NF? Why or why not? (State assumptions, if you make any.)

  What type of data model used in marts to improve performance

Where can sub queries be placed in a SQL select statement? What tables are good candidates for indexes and what type of indexes would you place on those tables? What type of data model is used in data marts to improve performance?

  Develop conceptual data model diagram

To develop a conceptual data model diagram and to perform logical design and Development Plan applications (here after called as application) that have been received during the previous month from the developers/ owners of the plots under the counc..

  Which object would you use to enter, delete, or modify data

Which object would you use to enter, delete, or modify data. Which object would you use to retrieve customers who live in Germany and the United States

  Describe the values of the two business intelligence tools

Estimate the costs and describe the values of the two business intelligence tools you have identified from Part 1 of this discussion based on their functionality, integrating architecture, and benefits to the enterprise. Provide your rationale

  Practice of optimizing table structures

Database normalization can principally be cleared as the practice of optimizing table structures. Optimization is adapted as a result of a thorough investigation of the numerous parts of data that will be stored within the database.

  The basic mechanisms for accessing relational database

Describe the basic mechanisms for accessing relational databases from various types of application development environments.

  What is the role of a dbms

What is the role of a DBMS, and what are it advantages? What are its disadvantages?

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