Concept explainers
What is the output of the following code?
const int SIZE 5 ;
int count;
int time[SIZE] =
speed[SIZE] =
dist[SIZE] ;
{1, 2, 3, 4, 5} ,
{18, 4, 27, 52, 100} ,
for (count= O; count< SIZE; count ++)
dis t[count] = time[count] * speed[count];
for (count= O; count< SIZE; count ++)
{
)
cout << time[count] <<" ";
cout << speed[count] <<" ";
cout << dist[count ] << endl ;
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
MyLab Programming with Pearson eText -- Standalone Access Card -- for Starting Out With C++: Early Objects (My Programming Lab)
Additional Engineering Textbook Solutions
Computer Science: An Overview (12th Edition)
C++ How to Program (10th Edition)
C Programming Language
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Java: Early Objects (6th Edition)
- 1. When you are taking java, you are aware that a[] is an array, It can also be evalutated under certain circumstances. if you have x[2*z+4], what do you need to be true to evaluate? a. 3<= x < z.length b. 3<= x < (z.length-1)/2 c 2 <= x < z.length d. 4<= x < z.length/2 2. Given the program solve the problem for (int i=0; i ! lolma.length-1; i= i+1){ lolma[i] = lolma[i]+lolma[i+1] the array looks like from 0-3: 5, 9, 1, -3 What will be the next order a. 5,9,1,-3 b. 11,19,3,-5 c. 14,10,-2,-3 d. 5, 14,10,-2arrow_forwardWhat does the following code? void xxxx(int arr[], int index[], int n){int temp[n]; for (int i=0; i<n; i++)temp[index[i]] = arr[i]; for (int i=0; i<n; i++){arr[i] = temp[i];index[i] = i;}}arrow_forward1)Write a method that takes an array of ints and returns the sum of all numbers that are even. For example, given an array {3, 4, 6}, you would return 10. 2)For this exercise, you are given an array of integers. Return true if every element in the array is an odd number, otherwise return false. 3) Given an array of strings, return the array in reverse order. For example, given: reverse({"one", "two", "three"}); You would return: {"three", "two", "one"} 4) For this exercise, you need to shift all the elements in the array one space to the right (increase the index of the element by 1). The last element will wrap around and become the new first element. For example, given: moveUp({"first", "second", "third", "fourth"}); You would return: {"fourth", "first", "second", "third"}arrow_forward
- Given the Array declaration below, determine the output: int T[8] = {2, 3, 7, 9, -1, 2, 4, 5}; int x = 5; cout << T[x-2] / T[12-2*x]; int y = -3; cout << pow(T[y+4],T[3-y]);arrow_forward(a). Write a Java statement that declares and creates a 2D integer array called int_arr with 5 rows and 7 columns(b). Use a nest for loops to assign an integer value i*j (the product of row number i and column number j of array int_arr) to each array element of the 2D array int_arr(c). Change the value of the last array element in row 0 to 5 (d). Change the value of the very last array element of the 2D array int_arr to 10.(e). Change the value of the very first array element of the 2D array int_arr to 10(f). Write a Java for loop to print every array element in the first row.(g). Write a Java for loop to print every array element in the last column.Answer:arrow_forwardPlease use Java and Please follow all directions. Several times I've posted this and the output has to include the names of items, quantity, and sale price. Item #03, Quantity: 2, Price: $12. Something like this but please have it in ascending order of quantity in stock. thank you! 1) Declare and initialize an array that keeps records of 10 items. Each item has a name, quantity in stock, and a sale price. Assign random values to numeric fields of each new item, and give sequential item names to each of them: "Item #01". "Item #02," "Item #03," ... Hint: You need to use the Random class library. 2) Traverse this array and print all the items. 3) Sort the values in this array in ascending order of quantity in stock and print all the items.arrow_forward
- what is the output of following java code segment? int array[]={3,2,5}; for(int j:array) system.out.print("%d" , j); system.out.println();arrow_forwardWhat is the value of J[2][1] in the following array declaration? int[][] J= {{5, 10 }, {15, 20, 25}, {30, 35}}; a. 20 b. 30 c. 35 d. 15arrow_forwardAny time you design code with an artificial limit someonewill exceed it. For example, consider the code:void err(const char* const fmt, int a = 0, int b = 0, int c = 0, int d = 0, int e = 0){ fprintf(stderr, "Fatal Error:\n"); fprintf(stderr, fmt, a, b, c, d, e); fprintf(stderr, "\n"); abort();}Now this works if you wish to write simple messages:err(“Size parameter (%d) out of range”, size);But what happens when we wish to a slightly more complex call?err(“Point (%d,%d) outside of box (%d,%d), (%d,%d)”, point.x, point.y, box.x1, box.y1, box.x2, box.y2);Our function can take a format and up to five parameters. We just gave itsix. It's not going to work.Now we could fix the err function to add another parameter, but thatwould only work until we needed seven parameter. Another change would beneeded at eight and so on.arrow_forward
- Write a java code for the following. Write two methods that return the union and intersection of two arrays of integers using the following header: public int [ ] union(int arr1[ ], int arr2[ ] ) public int [ ] intersection(int arr1[ ], int arr2[ ]) For example, the union of two array lists {2, 3, 1, 5} and {3, 4, 6} is {2, 3, 1, 5, 3, 4, 6} and intersection is {3}. Write a test program that prompts the user to enter two lists of size 4 each, and displays their union and intersection. The numbers are separated by exactly one space in the output.arrow_forwardThis is what I have so far 2. Too few parameters #include <stdio.h> Void simple(); Int main() { Int n; simple(1,2,3,4,5,6,7,8,9,10,11,12); Return0; } Void simple(int n){ printf(“%d”,n); printf(%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d) } What gets printed? The values 1 and the garbage values get printed. Where do the values come from? The values are some random values generated for the storage part failures like this where we are not allocating values but using them. Why? 1 is printed as per the statement. Garbage values are generated because of not having any argument passed to them to locate a specific location. 3. Too small arrayarrow_forwardThis is needed in java Given an array of doubles named heights, change the value at index 12 to 135.9.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education