In-Class Materials

In-Class Videos (These were recorded during this class, and are made available here in case you want to refer to them later)

Instructor's Materials:
Notes

These notes are for the instructor’s use, and not meant for public consumption.
They're posted here on the off chance that you find them useful - If they help you, that’s great.  If not, please just ignore them :)

Starter Project for the In-Class Exercises

Part 1: Integer Division

HIDDEN INSTRUCTOR NOTES

The revised expression eval really helped with this.  Since the students were used to annotating things with the data type it made the whole 'integer division happens when you divide two integers' thing a lot easier.

For this lecture I just put

int num = 11;

double dnum = 11.0;

Console.WriteLine( 11.0 / 2 ); // what does this produce?

Console.WriteLine( 11 / 2 ); // what does this produce?

We annotated each value with it's type, then revealed the output that is produced.  Then defined int div (do normal div, then drop everything after the decimal place) and what causes it ( int  / int )

Then showed how 11.0 / 2 converts 2 to a double, just like in the expression eval.

Then fiddled with the replacing numerator with variables.

Then explained that one should choose the data type based on what makes sense for the data (example: how many students are going on a field trip?)

Showed them typecasting (  (double) num / 2  )

Set them loose on the exercises

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.

Here are the same lines of code, included here for your convenience:

	Console.WriteLine(" 7 / 4 = {0}", 7 / 4); // Question #1
	Console.WriteLine(" 7 / 3 = {0}", 7 / 3); // Q #2
	
	Console.WriteLine(" 3 / 4 = {0}", 3 / 4); // Q #3
	Console.WriteLine(" 2 / 4 = {0}", 2 / 4); // Q #4
	Console.WriteLine(" 1 / 4 = {0}", 1 / 4); // Q #5
	
	Console.WriteLine(" 7.0 / 4 = {0}", 7.0 / 4); // Q #6
	Console.WriteLine(" 7 / 3.0 = {0}", 7 / 3.0); // Q #7
	Console.WriteLine(" 7.0 / 2.0 = {0}", 7.0 / 2.0); // Q #8
	
	Console.WriteLine(" (double)7 / 4 = {0}", (double)7 / 4); // Q #9
	Console.WriteLine(" 6 / (double)4= {0}", 6 / (double)4); // Q #10
	Console.WriteLine(" (double)5 / (double)4 = {0}", (double)5 / (double)4); // Q #11
	
	int numPeople = 10;
	int numSeats = 20;
	double galOfWater = 7.0;
	double BucketSizeInGal = 10;
	
	// For the following, what output is produced 
	// AND
	// which lines produce the right answer?
	Console.WriteLine(" % of seats that are occupied = {0}", numPeople / numSeats); // Q #12
	Console.WriteLine(" % of seats that are occupied = {0}", numPeople / 20.0); // Q #13
	Console.WriteLine(" % of seats that are occupied = {0}", numSeats / numPeople); // Q #14
	Console.WriteLine(" % of seats that are occupied = {0}", (double)numPeople / numSeats); // Q #15
	Console.WriteLine(" % of seats that are occupied = {0}", numPeople / (double)numSeats); // Q #16
	
	// For the following, what output is produced 
	// AND
	// which lines produce the right answer?
	Console.WriteLine(" % of the bucket that is filled = {0}", galOfWater / BucketSizeInGal); // Q #17
	Console.WriteLine(" % of the bucket that is filled = {0}", BucketSizeInGal / galOfWater); // Q #18
	Console.WriteLine(" % of the bucket that is filled = {0}", (double)galOfWater / BucketSizeInGal); // Q #19           
            

Part 2: Modulus: By Hand

HIDDEN INSTRUCTOR NOTES

Started by showing long division of 7 / 2 (3 R 1 ), pointing out that int div gets you to the 3, modulo gets you the 1 (aka 'remainder operator' in C#)

Pointed out that we only ever use this on integers

Pointed out that % is used because it kinda looks like division ( / ), but it's also different

Did another example

Set them loose on the exercises

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

For the following exercises, assume that they're being executed after the following code:

	int numStudents = 17;
	int seatsOnEachBus = 10;
  1. Console.WriteLine("What will this produce #1? {0}", numStudents % 2;
  2. Console.WriteLine("What will this produce #2? {0}", 7 % seatsOnEachBus;
  3. Console.WriteLine("What will this produce #3? {0}", numStudents % seatsOnEachBus;
  4. Console.WriteLine("What will this produce #4? {0}", seatsOnEachBus % numStudents;
  5. int fullBusses = numStudents / seatsOnEachBus;
  6. int studentsWithoutABus = numStudents % seatsOnEachBus;

 

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)