Ask DBMS Expert


Home >> DBMS

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

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M91940819

Have any Question?


Related Questions in DBMS

Data mining assignment -in this assignment you are asked to

Data Mining Assignment - In this assignment you are asked to explore the use of neural networks for classification and numeric prediction. You are also asked to carry out a data mining investigation on a real-world data ...

Sql query assignment -for this assignment you are to write

SQL Query Assignment - For this assignment you are to write your answers in a word document. This assignment is in three parts: Part A (reporting queries), Part B (query performance), Part C (query design). For this assi ...

The groceries datasetimagine 10000 receipts sitting on your

The groceries Dataset Imagine 10000 receipts sitting on your table. Each receipt represents a transaction with items that were purchased. The receipt is a representation of stuff that went into a customer's basket. That ...

You are in a real estate business renting apartments to

You are in a real estate business renting apartments to customers. Your job is to define an appropriate schema using SQL DDL in MySQL. The relations are Property(Id, Address, NumberOfUnits), Unit(ApartmentNumber, Propert ...

Objectivethe objective of this lab is to be familiar with a

OBJECTIVE: The objective of this lab is to be familiar with a process in big data modeling. You're required to produce three big data models using the MS PowerPoint software. This tool is available on UMUC Virtual Deskto ...

The relation memberstudentid organizationid roleid stores

The relation Member(StudentId, OrganizationId, RoleId) stores the membership information of student joining organization. For example, ('S1', 'O2', 'R3') indicates that student with Id 'S1' joined the organization with i ...

Relational database exerciseyou have been assigned to a new

Relational Database Exercise: You have been assigned to a new development team. A client is requesting a relational database system to manage their present store with the anticipation of adding more stores in the future. ...

Relational database design a given the following business

Relational Database Design A) Given the following business rules, identify entity types, attributes (at least two attributes for each entity, including the primary key) and relationships, and then draw an Entity-Relation ...

We can represent a data set as a collection of object nodes

We can represent a data set as a collection of object nodes and a collection of attribute nodes, where there is a link between each object and each attribute, and where the weight of that link is the value of the object ...

Data model development and implementationpurpose of the

Data model development and implementation Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop data models and map Database System into a standard development environment to gain unde ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As