Pages

Showing posts with label C# Exercise. Show all posts
Showing posts with label C# Exercise. Show all posts

17 April, 2011

Exercise 6 (part 5) – Putting our DLL through it’s paces

Over the last four posts I’ve built up the engine of an RPN calculator in the form of a DLL.  Now it’s finaly time to put it use.  In this post I’ll present the code for a console-based user interface for our calculator.

13 April, 2011

Exercise 6 (part 4) – The Calculator Engine and Anonymous Methods

In this post I’ll complete the RPN Calculator engine we’ve been looking at.  This will complete the DLL I’ve been working on, and next time I’ll run through the code for a Console-based front-end.

10 April, 2011

Exercise 6 (part 3) – Delegates and Class Inheritance

So, back to my RPN calculator implementation.  Bear in mind that I wrote this code over six months ago, and I’ve learned a lot since then.  If I was to do it again now I may make different design decisions, but for the moment I’ll stick with the original code.  Let’s see what we can learn.

01 August, 2010

Exercise 6 (part 1) – Multi-file DLL project

For his 6th exercise, Prashant suggests writing a 

Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus.

In planning my solution to this exercise, I thought it would be cool to write a DLL (a Class Library in .NET parlance) to be the core engine of the calculator, and then write a console-based front-end.  Later, when I’m learning WPF I can write a graphical front-end to the same DLL.

13 July, 2010

Exercise 5 – Reynolds again: overflow without exception

The 5th of Prashant’s 15 Exercises for Learning a new Programming Language builds directly onto the 4th:

Modify the above program such that it will ask for 'Do you want to calculate again (y/n),
if you say 'y', it'll again ask the parameters. If 'n', it'll exit. (Do while loop)

While running the program give value mu = 0. See what happens. Does it give 'DIVIDE BY ZERO' error?
Does it give 'Segmentation fault..core dump?'. How to handle this situation. Is there something built
in the language itself? (Exception Handling)

The first bit is easy, the second bit may be surprising.  First thing I’ll do is show you what happens when I run the program from last time with mu = 0.

Exercise 4 – Reynold’s Number: a basic class

The fourth of Prashant's exercises is:

Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, V= velocity, rho = density mu = viscosity
Write a program that will accept all values in appropriate units (Don't worry about unit conversion)
If number is < 2100, display Laminar flow,
If it’s between 2100 and 4000 display 'Transient flow' and
if more than '4000', display 'Turbulent Flow' (If, else, then...)

In working this solution I decided to declare a class to help in the calculation.  The solution also shows some details of reading input from the console.

02 July, 2010

Exercise 3 - Collections and Sorting

The third exercise in 15 Exercises for Learning a new Programming Language is:

Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.

The naive solution would be to build an array of entered strings/numbers and then write a method that will sort that array - a simple bubble sort would do.  Of course, .NET offers a better way…

30 June, 2010

Max/Min revisited

A kind commenter on my last post (thanks Matt) told me about an alternative to my Max/Min implementation.  The .NET framework includes a class library called LINQ (Language INtegrated Query).  In looking through the MSDN library I had seen this mentioned, but figured it had something to do with database queries.  I was partly right, but it turns out that LINQ is far more, and allows an alternate solution to Prashant's second exercise.

23 June, 2010

Exercise 2 – Fibonacci, and other things

Prashant’s second exercise is:

Fibonacci series, swapping two variables, finding maximum/minimum among a list of numbers.

So in this post we get to play with a bit of recursion, and I’ve thrown in some parametric types for good measure.

16 June, 2010

The First Exercise

The first item in Prashant’s list of 15 Exercises for Learning a new Programming Language is:

Display series of numbers (1,2,3,4, 5....etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).

So this post we start to look at loops and integer types.

07 June, 2010

Hello, World! – again

In 15 Exercises for Learning a new Programming Language, Prashant Mhatre kicks off with:

First of all, get familiar with Compiler, compiler option, editor shortcuts or integrated development environment (IDE). Start with a simple ‘Hello World’ program. Compile it. Use basic functionalities of debugger like setting break points, printing variable values, moving to the next or specific position, stopping debugger etc.

Let’s jump straight into the code first.