c17f00t1 - CSc 17 Test 1 Wednesday 18 October 2000...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 17 Test 1 Wednesday 18 October 2000 >>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<< 1. (12 pts) Assume the statement if(x<y) if(x<5) cout<<'D'; else if(x>77) cout<<'A'; else cout<<'B'; is preceded by one of the four pairs of statements below. State the output that occurs for each pair a) x=61; y=8; <no output> b) x=4; y=7; D c) x=50; y=60; B d) x=80; y=90; A 2. (8 pts) State the output of the following code. char *ch="Hello"; ch[2]='\0'; cout<<(2+4*5%6)<<endl; 4 cout<<(2+3/4/5.0)<<endl; 2 if(!(2>3) && 4==4) cout<<'A'<<endl; A else cout<<'B'<<endl; cout<<ch<<endl; He 3. (12 pts) State the output of the following main program. void func(int a, int &b, int &c, int *d, int *&e){ d=&c; e=&b; a++; b+=a; c+=b; cout<<a<<" "<<b<<" "<<c<<endl; } void main(){ int x,y,z, *tPt,*vPt; x=1;
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
y=5; z=10; tPt=&y; vPt=&x; func(x,y,z,tPt,vPt); 2 7 17 cout<<x<<" "<<y<<" "<<z<<endl; 1 7 17 x=10; y=20; func(x,x,x,tPt,vPt); 11 42 42 cout<<x<<" "<<*tPt<<" "<<*vPt<<endl; 42 42 42 } 4. (25 pts) Write a recursive function, sum(), which computes the sum of the elements of an array of ints using the following algorithm: to sum the elements a[low] through a[high], inclusive, add a[low] and a[high] to the
Image of page 2
Image of page 3
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