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

  Design program that displays table of contigrade temperature

Design a program that displays a table of the contigrade temperatures 0 through 20 and their Fahenheit equivalents. The formula for converting a temperature from centigrade to Fahrenheit is.

  Logical entity relationship diagram

How can turn a conceptual entity relationship diagram into a logical entity relationship diagram

  Thread risk analysis and modeling process

Determine the threats and countermeasures for system components and determine the Threat Risks - Decompose the application. Create high level diagrams of system components

  What are the good/bad choices the first two rdb systems made

What is the key benefit provided by the relational model over previous data models?

  Condition on attribute rating in table

Write a CHECK constraint that expresses the following condition on attribute Rating in table Movies in Movie Database: "Any possible value of Rating is either a null value or a number in the interval from 0 to 10 inclusively".

  How many different orders are possible

How many different orders are possible if a customer can order at most one hamburger, one fish sandwich, and one beverage but can order less?

  1 define relation2 what is an instance3 define tuple4 what

1. define relation.2. what is an instance?3. define tuple.4. what is domain?5. what do you mean by data base scheme?6.

  Write down a 350-word summary explaining two of the most

write a 350-word summary describing two of the most popular database vendors in the marketplace. answer the following

  Baxter aviation database

ER diagram for the Baxter Aviation database

  Designing of database

a. Discuss the degree to which you believe the Visio diagram reflects the database design. b. Describe any assumptions that you had to make about the business rules to in order to create the Visio diagram and the associated relationships.

  Overview of business intelligence technology

Discuss connections, similarities, shared issues, discrepancies, possible combinations of problems and techniques from the three papers, etc. Whatever you consider relevant, but with reasons and referring to the papers if necessary.

  Create an e-r diagram of entities, attributes & relationship

Using the script file below to create an E-R diagram of the entities, attributes and relationship.

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