CS133S Programming in C# I Archives

Wednesday
Jun012011

Wednesday's In-Class Demos

Wednesday
May252011

Today's Demo Code

Sunday
May222011

Possible Solutions for Non-Credit Exercises #1

Here are some possible solutions for the first set of non-credit exercises.

Write an application that asks the user to enter two integers, obtains them from the user and displays their sum, product, difference and quotient (division).

int firstNumber;
int secondNumber;

Console.Write("Enter an integer: ");
firstNumber = int.Parse(Console.ReadLine());

Console.Write("Enter another integer: ");
secondNumber = int.Parse(Console.ReadLine());

Console.WriteLine("The sum of {0} and {1} is {2}, \nthe difference is {3}, \nthe product is {4}, \nand the quotient is {5}",
firstNumber, secondNumber, firstNumber + secondNumber, firstNumber - secondNumber, firstNumber * secondNumber, firstNumber / secondNumber);

Write an application that asks the user to enter two integers, obtains them from the user and displays the larger number followed by the words “is larger”. If the numbers are equal, display the message “These numbers are equal”.

int firstNumber;
int secondNumber;

Console.Write("Enter an integer: ");
firstNumber = int.Parse(Console.ReadLine());

Console.Write("Enter another integer: ");
secondNumber = int.Parse(Console.ReadLine());

if(firstNumber == secondNumber)
    Console.WriteLine("These numbers are equal");
else
    Console.WriteLine("{0} is larger.", firstNumber > secondNumber ? firstNumber : secondNumber);

Write an application that reads an integer, then determines and displays whether it is odd or even.

Console.Write("Enter an integer: ");
int number = int.Parse(Console.ReadLine());

Console.WriteLine("{0} is {1}.", number, number % 2 == 0 ? "even" : "odd");

Write an application that reads two integers, determines whether the first is a multiple of the second and displays the result.

Console.Write("Enter an integer: ");
int firstNumber = int.Parse(Console.ReadLine());

Console.Write("Enter another integer: ");
int secondNumber = int.Parse(Console.ReadLine());

if(firstNumber % secondNumber == 0)
    Console.WriteLine("{0} is a multiple of {1}", firstNumber, secondNumber);
else
    Console.WriteLine("{0} is not a multiple of {1}", firstNumber, secondNumber);
Sunday
May222011

Non-Credit Exercises #2

For your coding pleasure, a second set of non-credit exercises.

Sunday
May222011

Portland Code Camp

Portland Code Camp brings regional software development professionals together for the opportunity to immerse themselves in seminars, presentations, group exploration, and networking. Participants will be able to engage in their preferred technology, as well as to sample other options...

It's scheduled for Saturday, June 4, 2011 at Eliot Center in downtown Portland, Oregon from 8:00 AM until 10:00 PM and is absolutely free!

I've attended Code Camps in the past and they are a blast, I strongly encourage you all to seriously consider going. Check out the list of sessions here and I'm sure you will find many that will interest you. Register today to save your spot.

Wednesday
May182011

In-Class Demo for May 18

Wednesday
May182011

Better Know A Framework: Indexer Sample Code

Here's an extended, closer-to-real-world example of using indexers in C#.

download

Monday
May162011

In-Class Demo for May 16

Thursday
May122011

Brushing Up

Several students have asked for videos/tutorial/exercises to help brush up on some of the programming concepts covered in class and on C# topics specifically. I'll be writing posts point towards this kind of information using the "brushing up," "code katas," and "exercises" tags. Here's the first set:

Tutorials & Videos

C# Station has what looks to be a nice set of approachable tutorials on the language. Some of these topics we've already covered, others are coming up soon.

Channel 9 has posted a series of Whirlwind Tours of C# videos. Here's one on Automatically Implemented Properties with more linked at the bottom of the page.

Code Kata

Kata:
A Japanese word describing detailed choreographed patterns of movements practiced either solo or in pairs. Kata are used in many traditional Japanese arts such as theater forms like kabuki and schools of tea ceremony, but are most commonly known for the presence in the martial arts. en.wikipedia.org/wiki/Kata

Code katas are small problems designed to get you thinking about programming like a programmer. You are encouraged to solve each of them multiple times using different techniques and even different languages! There are many such code katas, here are some of my favorites:

Exercises

Finally, here's a set of small exercises you are free to do. I'll be happy to review them with you but they are not graded.

Set 1

 

Wednesday
May112011

In-Class Demos