Academic year 2013/2014, Summer semester

Programming Windows in .NET (eng.)

Lecture - tuesdays at 8.30 classroom no.5.
Labs - tuesdays at 10.15 (with Łukasz Piwowar)

Excercise sets

Excercise Set 1. Due date: March, 25th

Excercise 1.
Install any version of Visual Studio 2013 on your personal computer (in case of the Express Edition, make sure you install the Windows Desktop edition).
Excercise 2.
Use the Visual Studio to compile and then execute first three example codes from the Win32API example set presented at the lecture (available here).
Excercise 3.
Learn to debug the code - show how breakpoints can be set in the source, what happens when the execution hits your breakpoints, how to inspect the state of variables when an exception is hit and how to resume the execution.

Excercise Set 2. Due date: April, 1st

Excercise 1.
Write a C# application that finds a largest 3-digit number that can be divided by each one of its its digits.
Excercise 2.
Decompile the program from the previous task using ildasm.exe
Excercise 3.
Recompile the CIL source with ilasm.exe
Excercise 4.
Decompile the program with a high-level decompiler (IlSpy) and save it as a project so that you can use VS to recompile it

Excercise Set 3. Due date: April, 15th

Excercise 1. (indexers)
Implement a two-dimentional grid class with two indexers
  1. a one-dimentional indexer that returns a list of elements of given row of the grid so that the client could call it like
    ...
    Grid grid = new Grid( 4, 4 );
    int[] rowdata = grid[1]; // "get" accessor
    
  2. a two-dimentional indexer that returns a given element of the grid so that the client could call it like
    ...
    Grid grid = new Grid( 4, 4 );
    elem[2, 2] = 5; // "set" accessor
    int elem = grid[1, 4]; // "get" accessor 
    
Both indexers should take integer numbers as parameters. The class constructor should take the number of rows and columns as parameters.
Excercise 2. (reflection)
Write a program that demonstrates the ability to access private members from outside of the class. The code should contain an example class with at least one private method and one private property. The client code should be able to access both private members via reflection.

Also, write code that compares the time spent on accessing members directly with the time spent on accessing members via reflection. How much slower the reflection is?

Hint. To measure time, use following block

DateTime Start = DateTime.Now;
/* code block here */
DateTime End = DateTime.Now;
TimeSpan Czas = Start-End;
Console.WriteLine( Czas );
Remember to repeat the code block enough times to get a meaningfull results.
Excercise 3 (attributes)
Write a method that takes any object as a parameter and finds all its public, instance methods with empty parameter list and integer return value. Then, all methods that are marked with [Marked] attribute are executed.
public class Foo
{
  [Marked]
  public int Bar()
  {
    return 1;
  }
  
  public int Qux()
  {
    return 2;
  }
}

Excercise set 4. Due date May, 13th, 2014

Excercise 1. (LINQ to Objects, sorting, filtering)
There is a text file which contains natural numbers in consecutive lines.

Write a LINQ expression, which reads all numbers and prints out only these numbers which are less than 100, all of them in a descending order.

from number in [expression_which_reads_numbers_from_file]

where ...

orderby ...

select ...
Reformulate the LINQ expression into a chain of LINQ method calls:
[expression_which_reads_numbers_from_file].Where( ... ).OrderBy( ... )
Excercise 2. (LINQ to Objects, grouping)
There is a text file which contans persons names in consecutive lines.

Write a LINQ expression which returns a set of all first letters of these names in an alphabetical order. For example, for the file

Kowalski
Malinowski
Krasicki
Abacki
the result should be
A, K, M
Excercise 3. (LINQ to Objects, analyzing server logs)
The event log of an application server is a text file of the form:
08:56:36 214.54.15.1 POST /AnotherApplication/test.jpg 200
08:55:36 192.168.0.1 GET /TheApplication/WebResource.axd 200
....
The first column is a datetime, then there’s the client’s IP number, HTTP request type, resource name and the response status.

Write one (or more) LINQ expression which will show IP numbers of the top three clients who sent the highest number of requests.

An example result should look like:

12.34.56.78 143
23.45.67.89 113
123.245.167.289 89
where the first column is the client’s IP number and the second column is the total number of requests.

Excercise set 5. Due date June, 03th, 2014

Excercise 1. (Windows.Forms, user interface)
Write a simple Windows.Forms application that presents a list of students.

List of requirements:

Lectures

  1. 2014.02.25
  2. 2014.03.04
  3. 2014.03.11
  4. 2014.03.18
  5. 2014.03.25
  6. 2014.04.01
  7. 2014.04.08
  8. 2014.04.15
  9. 2014.04.29
  10. 2014.05.06
  11. 2014.05.13
  12. 2014.05.20
  13. 2014.05.27
  14. 2014.06.03
  15. 2014.06.10

Bibliography

  1. Charles Petzold, Programming Windows 5th Edition
  2. Bruce Eckel, Thinking in C#
  3. Andrew Troelsen, Pro C# and the .NET Platform 4.5
  4. Daniel Solis, Illustrated C#