For this exercise you are asked to write an application that allows the user to input the coordinates of points on a map. After the
For this exercise you are asked to write an application that allows the user to input the coordinates of points on a map. After the user has input all the coordinates they want to input, the program then displays a text-based map, filled with dots (represented by the '.' character), except for the locations the user entered the coordinates of, which are indicated by 'X' characters.
The dimensions of the map is 66 columns by 19 rows. You should use a two-dimensional array to mark the coordinates entered by the user (e.g. bool[,] map = new bool[19,66]).
The program collects input from the user by asking the user to input the X coordinate first, followed by the Y coordinate, followed by 'y' or 'n' to ask the user if there are any more points to be entered.
After the user has indicated (by responding 'n' on the third question) that there are no more points, the program should display the map, ask the user to press enter to exit, then close when the user presses enter.
Here is an example of a typical session (using a map of 10 columns by 5 rows to save space):
---
Place a marker at which X coordinate? (0-9): 3 Place a marker at which Y coordinate? (0-4): 2 More? (y/n): y Place a marker at which X coordinate? (0-9): 5 Place a marker at which Y coordinate? (0-4): 1 More? (y/n): y Place a marker at which X coordinate? (0-9): 0 Place a marker at which Y coordinate? (0-4): 0 More? (y/n): n X......... .....X.... ...X...... .......... .......... Press enter to exit.
---
Note that:
The coordinates are base 0 - that is, the lowest legal value for a coordinate is 0 and the highest legal value is the respective dimension of the map minus 1. Therefore, for the above example with a 10 x 5 map, the valid X values are 0-9 and the valid Y values are 0-4.
The coordinates 0, 0 refer to the top left of the map.
Your program should detect invalid input and out of range coordinates. When the user enters something other than a number as one of the coordinate inputs, your program should display the message 'Invalid input.' and ask the user again.
Likewise, if the user enters something that is a number but that number is outside the legal range for the map, your program should display the message 'Out of range.' and ask for that coordinate again.
Finally, for the question 'More? (y/n): ', if the user enters anything other than 'y' or 'n', your program should display the message 'Please answer with y or n.' and ask the user again.
Here's another example of a possible session with the program, again with a 10 x 5 map:
---
Place a marker at which X coordinate? (0-9): sadfsfda Invalid input. Place a marker at which X coordinate? (0-9): 4 Place a marker at which Y coordinate? (0-4): 27 Out of range. Place a marker at which Y coordinate? (0-4): -3 Out of range. Place a marker at which Y coordinate? (0-4): 2 More? (y/n): a Please answer with y or n. More? (y/n): n .......... .......... ....X..... .......... .......... Press enter to exit.
---
Here's some hints specific to this exercise:
Make sure you refer to the coordinates within the array in the same order as the dimensions when you referenced the array. For example, if your array is a bool[19, 66] you will need to refer to it using the Y coordinate first, then the X coordinate, e.g. map[y, x]
For drawing the map remember that you can use Console.Write("."); or Console.Write("X"); to write a single character without ending the line, and then later use Console.WriteLine(); when you actually want to end the line.
When drawing the map you will want to use two loops, one inside the other.
Use this code as a template:
---
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace MapPlotting { class Program { public static void Main() { // Write your program here // ... Console.WriteLine("Press enter to exit."); Console.ReadLine(); } } }
---
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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