This lab will focus on 2D arrays and how they store and retrieve information from them. It will have a simple command file that will mimic what we are doing in our 3 project.

Details

In this lab you will make a 2D array of 13 columns and 2 rows of type char. char theArray[13][2]; will work to create the array you need to store the data.

The program will process a set of commands. The commands will be described below.

load - The first command will be a load command. The load command will be followed by a file to open. That file will contain a set of characters in a 13 x 2 grid that you are to read and store in the array. The load command will always be first and it will always be followed by a filename to open. For example

load data.txt

This would mean you create another ifstream object using the file name data.txt, so store that in a variable and open that.

location - The second command is the location command. The location command will be followed by 2 integers. The integers represent an x and y location in the array. The location given by the x and y may or may not be valid. You need to make sure that they are at least 0 and less then 13 for x and 2 for y. For example:

location 0 0
location 12 1
location -1 -1
location 13 2

The first two examples are valid and the last two are invalid.

Depending on what is stored in the first two locations you would get output like this:

0, 0: A
12, 1: z

For the last two you would get this output:

-1, -1: bad location
13, 2: bad location

So when the location is good, you output the coordinates and then the data that is there and when the location is bad, you output the coordinates then the words "bad location". Note the comma between the x and y and the colon after the y coordinate.

Sample Input

If the input file contains this:

load test1data.txt
location 12 1

And the test1data.txt contains this data:

2 Y
5
R {
i e
K E
0 =
R l
@ ^
[ ,
C p
l t
b {
]

This is the output:

12, 1:

Requirements

1.You must use the file lab8.h for the header.

2.In the header you must declare the function void read2D_Data( string input, string output );

3.In your cpp file you must implement the function and use a 2D array of characters of size 13x2.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.