Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Initializing Arrays 2 A loop is often used to initialize an array. Copy the Code Add your Header Comment Save your file as Loop.cpp Compile

Initializing Arrays 2 A loop is often used to initialize an array.

Copy the Code Add your Header Comment Save your file as Loop.cpp Compile and Run your program

#include using namespace std; int main () { int array [] = {16, 2, 77, 40, 12071}; int n, result=0; for ( n=0 ; n<5 ; ++n ) { result = array[n]; cout << result << endl; }//end for return 0; }//end Main

-----------------------------------------------------------------------------------

Exercise 1 Code and Run

Code the Pseudocode Save your file as Exercise1.cpp Start num i //array index // Declare a 10 element array Initialize the elements to 0 num numbers[10] = {0,0,0,0,0,0,0,0,0,0} for i = 0 to 9 number[i] = i + 100 Set element at location i equal to i+100 Output each array subscript i and element value numbers[i] end for Stop HINT SAVE your LOOP.cpp as Exercise1.cpp and modify the program to do what the pseudocode requires.

-------------------------------------------------------------------------------------

Exercise 2 Code and Run

Code the psudocode and Save your file as Exercise2.cpp HINT SAVE your Exercise1.cpp as Exercise2.cpp and modify the program to do what the pseudocode requires.

Start num numbers[9] num i //array subscript num numberIn num sum for i = 0 to 8 Ask user to input a number Store number in array[i] element Calculate the sum of the numbers end for Print out the sum Stop

-------------------------------------------------------------------------

Finish coding then compile and run the code below. Modify it to output each loopIndex and each array element. Save our file as Exercise3.cpp Hint save one of your other programs as Exercise3.cpp and modify your declarations, and loop to run the code using the constant NUM_ITEMS

const int NUM_ITEMS = 3; double target [NUM_ITEMS]; int loopIndex; for (loopIndex = 0; loopIndex < NUM_ITEMS; loopIndex++ ) target[loopIndex] = loopIndex + 10;

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_2

Step: 3

blur-text-image_3

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

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

Do you currently have a team agreement?

Answered: 1 week ago

Question

How will the members be held accountable?

Answered: 1 week ago