You should predict what each of the following expressions will evaluate to, given reasonable values for the variable f. (Note that since you are not being given specific values of f you may not be able to predict exact values of celsius.
When doing these, remember the order of operations (just like math class), and remember to track the data type of the values and variables (unlike math class). Here's a (potentially) useful link: Precedence and Order of Evaluation in C#
Example:
int f = /* exact value omitted */
double celsius = (5 / 9 ) * ( f - 32 );
The second statement will be evaluated in the following steps:
Thus, celsius will always have the value zero, regardless of what value f contains
Within the starter project you'll see a class named Loops, and within that you'll see a method named RunExercise (this is normally refered to using ClassName.MethodName, as in Loops.RunExercise). Loops.RunExercise in turn calls three other methods, each of which repeats some action several times (in each method).
Your task is to work with a partner and examine each of the three methods in turn. You'll notice that within each method, the same task is done several times - each time with a different type of loop. Your job is to compare and contrast the different loops - discuss both the advantages of each type of loop, as well as the disadvantages of each type of loop, for the given task.
Be ready to summarize and explain your list of pros and cons (for each type of loop within a given task) for the rest of the class.
Within the starter project you should examine the IncrementDecrementCompound.RunExercise method in detail. You should predict what the output of the method will be (and you should write down your prediction - either on paper or in an electronic format) AND THEN run the program in order to check your results. If the actual output differs from your output in any way you should figure out what went wrong with your prediction.
For each loop you should be prepared to explain why the code produces the answer it does.
Within the starter project you should examine the Random_Problems.RunExercise method in detail - feel free to run the method, if you want.
You need to fix all the errors in that method, so that the method will do the following:
Within the starter project you should fill in the Random_Via_Modulus.RunExercise method so that it will print out 10 random, whole numbers that range from 0 to 3 (including, possibly, 0 and 3). For this exercise you can only use the version of .Next that takes no parameters (there's an example in the method already). In other words you'll need to use the modulus operator to limit the possible random numbers that you might generate.
Once you've gotten that first part done, you should have this method also generate random numbers in the following ranges:
[0,3] (this was the range described above - it's numbered here so y'all can put your answers on the white board to discuss them)
[1, 10]
[-4, 10]
[2,20], but ONLY the even numbers (this will require more than 1 line of code)
Be ready to explain your answers to the rest of the class (both by giving the formula, and by explaining how the formula accomplishes the given task)
For this exercise you will take the following code and paste into the provided starter project, then find and fix all the errors in the code so that the Add method works as described here. While it's recommended that you put this code into the Params_Return_Values class, you are not required to.
The Add method should take two parameters, add them up,and return the sum of the two numbers. The Add method should compile and run with all of the examples listed in the RunExercise method, below:
public void RunExercise() { double result = Add(3, 5); Console.WriteLine("3 + 5 is: {0}", result); Console.WriteLine("3.1 + 5 is: {0}", Add(3.1, 5)); Console.WriteLine("3.1 + -5.7 is: {0}", Add(3.1, -5.7)); } // paste the functions (methods) here public int Add( a, b) { int sum = a + b; return sum; }
public static void Main() {
Program theObject = new Program(); theObject.RunExercise();
}
Review: Evaluating logical expressions?
Params & return values: Writing up a small function?
Student Code Samples
PEX for fun?
Skipped loops, increment, did the rest. Did explain increment in class, briefly
"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 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.