c109s08t1 - CSE 109 Test 1 Friday 22 February 2008...

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

View Full Document Right Arrow Icon
CSE 109 Test 1 Friday 22 February 2008 >>>>>>>>>>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. Write the output that occurs when the following program is run. #include <iostream> using namespace std; void x(int a, int &b, int &c){ int temp; temp=a; a=b; b=temp; b+=2; c+=a; } void y(int *a, int *&b){ *a+=2; b=a; *b+=3; } void z(int *a, int *&b, int *&c){ int *temp; temp=a; a=b; b=temp; c=a; } int main(){ int u=2, v=3, w=4, *r, *s, *t; x(u,v,w); cout<<u<<" "<<v<<" "<<w<<endl; <<<<<<<< 2 4 7 u=2; x(u,u,u); cout<<u<<endl; <<<<<<<< 6 s=&u; t=&v; u=2; v=3; y(s,t); cout<<u<<" "<<v<<" "<<*s<<" "<<*t<<endl; <<<<<<<< 7 3 7 7 s=&u; u=2; y(s,s); cout<<u<<" "<<*s<<endl; <<<<<<<< 7 7 u=2; v=3; w=4; r=&u; s=&v; t=&w; z(r,s,t); cout<<*r<<" "<<*s<<" "<<*t<<endl; <<<<<<<< 2 2 3 } 2. Write a function select() that reads text from an input stream and writes to the console only those characters that are in a given string. For example, the code istream f("input.dat"); select(f,"12345.!"); would display on the screen only those characters in the file 'input.dat' that match one of '1', '2', '3', '4', '5', '.', and '!'. You should include documentation of pre- and post-conditions for this function.
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
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /*Purpose: display on the screen only those characters in the file "in"
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