Starting from:

$30

COP3514.002 Project #6 Map analysis -Solved

Task description: 
In this project, you must obtain different information about a mapped territory. The territory map is represented by a 2D matrix, and each cell in this matrix represents an area of one square mile (each side is one mile in length). These cells can be either land (L) or water (W), as illustrated in the figure below. 
W     W     W     W     W 
W     L     L     L     L 
W     L     L     L     L 
W     W     L     L     L 
W     W     W     W     W 
Your task is to create two files: "coast.txt" and "statistics.txt". The file "coast.txt" must show the location of coast cells, which are land cells that share at least one side with a water cell. Coast cells must be marked with 'Y' and other cells with 'N'. Please consider any space outside the mapped area as water. The coast cells for the map above are shown below. 
N     N     N     N     N 
N     Y     Y     Y     Y 
N     Y     N     N     Y 
N     N     Y     Y     Y 
N     N     N     N     N 
Finally, the file "statistics.txt" must contain the total map area, the total land area, and the "wet perimeter" (i.e., the length of land in direct contact with the water). For the map above, the total map area is 25 square miles, the total land area is 11 square miles, and the wet perimeter is 14 miles. 
Execution specification: 
Your program will be run with one command-line argument, which defines the text file with the input map. For instance, a program named "a.out" will be executed as follows: 
./a.out [input_file.txt] 
where "input_file.txt" will be replaced with the name of the map file. 
Input specification: 
The map file starts with one line with two integers R and C representing the number of rows and columns in the map (1 ≤ R,C ≤ 1000). Each of the next R lines contains C characters indicating the cell type: 'W' for water and 'L' for land. You must read the input from the file indicated as a command-line argument! 
Output specification: 
For the file "coast.txt", print R lines, each containing C characters indicating if its respective cell in the input map is a coast cell or not. Use 'Y' to mark coast cells, and 'N' for any other cell. Do not forget the new-line character at the end of each row. 
For the file "statistics.txt", print three lines respectively showing the total map area, the total land area, and the wet perimeter. See the examples below to learn the expected format. 
 
Example #1: 
Command         
./a.out maps/1.txt         
Input file: maps/1.txt     Output file: coast.txt     Output file: statistics.txt 
5 5 
LLLLL 
LWWWL 
WWWWW 
LWWWW 
LLWWL     YYYYY 
YNNNY 
NNNNN 
YNNNN 
YYNNY     TOTAL AREA: 25 
TOTAL LAND AREA: 11 
WET PERIMETER: 28 
 
Example #2: 
Command         
./a.out maps/2.txt         
Input file: maps/2.txt     Output file: coast.txt     Output file: statistics.txt 
5 5 
WWWLL 
WWWLL 
WWWLL 
WWWLL 
WWWLL     NNNYY 
NNNYY 
NNNYY 
NNNYY 
NNNYY     TOTAL AREA: 25 
TOTAL LAND AREA: 10 
WET PERIMETER: 14 
 
Example #3: 
Command         
./a.out maps/3.txt         
Input file: maps/3.txt     Output file: coast.txt     Output file: statistics.txt 
10 10 
WWWWWWLLLL 
WWWWWWLLLL 
WWWWWWWLLL 
LLWWWWWWLL 
LLLLWWWWWL 
WWWWWLLWWW 
WWWWWLLLWW 
WWWWWWLLWW 
LLWWWWLLWW 
LLLWWWLLWW     NNNNNNYYYY 
NNNNNNYNNY 
NNNNNNNYNY 
YYNNNNNNYY 
YYYYNNNNNY 
NNNNNYYNNN 
NNNNNYNYNN 
NNNNNNYYNN 
YYNNNNYYNN 
YYYNNNYYNN     TOTAL AREA: 100 
TOTAL LAND AREA: 36 
WET PERIMETER: 56 
 

More products