Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++,please do it all 3. Introduction to Arrays An array is a variable capable of storing multiple values. When we declare an array we tell

C++,please do it all image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
3. Introduction to Arrays An array is a variable capable of storing multiple values. When we declare an array we tell the compiler how many values we want the array to hold. We also tell the compiler what type of values the array can store. All of the values in an array must be of the same type. Here is a declaration of an array called numlist that will be used to store 12 integers: const int SIZE 12: int nurmist [SIZE]: declare int array that can store 12 values If we wish to fill the array numlist with the integers typed from the keyboard, you can use a for loop. Here is a for loop that will allow you to enter 12 values from the keyboard and store them in the array numlist. Notice that we have used the variable i as an index for array numlist. for (i m 0: i SIZE: i++) cout "Enter the next value: cin numuistlil: It might be easier for our user to keep up with different values that need to be entered if we display something more helpful than "Enter the next value: Since users typically number items in a list starting from 1, we w say "Enter value M1 when asking for numlist 101, "Enter value #2: when asking for num list [1], and so forth. Here is the improved version of the loop: for (i 0: i SIZE: i++) cout "Enter value i-1 cin numlistlil By asking for value #1, then value H2, etc., we are allowing our user to count in a more natural way than C++ forces us to count. That is the most confusing part of working with arrays. It is natural to think that an array of size 12 will keep 12 values, thus, assuming that the indices would be 1through 12. For an array of size 12, index 1 is avalid index, but index 12 is invalid and may cause a run-time error if it is used. The following program allows you to enter 12 integers from the keyboard and will store those values in array numlist

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions