The following code totals the values in two arrays: numberArray1 and numberArray2. Both arrays have 25 elements. Will the code print the correct sum of values 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 < 24; count++)
total += numberArray1[count];
cout ≪ "The total for numberArray1 is " ≪ total ≪ end1;
//Calculate and display the total of the second array.
for (count = 0; count < 24; count++)
total += numberArray2[count] ;
cout ≪ "The total for numberArray2 is "« total << end1;
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++ from Control Structures to Objects Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Starting Out with Java: Early Objects (6th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- Javascript programming question below Write the pseudocode for an application that will:a. Prompt a user for three numbers.b. Store the values entered by a user in an array as they are provided bythe user.c. Ask a user if they would like to search for a value:i. If the user wishes to search for a value, the user needs to beprompted for a value to search for. If the value is found, anotification needs to be provided to the user.d. Use a for loop to cycle through the arrays in order to calculate anddisplay the total of the values stored in the array.arrow_forwardA Latin square is an n-by-n array filled with n different Latin letters,each occurring exactly once in each row and once in each column. Write a program that prompts the user to enter the number n and the array of characters,as shown in the sample output, and checks if the input array is a Latin square.The characters are the first n characters starting from A. Enter number n: 4Enter 4 rows of letters separated by spaces: ↵EnterA B C D↵EnterB A D C↵EnterC D B A↵EnterD C A B↵EnterThe input array is a Latin square Enter number n: 3 ↵EnterEnter 3 rows of letters separated by spaces:A F D ↵EnterWrong input: the letters must be from A to Carrow_forwardQ1 Write a Java program named matrixArray that generate 25 random integer numbers (their range must be between 0 and 50 exclusive) and stores them an array The program should do the following 1- Display (print out) all numbers 2- Display all between 20 and 35 inclusive. 3- Sum array elements between 20 and 35 inclusive.arrow_forward
- Given the following array declaration:int array[30];Note that you DON’T know the values in the array.Use a for loop to increment the contents of the even indexed (0, 2, 4, 6, 8 …) elements by the value of 4.Output the first component of array.Set of the value of the fourth component of array to 7 multiplied by the value of the 30th component of array plus 8.arrow_forwardPlease write this pseudocode in the form of source code 1. Declare an array of array named 'Data' of size 300*5 2. Set count = 0 3. Set i=0 4. For row i of the array 5. If (count==300) 6. break 7. end if 8. Set j=0 9. call function check() 10. if check() returns true then 11. Set Data[i][j] = Student ID 12. Set Data[i][j+1] = Student Name 13. Set Data[i][j+2] = Student class 14. Set Data[i][j+3] = Student Phone No 15. Set status in Data[i][j+4] = Admitted 16. Else 17. Set Data[i][j] = Student ID 18. Set Data[i][j+1] = Student Name 19. Set Data[i][j+2] = Student class 20. Set Data[i][j+3] = Student Phone No 21. Set status in Data[i][j+4] = Not Admitted 22. Set count=count+1 23. Set i = i+1. 24. Declare a method check() 25. If current time < 12hrs and student_temperature < 38 then…arrow_forward1. Write a for loop to initialize the following array with value 0.0 double[] balances = new double [5] 2. Write a for-each loop to print out every element of the above array.arrow_forward
- Below is code which defines and creates an Array, myList: int [] myList = new int [5]; //define and createThe loop below stores the values 1 to 5 in myList:for (int i = 0; i < 5; i ++) {myList [ i ] = i + 1; //store values using a loop}The loop below prints the values from first to last in myList:for (int i = 0; i < myList.length; i++) { System.out.print(myList [ i ] + " ");}The code below is used to get user from the user and calculate the sum:import java.util.*;public class WhileWithInput {public static void main(String[] args) {Scanner reader = new Scanner (System.in);int count = 1; double total = 0; while (count <= 5) {System.out.println("Enter a decimal number"); double number = reader.nextDouble();total = total + number;count = count + 1;System.out.println("The total is " + total); }System.out.println("The total is " + total); }}1CPS 2231 Chapter 7 – lab 2 Fall 2019Use the examples on page 1 to complete the lab below. Please submit a screen print of the Eclipse editor…arrow_forwardIn C Programming Language Palindrome: “A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward, such as ‘madam’ or ‘kayak’” (excerpt from Wikipedia).Write a program that reads 8 words from Palindrome.txt and checks whether the word you read is a palindrome (please read its description above) or not. Print the index numbers of all the palindrome words in your array. You are required to read words character by character into a character array.• Write readFile function, which gets a file pointer and a two-dim array, to read each word(bunch of characters) line by line and store them into a two-dim character array.• Write findSize function takes a one-dim array and returns its actual size.• Write isPalindrome function takes a one-dim character array to check whether the content is a polindrome or not. If the word (character squence) is a palindrome, then it returns 1. Otherwise, it returns 0.arrow_forwardWrite a program that defines a multidimensional array $clubs that stores information about four football clubs, including the name, and the year founded. The program should print the contents of the array using a foreach loop. The program should also sort the array by the club name using the sort() function. Finally, it should print the sorted array.Complete the code:<?php// Define a multidimensional array$clubs = array(array("Newcastle United","England", 1892),array("Gezira Sporting Club", "Egypt", 1882),array("Zamalek Sporting Club", "Egypt", 1911),array("Bidvest Wits South Africa", "Egypt", 1921));// Print the contents of the arrayecho "List of football clubs:\n";foreach ( //Add code) {//Add code}// Sort the array by the first columnsort(//Add code);// Print the sorted arrayprint_r(//Add code);?>arrow_forward
- C++ 2D ARRAY, Continue this codes and change the array to seat[6][6]. Include a loop that asks the user if he wants to try again or no. If the user enters the reserved seat again then display "this seat is taken already". Upon trying again, the reserved seat displayed as (X) must be displayed. My Code: #include <iostream> using namespace std; int main() { cout << "Bus Seats:\n"; cout << "* A B C D\n" << "1 * * * *\n" << "2 * * * *\n" << "3 * * * *\n" << "4 * * * *\n"; char seat[5][5]; int row, column; char col; cout << "Enter the row of your selected seat: "; cin >> row; cout << "Enter the column of your selected seat: "; cin >> col; for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ if(i==0){ switch (j) { case 0: seat[i][j]='*'; break; case 1: seat[i][j]='A'; break; case 2: seat[i][j]='B'; break; case 3: seat[i][j]='C'; break; case 4: seat[i][j]='D'; break; } } else if (j==0) { switch(i) { case 1: seat[i][j]='1';…arrow_forwardLAB 7.1 Working with One-Dimensional ArraysRetrieve program testscore.cpp from the Lab 7 folder. The code is as follows: // This program will read in a group of test scores (positive integers from 1 to 100)// from the keyboard and then calculate and output the average score// as well as the highest and lowest score. There will be a maximum of 100 scores.// PLACE YOUR NAME HERE#include <iostream>using namespace std;typedef int GradeType[100]; // declares a new data type:// an integer array of 100 elementsfloat findAverage (const GradeType, int); // finds average of all gradesint findHighest (const GradeType, int); // finds highest of all gradesint findLowest (const GradeType, int); // finds lowest of all gradesint main(){GradeType grades; // the array holding the grades.int numberOfGrades; // the number of grades read.int pos; // index to the array.float avgOfGrades; // contains the average of the grades.int highestGrade; // contains the highest grade.int lowestGrade; // contains…arrow_forward(Random sentences and story writer) Write an app that uses random-number generation to create sentences. Use four arrays of strings, called article, noun, verb andprepostion. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article, noun.As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the sentence is output, it should start witha capital letter and end with a period. The program should generate 10 sentences and output them to a text box. The arrays should be filled as follows:The article array should contain the articles "the", "a", "one", "some" and "any";The noun array should contain the nouns "boy", "girl", "dog", "town", "car";The verb array should contain the past tense verbs "drove", "jumped", "ran", "walked" and "skipped";The preposition array should contain the preposotions "to", "from", "over", "under" and "on";arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT