Lab: Arrays and Loops

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.

  1. Create a New Project
  2. The code for today's lab does not have a particular purpose.
  3. Paste the following code
  4. Declare an array numbers to have 10 floating point values.
  5. Set the first element to 3.6
  6. Print the first element
  7. Run the program
  8. Declare a const int SIZE to be 10 and change the declaration of numbers
  9. Run the program
  10. Solution is here
  11. As the last line of the code place this: cout << numbers [SIZE];
  12. Run the code. What happened?
  13. Remove the line of code that accesses an element past the end of the array.
  14. Next, use a for loop to permit the user to enter all 10 numbers.
  15. After the first for loop, place a second one that prints the numbers in reverse, all on one line.
  16. Run the program
  17. Solution is here
  18. Change the float to char
  19. Change the cout statements to make sense.
  20. Run the code and check the output.