{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info iconThis 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.
Background image of page 1

Info iconThis 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"
Background 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 ]}