CSE 1302C Final Exam SP12.docx

advertisement
CSE 1302C Final Exam
5/2/12
Directions: You have 2 hours to complete this exam. It is to be done without the assistance of others.
Name:_________________________
Question 1: Imagine you have a computing course with 10 students and each student has 10 lab grades.
All of these grades are stored in a 2D array of integers called ‘labGrades’ that has already been declared
and already contains the lab grades of each student. Write a snippet of code that determines which row
has the highest lab grade average, and what that average is. For example, the output could be “Row 5
has the highest lab average of 95.6”.
Question 2: Assume that you have a class called “Turtle” defined below. Create a class called
“AttackTurtle” that inherits from Turtle. AttackTurtles move much faster than regular Turtles (it’s up to
you how fast) and also have a number of missiles that they can carry, though the number varies. They
should also define an “Attack” method – which decreases the number of missile by 1- as well as an
appropriate constructor
public class Turtle
{
int maxWeight;
float speed;
public Turtle(float speed)
{
this.maxWeight = 10;
this.speed = speed;
}
public virtual void moveFaster()
{
speed++;
}
}
Question 3: What is the output of the following code? Again, please be careful with your additions
and/or multiplications!
static int recurse(int num1, int num2)
{
Console.WriteLine(num1 + ":" + num2);
if (num1 > 10)
{
return num2;
}
else
{
num1 += 2;
num2 -= 2;
return num1 * num2 + recurse(num1, num2);
}
}
static void Main(string[] args)
{
int result = recurse(3, 7);
Console.WriteLine(result);
}
Question 4: Imagine there is a server out there called “Dropbox.edu” that stores files that you send it. It
does this on port 81. Write a program that sends an existing file called “bob.txt” to Dropbox.edu (i.e. it
opens that file and sends it line by line to the server). YOU MUST HANDLE ANY EXCEPTIONS THAT
MIGHT OCCUR. For simplicity, you can assume that bob.txt is in the same directory as your program (i.e.
don’t worry about “../../../”).
Download