c17s98t2

# c17s98t2 - CSc 17 Test 2 Friday 27 March 1998 Page 1...

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

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, multiplication, and division with two instances of the ADT and produce an instance of the ADT, provided the result lies between

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern