CSE 1302C Final Exam_FA11.docx

advertisement
CSE 1302C Final Exam
Dec. 12th, 2011
Directions: You have 2 hours to complete this exam. All answers are to be your own, without the
assistance of others. If you have a question, please raise your hand. When you are finished, bring the
exam to the front of the room, smile, and then leave. Do BOTH SIDES of this exam. Good luck! As
always, you get +1 point for drawing something.
Question 1 (I/O): 50 pts. Imagine there is a server called “books.com” with port 2000 open for requests.
If you send the server the name of the book you want, it would send back the entire text of that book.
Write a console program that:
1) Asks the user for the name of a book (e.g. “Lord of the Rings”)
2) Connects to the server at books.com and sends the name of the book the user typed in
3) Receives the text of the book (line by line) and writes that data to a file (e.g. “Lord of the
Rings.txt”)
4) HANDLES ANY EXCEPTIONS THAT MAY HAVE OCCURRED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hint: you will probably be working with multiple streams to accomplish this. Also, think about what we
did in class (several times)!
Question 2 (Recursion): 25 pts. What is the complete output of the following code snippet?
static int recurse(int q, int s)
{
Console.WriteLine(q+" "+s);
if (q == 0){
q = s;
s--;
}
if (s == 0) {
return s;
}
return q + recurse(q - 1, s);
}
static void Main(string[] args)
{
Console.WriteLine(recurse(3, 2));
}
Question 3 (2D Arrays): 25 pts. A matrix is considered to be an transpose matrix of another if it is
mirrored along the diagonal (see below for an example). Imagine there are two 100x100 2D arrays of
ints called arrayOne and arrayTwo; both have been allocated (using “new”) and arrayOne has random
data. Write a snippet of code that puts the transpose of the random data from arrayOne into arrayTwo.
1
2
3
6
7
8
11 12 13
16 17 18
[21 22 23
4
9
14
19
24
1 6
5
2 7
10
15 => 3 8
4 9
20
[5 10
25]
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25]
Download