Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ PROGRAMMING TEXT FILES 7 10 WWWWWCCDEW WWWWCCEEEW WTWWWCCCCW WWFFFFFFWW WWFAAAAFWW WWFABCAFFW WWFAAAAFWW 3. The United States is not a landlocked country: the country touches
C++ PROGRAMMING
TEXT FILES
7 10 WWWWWCCDEW WWWWCCEEEW WTWWWCCCCW WWFFFFFFWW WWFAAAAFWW WWFABCAFFW WWFAAAAFWW
3. The United States is not a landlocked country: the country touches at least one ocean (in fact, it touches three). There are 44 countries (including Bolivia and Mongolia, for example) which are landlocked. That is, they do not touch an ocean, but by going through one other country, an ocean can be reached. For example, a person in Mongolia can get to an ocean by passing through Russia. Liechtenstein and Uzbekistan are the only two countries in the world which are land-landlocked. That is, not only are they land-locked, but all countries which surround these two countries are land-locked countries. Thus, one would have to pass through at least two different countries when leaving Uzbekistan before arriving at an ocean. Write a program to determine how landlocked each country is on a given map. A country is not landlocked (recorded as 0) if it touches water in any adjacent cell in either a horizontal, vertical, or diagonal direction. If a country is landlocked, you must calculate the minimum number of borders that one must cross in order to travel from the country to water. Each step of such a journey must be to a cell that is adjacent in either a horizontal, vertical, or diagonal direction. Crossing a border is defined as taking a step from a cell in one country to an adjacent cell in a different country. Note that countries may not be connected to themselves (as in a country formed of islands). In this case, the landlocked value for the country is the minimal of each connected region of the country. Input from a data file, the first line contains N and M (1 S N, M S 1000). On each of the next N lines, there are M capital letters. Each country will be represented by a unique letter, with the exception that the letter Wis reserved to indicate the water in the oceans or seas that will be used to determine the how landlocked each country is. The output consists of a label followed by the country letter followed by a space, followed by the landlockedness for that particular country. Output should be in alphabetical order. Enter the file name from the keyboard. Use user-defined functions/methods in your program. For C++ use the string class; otherwise, use any data structure of your choice. Refer to the sample output below. Sample File: Sample Run: Enter the file name: countries.txt Countries and landlockedness values: 7 10 WWWWWCCDEW WWWWCCEEEW WTWWWCCCCW WWFFFFFFWW WWFAAAAFWW WWFABCAFFW WWFAAAAFWW A 1 B2 - TimonStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started