C# 2 .0:15 Exercises for Learning a new Programming Language

C# 2 .0:15 Exercises for Learning a new Programming Language

上次寫了【藉由15 題練習題來學習新的程式語言】,裡面介紹兩篇不同作者認為學習程式語言 15 題良好的練習題。大致上,我已經在第一篇文章的題目時作出來了,因為 quick and dirty 的關係,程式難免有些小瑕疵,而且都還可以寫的更好。不過,我生性懶惰,而且瑕不掩瑜,大家就勉強參考一下吧

(1) 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).
Ans

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

(3) Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.
Ans

(4) 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...)
Ans

(5) 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)
Ans

(6) Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus
Ans

(7) Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations)
Ans

(8) Open a text file and convert it into HTML file. (File operations/Strings)
Ans

(9) Time and Date : Get system time and convert it in different formats 'DD-MON-YYYY', 'mm-dd-yyyy', 'dd/mm/yy' etc.
Ans

(10) Create files with date and time stamp appended to the name
Ans

(11) Input is HTML table, Remove all tags and put data in a comma/tab separated file.
Ans

(12) Extract uppercase words from a file, extract unique words
Ans

(13) Implement word wrapping feature (Observe how word wrap works in windows 'notepad')
Ans

(14) Adding/removing items in the beginning, middle and end of the array.
Ans

(15) Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc.

這一題我就懶得實作出來了,不過以上的特性 C# 2.0 通通都有支援,有興趣的人請自己去看看 MSDN 吧!