c17su02t1 - CSc 17 Test 1 6 June 2002 >SUGGESTED ANSWERS<...

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 6 June 2002 >>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<< 1. (20 pts) Given some function "statement()" and the code for(int j=0;j<n;j+=3) statement(j); a) Write a while loop which has the same effect as the above for loop b) Write a do-while loop which has the same effect as the above for loop --------------------------------------------------------- int j; j=0; while(j<n) {statement(j); j+=3; } int j; j=0; if(j<n) do {statement(j); j+=3; }while(j<n); 2. (20 pts) Given the code int j,k; cin>>j>>k; if(j>k || k>2) if(j<k && k<4) cout<<1; else cout<<2; else if((j==k)==(k==4)) cout<< 3; switch(j+k) {case 1: case 2: cout<<4; case 3: break; case 4: cout<<5; default: cout<< 6; } State the output if the user enters (in the given order on the line) a) 1 3 b) 4 2 c) 0 1 d) 8 -6 e) 1 2 -------------------------------------------------------------- 156 26 34 24 3 3. (20 pts) Given the functions void out(int x[]) {cout<<x[0]<<" "<<x[1]<<" "<<x[2]<<endl;} void v(int a, int&b, int&c) {a=b+c; b+=c; c+=b; } State the output when the following code is executed:
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
int x[]={1,2,3}, y[]={1,2,3},z[]={1,2,3},w=2; v(y[0],y[1],y[2]); out(y); v(x[1],x[0],x[2]); out(x); v(z[0],z[1],z[0]); out(z); v(w,w,w); cout<<w<<endl; -------------------------------- 1 5 8 4 2 7 4 3 3 8
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ 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