m reads one text file: – input.txt • Your program creates a text file: – output.txt • Your program solves the following problem: – You are given a water level information L. Condition: 0

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

• Your program reads one text file:
– input.txt
• Your program creates a text file:
– output.txt
• Your program solves the following problem:
– You are given a water level information L. Condition: 0<L<128.
– You are given a terrain information (elevation matrix M). Condition: 0M[i][j]<128 8i,j<512.
– Definition of an island: An island is the collection of terrain points( elevation values M[i][j]), above
water( greater than L value), from which you can find a path to any other without having to pass the
path through water.
– Definition of a path: A path is an ordered set of points where successive points have either their X
coordinates the same and their Y coordinates different only by one in magnitude (so can be y - 1 or y +
1); or have their Y coordinates the same and have their X coordinates different only by one in magnitude
(so can be x - 1 or x + 1). But not both of them: in other words they have to touch either in the X
direction or in the Y direction, and not in the diagonal.
– If a piece of terrain is partially (or fully) located (touching) at the edge(s) of the 512 × 512 grid, still it
will count as an island.
input.txt
• First line is a single integer. (The L value)
• The rest of the file has 262144 integers. Skip all the whitespace and read all of these integers and create a
512x512 matrix. Integers are listed in row-order.
output.txt
• Each line holds coordinate information of a point on an island. (single point for each island)
• Example: Here there are 5 islands. (#... are comments, which are not printed.)
x_coordinate1 y_coordinate1 #coordinate of a point which is on island1
x_coordinate2 y_coordinate2 #coordinate of a point which is on island2
x_coordinate3 y_coordinate3 #coordinate of a point which is on island3
x_coordinate4 y_coordinate4 #coordinate of a point which is on island4
x_coordinate5 y_coordinate5 #coordinate of a point which is on island5
Remarks
• There will be at most 100 islands.
• You can allocate only one array.(create an array for the terrain data).
• You cannot declare any other array in your program.

Your program reads one text file:
input.txt
• Your program creates a text file:
output.txt
• Your program solves the following problem:
- You are given a water level information L. Condition: 0<L<128.
- You are given a terrain information (elevation matrix M). Condition: 0<M[1] [j]<128 V1,j<512.
Definition of an 1sland: An island is the collection of terrain points( elevation values M[1] []), above
water( greater than L value), from which you can find a path to any other without having to pass the
path through water.
- Definition of a path: A path is an ordered set of points where successive points have either their X
coordinates the same and their Y coordinates different only by one in magnitude (so can be y - 1 or y +
1); or have their Y coordinates the same and have their X coordinates different only by one in magnitude
(so can be x - 1 or x + 1). But not both of them: in other words they have to touch either in the X
direction or in the Y direction, and not in the diagonal.
- If a piece of terrain is partially (or fully) located (touching) at the edge(s) of the 512 x 512 grid, still it
will count as an 1sland.
input.txt
• First line is a single integer. (The L value)
• The rest of the file has 262144 integers. Skip all the whitespace and read all of these integers and create a
512x512 matrix. Integers are listed in row-order.
putput.txt
• Each line holds coordinate information of a point on an island. (single point for each island)
• Example: Here there are 5 islands. (#... are comments, which are not printed.)
coordinate1 y_coordinatei
_coordinate2 y_coordinate2
_coordinate3 y_coordinate3
_coordinate4 y_coordinate4
coordinate5 y_coordinate5
#coordinate of a point which 1s on island1
#coordinate of a point which 1s on island2
#coordinate of a point which 1s on 1sland3
#coordinate of a point which 1s on 1sland4
#coordinate of a point which is on island5
Remarks
• There will be at most 100 islands.
You can allocate only one array.(create an array for the terrain data).
• You cannot declare any other array in your program.
1
You cannot use dynamic allocation.
Transcribed Image Text:Your program reads one text file: input.txt • Your program creates a text file: output.txt • Your program solves the following problem: - You are given a water level information L. Condition: 0<L<128. - You are given a terrain information (elevation matrix M). Condition: 0<M[1] [j]<128 V1,j<512. Definition of an 1sland: An island is the collection of terrain points( elevation values M[1] []), above water( greater than L value), from which you can find a path to any other without having to pass the path through water. - Definition of a path: A path is an ordered set of points where successive points have either their X coordinates the same and their Y coordinates different only by one in magnitude (so can be y - 1 or y + 1); or have their Y coordinates the same and have their X coordinates different only by one in magnitude (so can be x - 1 or x + 1). But not both of them: in other words they have to touch either in the X direction or in the Y direction, and not in the diagonal. - If a piece of terrain is partially (or fully) located (touching) at the edge(s) of the 512 x 512 grid, still it will count as an 1sland. input.txt • First line is a single integer. (The L value) • The rest of the file has 262144 integers. Skip all the whitespace and read all of these integers and create a 512x512 matrix. Integers are listed in row-order. putput.txt • Each line holds coordinate information of a point on an island. (single point for each island) • Example: Here there are 5 islands. (#... are comments, which are not printed.) coordinate1 y_coordinatei _coordinate2 y_coordinate2 _coordinate3 y_coordinate3 _coordinate4 y_coordinate4 coordinate5 y_coordinate5 #coordinate of a point which 1s on island1 #coordinate of a point which 1s on island2 #coordinate of a point which 1s on 1sland3 #coordinate of a point which 1s on 1sland4 #coordinate of a point which is on island5 Remarks • There will be at most 100 islands. You can allocate only one array.(create an array for the terrain data). • You cannot declare any other array in your program. 1 You cannot use dynamic allocation.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY