Concept explainers
Statement-1:
Program:
//Header file
#include <iostream>
using namespace std;
//Main function
int main()
{
//Declare the array variable and initialize it
int values[5]={4,7,6,8,2};
//Display the subscript of the array
cout << values[4] << endl;
//Pause the system
system("pause");
//Return the statement
return 0;
}
Explanation:
In the above code, the array contains 5 values in it and the subscript of the array starts from 0 to 4.
This can be written as,
values[0]= 4;
values[1]= 7;
values[2]= 6;
values[3]= 8;
values[4]= 2;
Thus, the subscript of the array of values[4] contains the value “2”.
Sample Output:
2
Press any key to continue . . .
Therefore, the
Statement – 2:
Program:
//Header file
#include <iostream>
using namespace std;
//Main function
int main()
{
//Declare the array variable and initialize it
int values[5]={4,7,6,8,2};
//Display the subscript of array
cout << values[2]+values[3] << endl;
//Pause the system
system("pause");
//Return statement
return 0;
}
Explanation:
In the above code, the array contains 5 values in it and the subscript of the array starts from 0 to 4.
This can be written as,
values[0]= 4;
values[1]= 7;
values[2]= 6;
values[3]= 8;
values[4]= 2;
Thus, the subscript of the array of values[2] contains the value “6” and the subscript of the array of values[3] contains the value “8”.
Sample Output:
14
Press any key to continue . . .
Therefore, after adding these two values, the program displays the value “14” in the output screen for statement2.
Statement – 3:
Program:
//Header file
#include <iostream>
using namespace std;
//Main function
int main()
{
//Declare the array variable and initialize it
int values[5]={4,7,6,8,2};
//Display the subscript of array
cout << ++values[1] << endl;
//Pause the system
system("pause");
//Return statement
return 0;
}
Explanation:
In the above code, the array contains 5 values in it and the subscript of the array starts from 0 to 4.
This can be written as,
values[0]= 4;
values[1]= 7;
values[2]= 6;
values[3]= 8;
values[4]= 2;
In the highlighted statement, the subscript of the array of values[1] contains the value “7” and it is pre-incremented by 1.
Sample Output:
8
Press any key to continue . . .
Therefore, the program displays the value “8” in the output screen for statement3.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
- (Electrical eng.) Write a program that declares three one-dimensional arrays named volts, current, and resistance. Each array should be declared in main() and be capable of holding 10 double-precision numbers. The numbers to store in current are 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, and 3.98. The numbers to store in resistance are 4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, and 4.8. Your program should pass these three arrays to a function named calc_volts(), which should calculate elements in the volts array as the product of the corresponding elements in the current and resistance arrays (for example ,volts[1]=current[1]resistance[1]). After calc_volts() has passed values to the volts array, the values in the array should be displayed from inside main().arrow_forward(Data processing) Write a program that uses an array declaration statement to initialize the following numbers in an array named slopes: 17.24, 25.63, 5.94, 33.92, 3.71, 32.84, 35.93, 18.24, and 6.92. Your program should locate and display the maximum and minimum values in the array.arrow_forwardAn array definition reserves space for the array. true or falsearrow_forward
- Largest/Smallest Array Values Write a program that lets the user enter 10 values into an array. The program should then display the largest and smallest values stored in the array. Do question 7(above) again this time using 5 functions. void getValues(int [], int); void displayValues(const int[], int); int largest(const int[],int); int smallest(const int[],int); void displayLargestSmallest(int,int);arrow_forwardC++arrow_forwardMovie Data Write a program that will be used to gather statistical data about the number of movies college students see in a month. The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program then should allow the user to enter the number of movies each student has seen. It should then sort the scores and calculate the average. Modularity: Main: The main function should accept the number of students from the user and dynamically create an array large enough to contain number of movies watched for each student. Input validation: The number of students should be a positive integer. Print the average and free the allocated array when complete. Get the data: This function should get the number of movies watched by each college student. Input validation: The number of movies should be a positive integer. Sort the data: This function should sort the array in ascending order. Note you may use the Standard Template Library sort…arrow_forward
- Lotto Program C++Write a program that simulates the Powerball lottery. In Powerball, a ticket is comprised of 5 numbers between 1 and 69 that must be unique, and a Powerball number between 1 and 26. The Powerball does not have to be unique. Hint: You can use an array to represent the 5 unique numbers between 1 and 69, and an integer variable to represent the powerball. The program asks the player if they'd like to select numbers or do a 'quickpick', where the numbers are randomly generated for them. If they opt to select numbers, prompt them to type the numbers in and validate that they are unique (except the powerball), and in the correct range. The program then generates a 'drawing' of 5 unique numbers and a Powerball, and checks it against the user's lotto ticket. It assigns winnings accordingly. Because it is so rare to win the lottery, I suggest hard coding or printing values to when testing the part of the program that assigns winnings.arrow_forwardThe _______ function sorts an array of objects. a) bsort() b) hsort() c) ssort() d) qsort()arrow_forwardcomprog array declarationarrow_forward
- Look at the following array definition. int numbers[5] = { 1, 2, 3 };A) What value is stored in numbers[2]?B) What value is stored in numbers[4]?arrow_forwardFill-in-the-Blank The number inside the brackets of an array definition is the _________, but the number inside an array’s brackets in an assignment statement, or any other statement that works with the contents of the array, is the _________.arrow_forwardTRUE or FALSEA static array's capacity will change whenever it deems necessary.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning