Question
C++ Arrays lab Objectives Declare an array Initialize an array Access elements of an array Use repetition to process all elements of an array Program
C++ Arrays lab
Objectives
Declare an array
Initialize an array
Access elements of an array
Use repetition to process all elements of an array
Program to be modified
/* arrayLab.cpp
Name:
Date:
Chapter 8 Arrays Lab
*/
/*
Place your name and section at the top in comments. Read theinstructions for each section and then implement your solutionwithin this program.
*/
#include
using namespace std;
int main() {
// 1. Declare an array of type integer named iNum andinitialize
// it with the values 2, 4, 6, 8, 10.
// 2. Write a statement to output the third element of arrayiNum
// followed by a newline.
// 3. Write a statement to store the value 12 in the last
// element of array iNum.
// 4. Declare an integer variable named index and set thatvariable
// to the value needed to use it as an index to access thesecond
// element of the array iNum.
// 5. Use the variable "index" as a subscript to display the
// second value of the iNum array.
// 6. Write a "while" loop using index that will output all ofthe
// elements of the array iNum. The values should be separatedby
// a space and a newline should be output at the end.
// 7. Write a function that takes three arguments. The first isthe
// name of an integer array, the second is an integer thatspecifies
// a position in the array, and the third is an integer thatwill
// be stored in the array. This function returns nothing.
// 8. Write the prototype for the function above and place itbefore main()
// 9. Call the function you wrote and send it the iNum array, 1,and 21 as
// the arguments, which should store 21 in the second element ofthe array.
//10. Write a "for" loop using index that will output all of theelements
// of the array iNum. The values should be separated by a spaceand
// a newline should be output at the end.
cout << "Press enter to continue...";
cin.get();
return 0;
}
Example run of program
6
4
2 4 6 8 12
2 21 6 8 12
Press enter to continue...
Step by Step Solution
3.31 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
arrayLabcpp C program to perform operation on array include using namespace std 8 function prototype void assignint array int position int value int m...Get Instant Access to Expert-Tailored Solutions
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