Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ For this lab, we are turning our attention to arrays. An array is a sequential storage unit. So in general it can store more

C++

For this lab, we are turning our attention to arrays. An array is a sequential storage unit. So in general it can store more than 1 of a data type. Each element of the array is stored at an index position and those indices start at 0. So for example, if an array has space for 10 ints, they will be stored in index positions 0-9.

Details

You access the individual array elements with [ ] and you put a number in the []. For example, if our array is called myArray and it has size 10, then we could access the first spot like this:

myArray[0] 

It is an error to put a number that is not within the array indices bounds. It is your job as the programmer to ensure that never happens. This lab is focusing on making sure that doesnt happen. In my tests, I will be giving you index numbers that are in fact too large or too small.

Input The input for this program will be a number followed by a character. The number represents the index position where the character is to be stored. You must make sure the given index is valid. If it is, then store the character at the given index location. If it not valid, then dont do anything.

1 x 2 a 3 q 30 r 25 r -1 z 0 t 

We will make our array to be of size 30. If an index number is repeated, and it is valid, then we will simply replace what was there.

After you finish reading all the data, you will simply print the entire array in the form shown below.

Output

Index Letter 0 t 1 x 2 a 3 q 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 r 26 27 28 29 

What is in the output is a header line that indicates what is in the columns below. The first column is the index number and the second column is the contents of the array at the given index location.

As you know, if you dont initialize a variable, then you dont know what is in it. Since the data is character data, the array should be of type char. We can use the space character to initialize our array. The space character is and wont show anything when printed and can be used to initialize our array. I suggest using a for loop to initialize all 30 index locations to the space character.

Requirements

Below are the requirements for the lab:

You must declare the function void arrayChecking( string input, string output ); in a file named: lab8.h

Your array must be of size 30.

Your array must be of data type char.

You must initialize your array to the space character,

You must implement your function in a cpp file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions