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.

Part 1: Review: PCE 01 (Optional)

This exercise is actually a quick review of some of the PCEs from Lesson 01.  While not every set of In-Class Exercises will start with such a review, the instructor felt that it would be good to do a quick check-in and verify that everyone understands some of the basic skills that were covered in the previous lesson.

For this exercise you should partner up with someone (triples are ok only if there is an odd number of people).  You & your partner should download the starter project for the In-Class Exercises and make sure that you're able to compile and run it (note that the project should not do anything just yet). 

Next, add a class into the file (there's a comment to help remind you where to put it), and in that class put a RunExercise method.  Within that method start by printing out a message asking the user to type in a number. 

(While you're free to do the entire exercise all at once I would recommend that you get the program to compile and run at this point in order to confirm that the program is doing what you want it to.  In general I would recommend frequently checking your program as you're developing it).

Once that's done you should actually get the number that the user has typed in, and print that number back to the user.

Note: There should be a folded-up #region within the provided program.  If it's not folded up you should fold it by clicking on the box in the left margin, next to the word #region.  If it is folded up (as it hopefully should be) then keep it closed, just so that you don't accidentally give yourelf the answer by seeing it in the provided code for a future exercise.

Part 2: Integer Division

For this exercise you should examine the class named IntegerDivision in the provided starter project.

Within that class you should examine the RunExercise method, and write down what the output of each of the different lines of code will be BEFORE you run the program.  Once you've done that you should then run the program and compare the actual output to your predicted output.  Go back & reexamine anything that you got wrong, and make sure that you're clear on why the correct answer is, in fact, correct.

A great place to write down your answers is in the C# source code file, in comments next to the line that produces the output.

Part 3: Modulus: By Hand

For this exercise you should write out (by hand, on paper) the result of doing the following operations:

  1. 10 % 2
  2. 10 % 5
  3. 13 % 7
  4. 10 % 10
  5. 2 % 10
  6. 5 % 10
  7. 93 % 107
  8. 107 % 93

Part 4: Modulus: By Computer

For this exercise you should fill in the missing code within the ModulusExericse.RunExercise method (this means the RunExericse method in the ModulusExericse class). 

The program will help the user figure out how many buses are necessary to transport a given number of people.  The program should ask the user for the total number of people, and how many people each bus can hold.  You will need to use the various, mathematical operations that we've studied to determine how many buses are needed to transport all those people (assuming that you pack each and every bus completely full, except (possibly) for the last bus).  You also need to tell the user how many people are actually on the last bus (this may very well be less than the capacity of the bus)

Part 5: Evaluating Expressions: Order of operations & data types

For each expression in the left-hand column, show how C# evaluates the expression.  This means that you should re-write the expression after each individual operation (such as +, -, etc.), so that it's clear both what happens, and in what order stuff happens in.  You should also be sure to clearly indicate the correct type at each stage of the computation (e.g., 7.0 rather than 7 for a double, Strings in quotes, etc.).

  1. 16/3 + 3.2 * 2
  2. 8/7 + "5/4" + 8/3
  3. 88 % 10 % 3 * 16/10
  4. 29/3/2/4.0 + 3.6 * 2
  5. 1.4 + (3 + 2 * 6)/(8 - 14/3) * 2.2

Part 6: Conditional Statements: If/Else and Switch

For this exercise you should examine the class named ConvertSwitchToIfElse in the provided starter project.  You should take the provided code (most importantly, the switch statement) and convert into equivalent C# source code that only uses if and if/else statement(s) to accomplish the same task.

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://oncourseworkshop.com/self-awareness/one-minute-paper/).

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 the questions listed therein - it should take a couple minutes or so.

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