COSC1410-Exam2-Jones-Key

COSC1410-Exam2-Jones-Key - COSC1410 Dr. Jones COSC 1410...

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

View Full Document Right Arrow Icon
COSC1410 Dr. Jones COSC 1410 Exam #2 Your Name: _________ KEY ___________ TA Name:___________________ 1. What is the value assigned to the variable in each of these cases? Explain the results. double z, w, t; a) z = 1/2; b) t = 3.0/2.0; Answer: (4 points) a) 0 is calculated because 1/2 is done with truncating integer divide, gives 0. The floating point value 0.0 is stored. b) 1.5 is calculated and stored. 2. Assume variables first and second are declared to be double and are initialized. Write a sequence of lines of code that cause the values stored in first and second to be exchanged if the value of first is not less than second . Answer: (6 points) // double first, second; // these have been initialized if (!(first < second)) { double temp = first; first = second; second = temp; } //assert: first <= second
Background image of page 1

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

View Full DocumentRight Arrow Icon
Page 2 3. Write Boolean expressions that represent the given English expressions. Assume any variables used have been declared and initialized. a) x and y are odd b) ch is an upper case alphabetic character (between 'A' and 'Z' ). Answer: (6 points) a. b. 4. Write Boolean expressions that represent the given English expressions. Assume any variables used have been declared and initialized. a) at least one of x or y is odd b) at least one of x or y is non-negative ( x is non-negative is written x >= 0) c) x is 1 or x is equal to y Answer: (6 points) a) (x%2==1) || (y%2==1) b) (x >= 0) || (y>=0) c) (1==x) || (x==y) 5. What is the output from each of the following loops? a) while ( 0 )
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

COSC1410-Exam2-Jones-Key - COSC1410 Dr. Jones COSC 1410...

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

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