Question

The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array....

The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array. It stores 4 and 5 as the first and second elements, respectively, of the array. It adds the first and second elements of the array and stores their sum as the third element of the nums. It prints the third element of nums. It then adds the second and third elements of the array and stores their sum as the fourth element of nums. Finally, it prints the fourth element of nums. Do not add numeric literals for either the second blank on line 4 or the second blank of line 6. Use expressions involving the addition of array elements for each blank. Complete the code segment. [15 points]

Listing 1: Code Segment
----------------------------------------------------------------------
1. int nums ______;
2. nums _____ = 4;
3. nums ____ = 5;
4. nums ___ = ___ ;
5. cout<<"third element: "<<nums____<<endl;
6. nums____ = ____;
7. cout<<"fourth element: "<<nums____<<endl;

B. From the choices given, select the alternate execution sequence(s) for which the end-user of the code segment experiences the same interactivity.

Answer

A.)only i, ii and vii only

B.)ii only

C.)iii and iv

D.)ii and iv  [5 points]

i. 1, 2, 3, 4, 5, 7, 6
ii. 1, 3, 2, 4, 5, 6, 7
iii. 1, 3, 2, 6, 5, 4, 7
iv. 1, 3, 2, 4, 6, 7, 5
v. 1, 2, 3, 4, 6, 5, 7

Homework Answers

Answer #1

A.

//c++ program completion of code segment

#include <iostream>
using namespace std;

int main() {

//initialising array
int nums[4];
nums[0]=4;//first element in array
nums[1]=5;//second element in array.
nums[2]=nums[0]+nums[1];//adding first and second element and store as third element.
cout<<"Third element "<< nums[2]<<endl;//printing third element.
nums[3]=nums[2]+nums[1];//adding second and third element and store in fourth element.
cout<<"fourth element "<< nums[3]<<endl;//printing fourth element.

return 0;
}

screenshot of code and output is as follows:

Please refer to the screenshot of the code to understand the indentation of the code.

B.

option B, II only.:the sequence ii only follows alternate solution.

from the figure ,only option 2 follows the alternate solution of the code segment.others do not follow the order.

The ii follows the same addition order of the code segment.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...
Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between 1 and 100. 2- Moves all multiple of 3-numbers in the array that created in part-a into a new array. 3- Moves all multiple of 5-numbers in the array that created in part-a into a new array. 4- Find the maximum and the minimum multiple of 3-numbers, if exist. 5- Find the maximum and the minimum multiple of 5-numbers, if exist. 6- Prints the...
C ++ program that will read in prices and store them into a two-dimensional array //...
C ++ program that will read in prices and store them into a two-dimensional array // It will print those prices in a table form and the lowest price. // EXAMPLE // Input: // Please input the number of rows from 1 to 10 // 2 // Please input the number of columns from 1 to 10 // 3 // // Input price of item (0,0): 2 // Input price of item (0,1): 4 // Input price of item (0,2):...
Write a MIPS assembly program that sorts an array using bubble sort translating the C code...
Write a MIPS assembly program that sorts an array using bubble sort translating the C code int main(void) { int array[] = {10, 2, 7, 5, 15, 30, 8, 6}; // input array int arraySize = sizeof(array)/sizeof(array[0]); bool swapped = true; int j = 0; int tmp; while (swapped) { swapped = false; //Note : "j" , "arraySize - j" are optimizations to the bubble sort algorithm j++; // j= sorted elements int i=0; /* "arraySize - j" is used...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
In java 1. Write a recursive algorithm to add all the elements of an array of...
In java 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C. 4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
Giving an array of integers A[1:8] ={5, 1, 3, 2, 7, 6, 8, 4}. Build a...
Giving an array of integers A[1:8] ={5, 1, 3, 2, 7, 6, 8, 4}. Build a MAX-HEAP on A. Show the steps using binary tree representation or array view. Use heap sort: show the array after the first, the second, and the third of heap sort
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
How do I break down a user inputted integer to individual digits and store it into...
How do I break down a user inputted integer to individual digits and store it into my array? I have an if statement that compares the spots of the array to check if it is a palindrome, but I need to make it so the user inputted number is broken up individually into the array. Please break it down into steps so I can understand. #include<iostream> using namespace std; int main() {    char array[6];           cout <<...
Create a 2D numpy array that contains values (4, 3, 1, 33, 21) in the first...
Create a 2D numpy array that contains values (4, 3, 1, 33, 21) in the first row values (67, 27, 89, 34, 67) in the second row and values (60, 99, 89, 12, 43) in the third row Your code should print the following: [[ 4 3 1 33 21] [67 27 89 34 67] [60 99 89 12 43]] Write code that prints values [34, 67] [12, 43]. You must use the colon : based slicing approach to complete...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT