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

Info icon This 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 of x and y. Thus, if x=5 and y=6 before the call, both x and y are 6 after the call.
Image of page 1

Info icon This 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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern