The following code totals the values in each of two arrays described in question 31. Will the code print the correct total for both arrays? Why or why not?
int total= 0; // Accumulator
int count; // Loop counter
// Calculate and display the total of the first array.
for (count = 0; count < 25; count ++)
total += array1[count];
cout << "The total for array1 is" << total << end l ;
// Calculate and display the total of t he second array.
for (count = 0; count < 25; count ++)
total += array2[count];
cout << "The total for array2 is"<< total<< end l ;
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out with C++: Early Objects
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How To Program (Early Objects)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Concepts of Programming Languages (11th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
- (Electrical eng.) Write a program that specifies three one-dimensional arrays named current, resistance, and volts. Each array should be capable of holding 10 elements. Using a for loop, input values for the current and resistance arrays. The entries in the volts array should be the product of the corresponding values in the current and resistance arrays (sovolts[i]=current[i]resistance[i]). After all the data has been entered, display the following output, with the appropriate value under each column heading: CurrentResistance Voltsarrow_forward{ // Declare a named constant for array size here // Declare array here // Use this integer variable as your loop index int loopIndex; // Use this variable to store the batting average input by user double battingAverage; // Use these variables to store the minimim and maximum values double min, max; // Use these variables to store the total and the average double total, average; // Write a loop to get batting averages from user and assign to array cout << "Enter a batting average: "; cin >> battingAverage; // Assign value to array // Assign the first element in the array to be the minimum and the maximum min = averages[0]; max = averages[0]; // Start out your total with the value of the first element in the array total = averages[0]; // Write a loop here to access array values starting with averages[1] // Within the loop test for minimum and maximum averages.…arrow_forwardPart 1: Randomizing an Array In this problem you will write a program that will randomize the elements of an array created by the user. 1. Prompt the user to enter an integer, then asks the user to enter that many values. Store these values in an array and print the array. Then re-shuffle the array elements so randomly. Do not just randomize the order in which they are printed; actually change the way they are stored in the array. Do not create a second array; just rearrange the elements within the array you have. (Hint: Swap elements that need to change places.) When the elements have been randomized, print the array again. 2. Create another version of your program that applies the following modification to the randomization process: elements that have been already swapped should not be swapped again. Example: if element 1 was swapped with element 10, when the 10 th element is reached it should not be swapped again. Yet if the 2 nd element is reached it can be swapped with the 10o the…arrow_forward
- Pass by Array Create a JAVA program that will ask the user to enter ten numbers and get the sum of all odd numbers. The numbers will be stored in array The array value will be pass as argument to the functionarrow_forwardAn array definition reserves space for the array. true or falsearrow_forward1- Write a program that prompts the user to read two integers and displays their sum. Your program should prompt the user to read the number again if the input is incorrect. Hint: use the InputMismatchException 2- Write a program that meets the following requirements: Creates an array with 100 randomly chosen integers. Prompts the user to enter the index of the array, then displays the corresponding element value. If the specified index is out of bounds, display the message Out of Bounds Hint: use the ArrayIndexOutOfBoundsExceptionarrow_forward
- A for loop is often used when processing the elements of an array. Given an array called scores with 10 elements, what entries would complete the for loop header shown below? for (int i = 10; i++) O first blank: 0 second blank: <= O first blank: 0 second blank: < O first blank: 1 second blank: <= first blank: 1 second blank: < O Oarrow_forwardFill-in-the-Blank To print out all elements of a two-dimensional array you would normally use a(n) _________ loop.arrow_forward4- Using “Def” keyword write a function that returns the mean element of the given array elements (The function name will be MeanofArrayElements)5- Using “Def” keyword write a function that returns the sum of each element for the given array (The function name will be SumofArrayElements)6- Using “Def” keyword write a function that compares two arrays, if both are the same it will return true, else it will return false. (The function name will be AreArraysEqual)arrow_forward
- PROGRAMMING LANGUAGE: C++ Write a program that accepts up to 20 test-match scores of a batsman in the range of 0 to 100 from the user and stores them in an array. Then main should report how many perfect scores (i.e., scores of 100) and ducks (i.e., scores of 0) were enteredarrow_forwardQuestion 1 Write a program that declares an array of 100 doubles. The program asks the user to enter a number N between 100, and then: initializes the first N elements of the array to random numbers between 1 and 100. calculates the average of these numbers and displays it. A final loop displays the elements of the array, each on a line, with an indication as to whether that number is lower or higher than the average. For example, if the numbers generated are 5, 28, 3, 8, 15, 7, 22, 6, 1, 4, then the program will print: Average = 9.9 5 28 3 8 15 7 22 6 1 4 11 11 11 -- 11 11 1- —— 11 lower than average higher than average lower than average lower than average higher than average lower than average higher than average lower than average lower than average lower than averagearrow_forward# Declare a named constant for array size here. MAX_AVERAGES = 8 # Declare array here. # Write a loop to get batting averages from user and assign to array. averageString = input("Enter a batting average: ") battingAverage = float(averageString) # Assign value to array. # Assign the first element in the array to be the minimum and the maximum. minAverage = averages[0] maxAverage = averages[0] # Start out your total with the value of the first element in the array. total = averages[0] # Write a loop here to access array values starting with averages[1] # Within the loop test for minimum and maximum batting averages. # Also accumulate a total of all batting averages. # Calculate the average of the 8 batting averages. # Print the batting averages stored in the averages array. # Print the maximum batting average, minimum batting average, and average batting average. This is on mindtap pyton what needs to be fixarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage