The objective for today's lab is to use arrays. You will
declare arrays, access individual elements, access arrays using
a for loop, and initialize arrays.
- Create a New Project
- The code for today's lab does not have a particular purpose.
- Paste the following code
- Declare an array numbers to have 10 floating point values.
- Set the first element to 3.6
- Print the first element
- Run the program
- Declare a const int SIZE to be 10 and change the declaration
of numbers
- Run the program
- Solution is here
- As the last line of the code place this:
cout << numbers [SIZE];
- Run the code. What happened?
- Remove the line of code that accesses an element past the end of the array.
- Next, use a for loop to permit the user to enter all 10 numbers.
- After the first for loop, place a second one that prints
the numbers in reverse, all on one line.
- Run the program
- Solution is here
- Change the float to char
- Change the cout statements to make sense.
- Run the code and check the output.