c17s98t2

c17s98t2 - CSc 17 Test 2 Friday 27 March 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 2 Friday 27 March 1998 Page 1 >>>>>>>>>>>>>>>>>>>>>ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<< 1. (10 pts) In writing the function below, I forgot to provide the documention. Provide it by stating the pre- and post-conditions. void x (int y[], int m, int n) //Pre-Condition: 0<=m<=n //Post-Condtions: The numbers originally appearing in y[m]. ..y[n] // are now in reverse order { int t; do { t=y[m]; y[m]=y[n]; y[n]=t; m++; n--; } while (n>m); } 2. (15 pts)Rewrite the following code using only a switch statement. if ( x==1) y=2; else if (x==2) y=7; else if (x==5) y=8; else if ( (x==7) || (x==9)) y=10; else y=13; switch (x) { case 1: y=2; break; case 2: y=7; break; case 5: y=8; break; case 7: case 9: y=10; break; default: y=13; } 3. (25 pts) In many applications the values of a variable cannot be outside some range, e.g., 0.0<=GPA<=4.0, 0<=PERCENT<=100, 0<=AGE<=150. Consider an ADT, for example, with the following properties. Each instance of the ADT stores an integer between 20 and 50 inclusive. One can perform addition, subtraction,
Background image of page 1

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

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

Page1 / 2

c17s98t2 - CSc 17 Test 2 Friday 27 March 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