-->

Type something and hit enter

On
advertise here

 

Exercises for Learning a new Programming Language

I have a working knowledge of many programming languages, but my job requires me to learn new languages, often in a short period of time. Instead of reading hundreds of pages of manuals and books, read 10-15 pages of tutorials and primers quickly. (As you know, Google is a great search engine for things like this). I have a printed copy of the Language Syntax Reference Card. (There are many references on the internet. Type "language to learn" + "reference map" into Google. )


First, familiarize yourself with your compiler, compiler options, editor shortcuts, or integrated development environment (IDE). Start with a simple "Hello World" program. Compile it. Use basic debugger features such as setting breakpoints, viewing variable values, going to the next or specific location, and stopping the debugger.


Here are some exercises I use to quickly get up to speed with the basics of a new language. Please note that some programs may not be suitable for beginners.


(1) Display rows of numbers (1, 2, 3, 4, 5....) in an infinite loop. If someone presses a certain key (such as the ESCAPE key) the program should exit.


(2) Fibonacci sequence, swap two variables and find the max/min in a list of numbers.


(3) Accepts rows of numbers, strings from the keyboard and sorts them in ascending and descending order.


(4) The Reynolds number is calculated using the formula (D*v*rho)/mu. Now write a program where D = diameter, V = velocity, rho = density, mu = viscosity

and enter all the values. Accepted in appropriate units (don't worry about unit conversion)

If number <; 2100, show laminar flow, if between 2100 and 4000

, show "unsteady flow", "4000"

, display 'turbulence' (otherwise...)


(5) Change the above program to: Ask "Do you want to recalculate (y/n)".

If you answer "y", you will be asked for the parameters again. If 'n', exit. (Run while loop)


Enter the value mu = 0 when running the program. See what happens. Do you have a "DIVIDE BY NULL" error?

"Segfault..Do you have a core dump?". How to handle this situation.

Are there any built into the language itself? (exception handling)


(6) add, subtract, multiply, divide, square root, square root, cube,

sin, cos, tan, factorial, reciprocal, modulus Support scientific calculator


(7) Output output in various formats


(8) Open text file and convert to HTML file. (file operation/string)


(9) Time and date:

Get the system time and use various Convert to format. .


(10) Creates a file with a date/time stamp appended to its name.


(11) Input is an HTML table. Remove all tags and put the data into a comma/tab delimited file.


(12) Extract capitalized words from a file and extract unique words


(13) Implement line breaks (note how line breaks work in Windows Notepad) Array .


(15) Are these features supported in your language?

Operator overloading, virtual functions, references, pointers, etc. (name mangling) - read more about this


Click to comment