Homework 1 - none are replaced d) cout << “a =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Ford Kirkland (tfk3) Homework #1 1. What, if anything, prints when each of the following C++ statements is executed? If nothing prints, then answer “nothing” Assume x=2 and y=3. a) cout << x; 2 b) cout << x + x; 4 c) cout << “x =”; x = d) cout << “x = “ << x; x = 2 e) cout << x + y << “ = “ << y + x; 5 = 5 f) z = x + y; nothing g) cin >> x >> y ; nothing h) // cout << “x +y = “ << x + y; nothing I) cout << “\n”; \n 2. Which of the following C++ statements contain variables whose values are replaced? Specify those variables. a) cin >> b >> c >> d >> e >> f; All are replaced b) p = i + j + k -7; p is replaced c) cout << “Values of a and b are:” << a<<’ ‘ << b;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: none are replaced d) cout << “a = 5”; none are replaced 3. a) y = 2 * x * x * x + 5/(x+1); Correct b) y = 2 * (x * x * x + 5)/(x+1); Incorrect c) y = ( 2 * x ) * x * ( x + 5 ); Incorrect d) y = (( 2 * x ) * x * x + 5)/(x+1); Correct e) y = (2 * ( x * x * x ) + 5)/x+1; Incorrect f) y = (2 * x^3+ 5)/(x+1); Incorrect 4) State the order of evaluation of the operators in each of the following C++ statements and show the value of x after each statement is performed. a) x = 8 + 4 * 10 / 2 – 1; 4*10=40/2=20-1+8=27 b) x = 4 % 4 + 4 * 4 – 4 / 4; 4%4=0*4=0/4=0+4-4=0 c) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) ); 9*3=27/3=9+3=12(3*9)=(12*27)=324...
View Full Document

This note was uploaded on 04/07/2011 for the course EEL 0565 taught by Professor Khabou during the Spring '11 term at W. Florida.

Page1 / 2

Homework 1 - none are replaced d) cout << “a =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online