c17f98t1 - CSc 17 Test 1 Friday 2 October 1998 Page 1...

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

View Full Document Right Arrow Icon
CSc 17 Test 1 Friday 2 October 1998 Page 1 >>>>>>>>>>>>>>>>>>>>>>>ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. Assume that we have #include<math.h>. Explain why the segment of code in (a) causes a run-time error (i.e., crashes) and why the segment of code in (b) executes without a run-time error (i.e., does not crash). (4 pts) (a) x=-5; if (sqrt(x)>1 || x<0) cout<<x; (11 pts) (b) x=-5; if(x<0 || sqrt(x)>1) cout<<x; (a) Taking the square root of a negative number (DOMAIN error). (b) The expression "sqrt(x)>1" never gets evaluated, because the expression "X<0" is true ("Shortcut evaluation") 2. (10 pts) Write out the value of each of the following expressions: (a) 7+6*5/4%3 8 (b) 7+6*5/4.0 14.5 (c) 7.6345-int(7.9345) 0.6345 (d) (!(2>3) && (4<5)) true (e) ( ( (2>3) && (4<5) ) == (1==2) )== (4==5) false 3. (25 pts) Write a function bigBoy with the following properties. When we have the declaration "double x,y;" the call bigBoy(x,y) returns the smaller of x and y, and after the call both x and y contain the larger
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '08
  • varies
  • United States Declaration of Independence, Following, Negative and non-negative numbers, The Declaration, Run time

{[ snackBarMessage ]}

Page1 / 3

c17f98t1 - CSc 17 Test 1 Friday 2 October 1998 Page 1...

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