Question

In: Computer Science

Arrays provide the programmer the ability to store a group of related variables in a list...

Arrays provide the programmer the ability to store a group of related variables in a list that can be accessed via an index. This is often very useful as most programs perform the same series of calculations on every element in the array. To create an array of 10 integers (with predefined values) the following code segment can be utilised:

int valueList[10] = {4,7,1,36,23,67,61,887,12,53};

To step through the array the index '[n]' need to be updated. One method of stepping through the array is via a 'for' loop. Based on the array ‘valueList’ create a small C++ application utilising a 'for' loop that steps through the array and determines the largest number in the list and prints out the index and value. Hint: Consider creating an integer that stores the current largest integer and then compares it with the next indexed value.

Solutions

Expert Solution

Program:

#include<iostream>

using namespace std;

int main()

{

int valueList[10] = {4,7,1,36,23,67,61,887,12,53}; // array variable declaration and assign values

int largestValue,largestValueIndex=0; // variable declaration

largestValue = valueList[0]; // Current largest value is considered as the first element of the arrray

for(int i = 1; i < 10; i++){ // Loop to run for 10 elementd

if(valueList[i] > largestValue){ // if condition to check current value of the array is larger

largestValue = valueList[i]; // update the larger value

largestValueIndex = i; // Update the index value

}

}

cout<<"The largest number in the list is: "<<largestValue<<endl; // print largest number

cout<<"The largest number array index is: "<<largestValueIndex<<endl; // print largest number index

return 0;

}

Output:


Related Solutions

Python programming Summary Store the times into arrays called Chevy[ ] and Ford[ ]. Then list...
Python programming Summary Store the times into arrays called Chevy[ ] and Ford[ ]. Then list the winner of each pair, giving the number of seconds the winner won by. At the end declare which team won based on which team had the most wins. Lab Steps There are eight cars in each team called Chevy and Ford. One car from each team races its opponent on the drag strip. Read in the racing times for the eight Chevy cars...
How is the ability to store glucose as glycogen related to the general principle of physiology...
How is the ability to store glucose as glycogen related to the general principle of physiology that physiological processes require the transfer and balance of matter and energy?
Build a simple list implementation that uses arrays to store the values. Create a class SimpleArrayList...
Build a simple list implementation that uses arrays to store the values. Create a class SimpleArrayList with a public constructor that initializes the list using a passed array of Object references. Assert that the passed array is not null. Next, implement: 1)Object get(int), which takes an int index and returns the Object at that index 2)void set(int, Object), which takes an int index and an object reference and sets that value at the index to the passed reference Both your...
Create a list of six variables related to this decision – three must be categorical in...
Create a list of six variables related to this decision – three must be categorical in nature, and three must be numeric. Indicate how these variables are measured. For example, are they yes/no questions, Likert-scale questions, numeric values (what units?), etc. The decision is: making the ordering process quicker for customers at a fast food establishment.
// Programmer: // Date: // The Saurian class has the ability to translate English to Saurian...
// Programmer: // Date: // The Saurian class has the ability to translate English to Saurian // and Saurian to English public class Saurian {    // data    // constants used for translating    // note M = M and m = m so M and m are not needed    public static final char[] ENGLISHARR = {'A','B','C','D','E','F','G','H','I','J','K','L','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','n','o','p','q','r','s','t','u','v','w','x','y','z'};    public static final char[] SAURIANARR = {'U','R','S','T','O','V','W','X','A','Z','B','C','D','E','F','G','H','J','K','I','L','N','P','O','Q','u','r','s','t','o','v','w','x','a','z','b','c','d','e','f','g','h','j','k','i','l','n','p','o','q'};    public static final int ARRLENGTH = ENGLISHARR.length;   // should be the same...
List and describe the five stages of group development and provide examples.
List and describe the five stages of group development and provide examples.
Provide an example of a nominal, rank-order, and equal-interval variable. Be sure to list the variables...
Provide an example of a nominal, rank-order, and equal-interval variable. Be sure to list the variables and note how they are measured (i.e., the categories for the variables).   
Ron is a topnotch programmer with over twenty years experience. He prides himself on his ability...
Ron is a topnotch programmer with over twenty years experience. He prides himself on his ability to solve any problem, and produce great code. He was appointed to a project team led by LaVerne, a young analyst, given her first chance at a lead role. She gave him some DFD diagrams (that she worked very hard to do), and he became very irritated. Ron told her that she had wasted her time and his. DFD diagrams don't show what the...
Provide a civil engineering related hypothesis and then list the outcome variable with its unit of...
Provide a civil engineering related hypothesis and then list the outcome variable with its unit of measurement (i.e. psi, frequency, inches, etc.) and three predictor variables with their respective units of measurement.
Organize the following list of items into 3 main categories. Then group related ideas under those...
Organize the following list of items into 3 main categories. Then group related ideas under those categories. Finally put all items in logical order. When your outline is complete, rationalize/explain why you chose the ordering you chose. Qualifications No physical examination or health questions Guaranteed acceptance for all applicants Hospitalization Benefit is $100 a day Paid when hospitalization is the result of a motor vehicle or a common carrier accident Cash paid in addition to any other insurance carried Costs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT