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++ 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
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 = ______________                                                                                                                                                                                                   ...
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...
Given the following code: public void expand(Object a) {     // assume element has enough capacity...
Given the following code: public void expand(Object a) {     // assume element has enough capacity     for (int i = size - 1; i >= 0; i--) {         element[4 * i + 3] = a;         element[4 * i + 2] = a;         element[4 * i + 1] = a;         element[4 * i] = element[i];      }      size = 4 * size; } element is a one-dimensional array that stores elements of the type Object....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
php please shiftNTimes // Modify array so it is "left shifted" n times -- so shiftNTimes(array(6,...
php please shiftNTimes // Modify array so it is "left shifted" n times -- so shiftNTimes(array(6, 2, 5, 3), 1) // changes the array argument to (2, 5, 3, 6) and shiftNTimes(array(6, 2, 5, 3), 2) // changes the array argument to (5, 3, 6, 2). You must modify the array argument by // changing the parameter array inside method shiftNTimes. A change to the // parameter inside the method shiftNTimes changes the argument if the // argument is passed...
2- Use a conditional operator to fill in the underlined part of the "cout" statement to...
2- Use a conditional operator to fill in the underlined part of the "cout" statement to make the following code prints either “is equal to C++” or “is not equal to C++” depending on value of the string. Put your entire code only inside the blank spaces in parentheses and do not modify other parts of the code. (4 pts): string st; cout << "Enter a string:"; cin >> st; cout << "String " << st <<              (........................................................................................) ; 3-...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT