Lesson 02 In-Class Exercises

Before starting any specific exercise, you may wish to download, extract, and open up the provided starter project for this lesson so that you'll have it ready when you need/want it.

1) Debugging

Download, extract, and open up the provided starter project for Visual Studio.  In the Program.cs file you will find at least three classes that contain code for you to debug. The classes will have names like "Debugging_Problem_1", and they all contain a method named "DebugThis" that you should debug.

The goal here is to make sure that you're comfortable and confident using Visual Studio's debugger, so focus less on fixing the bug(s) by staring at the code real hard (which is the typical way that students fix errors prior to learning about the debugger) and instead focus on using the tools the debugger provides in order to get the debugger to show you what the program is doing.  Make sure that you use all of the following

Be prepared to demonstrate to the rest of the class how you got the debugger to show you how the program executed.  Make sure that you're able to use each of the above tools/techniques, and that you can show how they were useful in detecting & fixing the problem(s) in each of the classes.

2) Enums: Enums Used As Return Values

We'll use enums as return values in order to convey rich information about why a method failed back to the calling functions.  While this is an older style of programming (now-a-days we would mostly use exception handling to convey failure information) it's often still useful, and it's good to be familiar with it.

For this exercise you should create a method named WhatSortOfNumber.  This method is given an integer, and it will return an enumeration (which you must define on your own).  The method should indicate if the number is positive, negative, or zero.  You must add as much code as you need to the Enum_Practice.RunExercise method so that you can actually test your WhatSortOfNumber method.

3) Enums: Enums Used As Parameters: Practice

A much more common way to use enums is to allow a calling method to pass rich information to a called method by using a enum type for a parameter.  You could use an integer but the enum is more type-safe (i.e., the compiler can catch errors easier).

For this exercise you need to make a method called MathOps(double x, double y, Operation ). The method should perform the operation specified by the Operation parameter on the pair of double parameters.  So if Operation.Subtract is specified, the method should return x - y.  For convenience, here's the Operation enumeration (make sure to implement all the operations!)

 enum Operation
{
Add,
Subtract,
Multiply,
Divide
}

4) Enums: Enums Used As Parameters: Discovery

enums are used in the C# / .Net Framework Class Library (FCL) in order to control how you might open a file.  Briefly look at File.Open(String, FileMode, FileAccess) method, specifically the FileMode and FileAccess parameters for more information about this.

For this exercise you should examine the above method call look into how you can do the following.  For each one you should write down the line of code that you think probably ought to accomplish the given task.  In the interest of time you do not need to actually make these all compile and run, instead just make your best guess:

  1. Opening an existing file in order to read the contents of the file.

  2. Add new logging information to the end of a file.  If the file doesn't exist then a new one should be created

  3. A record of high scores should be written into a file.  Since the high scores are only for a game, any existing high score file should be replaced with the new scores.

If you have free time and would like to actually make the code compile and run for the above examples please feel free to do so, but ONLY AFTER YOU'VE GONE THROUGH AND WRITTEN DOWN YOUR BEST GUESS FOR EACH OF THE ABOVE!!

Be prepared to explain to the rest of the class your choices for the    

5) Big Oh Review

Within the provided starter project, examine the several methods within the BigOhReview class - they'll have named like Method_1, Method_2, etc.  For each one, see if you can figure out what the running time is in Big Oh notation.  If you decide, for example, the running time of a given method was O( N ) be sure to specify what the "N" represents.

One Minute Paper

"A “one-minute paper” may be defined as a very short, in-class writing activity (taking one-minute or less to complete) in response to an instructor-posed question, which prompts students to reflect on the day’s lesson and provides the instructor with useful feedback." (from http://www.oncourseworkshop.com/Awareness012.htm).

For this One Minute Paper, I would like you to think back on both the preview videos / viewing quiz and today's in-class exercises, and quickly write up answers to two questions:

  1. What was the thing that you were most confused about at the start of this lecture? (Also let me know if you're still confused about this)
  2. Which of the in-class exercises and activities were most helpful to you, and why?

Head on over to the Google Docs form, and fill out the One Minute Paper for this lecture.