Question

In: Computer Science

I ALREADY HAVE THE CORRECT ANSWERS. CAN YOU EXPLAIN TO ME HOW AND/OR WHY THESE ARE...

I ALREADY HAVE THE CORRECT ANSWERS. CAN YOU EXPLAIN TO ME HOW AND/OR WHY THESE ARE THE ANSWERS? THANK YOU :)

int a(int &x, int y) { x = y; y = x + 1; return y;

}

int b(int &x, int y) { y = x + 1; x = y; return y;

}

void c(int x, int y) { if (x > 2) return; cout << y; c(x + 1, y - 1);

}

int main() {

int x[2][3] = {{1, 2, 3}, {4, 5, 6}};

int y[3] = {7, 8, 9};

cout << x[1][1] << endl;   // line (a)

y[0] = a(y[0], y[1]);

cout << y[0] << y[1] << endl; // line (b)

cout << b(x[0][2], x[1][2]) << endl;    // line (c)

cout << x[0][2] << x[1][2] << endl; // line (d)

c(0, 4); cout << endl; // line (e)

}

(a) What is the output from the instruction beginning on line (a)?

Answer: 5

(b) What is the output from the instruction beginning on line (b)?

Answer: 98

(c) What is the output from the instruction beginning on line (c)?

Answer: 4

(d) What is the output from the instruction beginning on line (d)?

Answer: 46

(e) What is the output from the instruction beginning on line (e)?

Answer: 432

Solutions

Expert Solution

a) x[1][1] refers to element present in 2nd row and 2nd column i.e. 5.

b) when we use call by reference, changes in function parameter are reflected on actual parameters(outside function) i.e. if we send some variable by call by reference to function and we made some changes to that variable inside function , then that changes will get reflected on actual variable which means value of actual variable will get over written by new value.

here y[0]=7 and y[1]=8 sent to function a;

In function

&x=y[0]=7 (call by reference)

y=y[1]=8

x=y(means value of y(i.e 8) will be copied to x(here value of x changed from 7 to 8 as well as value of y[0] is also changed to 8)

y=x+1(y=8+1 i.e y=9)

return y(here y will be returned to main function and value present in y will be stored in y[0])

therefore output of line b

cout << y[0] << y[1] << endl;

output

98

c)Same happen in this part also

x[0][2]=3

x[1][2]=6

in function b

&x=x[0][2]=3

y=x[1][2]=6

y=x+1(y=3+1 i.e y=4)

x=y(x=4 as well as x[0][2]=4)

return y(value of y(i.e. 4 ) will be returned to main function)

therefore output will be 4

d.) Now according to new x ,

x[0][2]=4

x[1][2]=6

therefore output of line d is 46


Related Solutions

Can you please check my answers and if I am wrong correct me. Thank you! A....
Can you please check my answers and if I am wrong correct me. Thank you! A. In today's interconnected world, many central banks communicate regularly and frequently with the public about the state of the economy, the economic outlook, and the likely future course of monetary policy. Communication about the likely future course of monetary policy is known as "forward guidance.". If the central bank increases the reserve ratio, as the market has perfectly expected, which of the following will...
I just wanted to double check my answers, can you just provide me with the correct...
I just wanted to double check my answers, can you just provide me with the correct answer for each one in order to cross-check, thank you. The United States' class system is heavily dependent upon an individual's social background. True False At which level of the factors which put women at risk does the following statement fit? "Tolerance of violence as a means of conflict resolution". Family/Relationship Level Individual Level Community Level Societal Level Which of the following countries is...
I just wanted to double check my answers, can you just provide me with the correct...
I just wanted to double check my answers, can you just provide me with the correct answer for each one in order to cross-check, thank you. When women carry the burden of poverty and are treated as non-equals when compared to men, which of the following terms describes this circumstance? Twice Burdened Double Discrimination Double Deprivation Double Jeopardy Which of the following countries was not a colony of Britain? Singapore Korea Hong Kong In 2012, which country utilized 2.8% of...
The correct answers are already bolded, but please show your work/explain how you get the answer....
The correct answers are already bolded, but please show your work/explain how you get the answer. 1. Rick can cut 6 pieces of wood or catch 6 fish per day. Timmy can cut 9 pieces of wood or catch 18 fish per day. Which one of the following points is not on the Timmy’s production possibility frontier fish is on the horizontal axis and pieces of wood is on the vertical axis? a. (0, 9) b. (18, 0) c. (8,...
Please explain to me the answers so that I can understand the concept. Thank you! You...
Please explain to me the answers so that I can understand the concept. Thank you! You must evaluate a proposal to buy a new milling machine. The purchase price of the milling machine, including shipping and installation costs, is $126,000, and the equipment will be fully depreciated at the time of purchase. The machine would be sold after 3 years for $85,000. The machine would require a $3,500 increase in net operating working capital (increased inventory less increased accounts payable)....
i have 2 chemistry questions. please give me correct answers. thank you . 1. Calculate the...
i have 2 chemistry questions. please give me correct answers. thank you . 1. Calculate the pH of a 0.23 M solution of acetic acid (CH3COOH). DATA : pKa (CH3COOH) = 4.76 Answer: 2. Calculate the pH of a 0.37 M solution of potassium cyanide (KCN). DATA : pKa (HCN) = 9.21 Answer:
Can you please confirm if the answers are correct. Thank you Carol has already purchased Inventory...
Can you please confirm if the answers are correct. Thank you Carol has already purchased Inventory of $10,000 Carol has already purchased $10,000 in equipment. Carol will also keep a $10,000 as a Beginning Cash Balance. Carol will have Accounts Payables of $10,000 (supplier credit for the inventory). Carol’s friend who owns a Fitness Equipment store has agreed to give Benny a 1-year loan for the equipment needed of $10,000 (10% annual interest rate) (this will be paid back with...
Can someone please explain how to do the steps for this? I already have part a...
Can someone please explain how to do the steps for this? I already have part a completed but I need help with b-e. Thank you. Problem 1: (a) What is spurious regression? Explain. (b) Assuming , randomly generate 1000 observations of variables X and Y using the following equations: Report the graphs of X and Y. (c) Run the regression: and report the estimated results. (d) What did you expect about the magnitudes and R-square? How are the estimated values...
I was wondering if you can tell me if the following code is correct and if...
I was wondering if you can tell me if the following code is correct and if its not can it be fixed so it does not have any syntax errors. Client one /** * Maintains information on an insurance client. * * @author Doyt Perry/<add your name here> * @version Fall 2019 */ public class Client { // instance variables private String lastName; private String firstName; private int age; private int height; private int weight; /** * First constructor for...
can you check if my answers are correct and can you please type the correct answers...
can you check if my answers are correct and can you please type the correct answers for each question 5 points) Trevor is interested in purchasing the local hardware/electronic goods store in a small town in South Ohio. After examining accounting records for the past several years, he found that the store has been grossing over $850 per day about 60% of the business days it is open. Estimate the probability that the store will gross over $850 at least...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT