Nil honlapja
Tetszőleges böngésző
Tetszőleges felbontás
Utolsó módosítás:
|
Programming exercises
Your program will not do what you want, but what you type. - anyone
The following approach - which I know more or less - is a possible way of
learning to create programs. You have to be able to complete these exercises
if you want to be a programmer. In theory you will need some years to solve all
of them (and to learn the necessary background knowledge) if you have just
started to do programming and you still want to continue your life.
Do not send me solutions and do not want hints from me! The solution is good if
it fulfills the exercise. You cannot ask your procurer "Is it good now? Is it
good now?". If you are lonely you can search for a buddy whos knowledge and
skills are comparable to yours and do the adventure together! Or perhaps you
may want to search for a mentor who will guide you trought the learning. ... It
is also possible that you are a mentor so that's why you are here. ;-)
You can learn programming by writing programs. This is a compulsory but not a
sufficient condition. You can do a real learning this way, you can build
a large amount of routine inside yourself. Going ahead from ther is a matter
of theoretical knowledge. You may expect success only if you dig deep. The
knowledge of the English language is also unmissable.
These exercises are good for almost any programming language. You can start
programming in each programming language with a differnt method. These methods
can be found using Google/Yahoo/..., this page is not aimed to take care about
individual programming languages. Not all exercises are interpretable for all
programming languages. It is demonstrably true for non-imperative languages.
If you do not know a concept (for example Fibonacci numbers, AVL tree), then
you should use school books, textbooks, Wikipedia
(http://en.wikipedia.org/), Google
or Yahoo... (I could collect links for these concepts, but it would not make
sense because the Internet is changing too fast.)
It is not required to do the solutions continously.
I. Non-interactive, non-abstract exercises
- Create a program which prints
Hello World! and a line break!
- Create a program which prints the whole numbers from 1 to 10!
- Craete a program which prints the whole numbers from 10 to 1!
- Create a program which prints the even numbers from 1 to 50!
- Create a program which prints the first 10 square numbers!
- Create a program which prints the first 25 Fibonacci numbers!
- Create a program which prints the first 100 prime numbers!
II. Interactive, non-abstract exercises
If you read an out of the blue sky variable name - for example n - or I say about something
that it is given then you have to read the value of it from the user. If I talk about
indexes and I do not say differently then I talk about human indexing, starting at 1. It is possible
that a certain language's array indexing begins at zero, in this case - in the absence of other
instructions - the first element means the zeroth element of the array in that programming language.
- Create a program which asks for two integers and prints their sum!
- Create a program which asks for two real numbers and prints their avarage!
- Create a program which asks for a number! The program must deny numbers that are negative or greater than 100! The program has to repeat asking for the number until it is acceptable! (In the following if we enforce conditions on user input then we should proceed with the sulution in this manner!)
- Create a program which asks for a whole number! If the user's input is not whole or not a number then the program must warn him/her and repeat the asking for input until it is correct! After successful input if the number is even the program has to print
even , if not then odd ! (In the following we should process every user supplied data with the same level of carefulness!)
- Create a program which asks for the three sides of a triangle and prints the area and the circumference of it! (Area: Heron's formula) If the triange does not exists then the program has to report that condition (it must not
crash )
- Create a program which asks for the three factors of the quadratic equation and prints the real roots. If the equation is not solvable on the real numbers then the program has to report it to the user.
- Create a program which decides whether a user given number is prime or not.
- (deleted)
- Create a program which asks for
n (n>=1) number and prints the greatest. (You should not store all the numbers in the memory to solve this problem.)
- Create a program which asks for
n (n>=1) number and prints the greatest, the smallest and the sum of them! (You should not store all the numbers in the memory to solve this problem.)
- Create a program which asks for
n (n>=2) numbers and prints the one that is the further away from its preceding one (the first cannot win)! (You should not store all the numbers in the memory to solve this problem.)
- Create a program which asks for
n (n>=0) numbers and prints them in ascending order!
- Create a program which asks for
n (n>=0) English names and prints them in the ascending order of the English alphabet!
- Create a program which asks for the numers of a lottery ticket (5 pieces of numbers between 1 an 90 without repetition) and prints them in ascending order!
- Create a program which prints the Pascal's triangle's first 10 lines! The lines should start at the begning of the screen lines, the number should have spaces in between (but not before the first)!
- Craate a program which
thinks of an integer between 0 and 1023! The user has to guess for the number. The program must report that Smaller , Equal or Greater the number it thought! The program must repeat asking for guesses until the user succeeds!
- Create a program which is the opposite of the above! The user thinks of a number and the program makes guesses. If the guess of the program is good then the user should press
2 (or ENTER). If the goal is smaller then 1 , otherwise 3 ! If the program knows that the user is lying it must print You lie! ! The program must be successful up to 10 guesses.
- Create a program which asks for
n (n>=0) numbers and prints the alternating sum of them! (The sum starts at 0, elements with odd index are added, the others are substracted.)
- Craete a program which asks for
n (n>=0) students' name and height and prints them in the ascending order of their height!
- Create a program which finds the prime numbers until 100 million and reports the amount of them! The program must run within 1 minute! Unconventionally this is not an interactive exercise, and also I give you the result: 5 761 455.
Modify some of the solutions in a way that the program asks for the input method which can be
interactive and file. According to the possibilities and style of the language try to solve
this in a way that the essential part of the solution should not be written twice in the source
code!
III. (More) abstract exercises
In the following exercises I do not provide simple ways for verifying the solution, I leave it
to the solver. You may have to learn some new concepts using textbooks, Wikipedia and Google.
- Create a program which reads a
matrix of numbers and prints the transposed of it!
- Create a program which is able to multiply real matrices!
- Create a program which places 8 queens on an imaginary chess board in a way that they could not reach eachother in one move!
- Create a program which tells whether the textual input is a strict palindrom or not!
- Create a program which asks for
n (n>=0) integers and prints the greatest positive of them if it exists!
- Create a program which can calculate the angle between two two-dimensional vectors!
- Create a program which can calculate the angle between two
n -dimensional vectors!
- Create a program which can calculate the cross procut of two three-dimensional vectors!
- Create a program which asks for circles (center's x and y coordinate and radius) and prints the ones that contain a given point!
- Create a program which asks for triangles (three corners) and prints the ones that contain a given point!
- Create a program which asks for rectangles (
top left vertex's x and y coorinate, the angle of the upper edge (in degrees), width and height) and prints the ones that contain a given point!
- Create a program which asks for regular polygons (number of edges, center, radius, angle of a highlighted vertex) and prints the ones that contain a given point!
- Create a program which asks for shapes (see the above 4 exercises) in random order and prints the ones that contain a given point in the ascending order of their area!
- Create a program which you can play
Tha towers of Hanoi with! The program itself must be able to play this game!
IV. Totally abstract exercises
- Create a program which is able to draw circles and lines pixel by pixel, with own algorithm, fast!
- Create a program which produces sound waves mathematically and plays (beeps) the main theme of the "Star Wars - The Imperial March".
- Implement the following orderings on array:
quick sort , merge sort , heap sort !
- Implement the following structures:
doubly-linked list , set (using AVL tree ), stack (using your fresh doubly-linked list)!
- Implement a calculator which can calculate the formlua given by the user! (Example:
2+3*4^5+sqrt(sin(45))^ln(2) )
- Create a program which is able to store arbitrary long integers, calculate their sum, difference, product and quotient!
- Read two Rubik's cubes from file which in they are cutted amongst their edges and laid out on the plane. Make decision about their equality! (It is possible that their orientation is different but they are equal.)
- Continue the above exercise and decide whether one of them can be transformaed into the other with one regular move!
- Create a program which reads the number of vertexes of an undirected graph and the edges of it from a file and counts the connected components of it!
- Create a program which calculates the determinant and inverse of a matrix.
- Create a program which generates an unicursal labyrinth and solves it!
The end
-
Know the possibilities, strengths and weaknesses of you choosen X where X is a
- programming language
- programming ennvironment (standart toolkit, 3rd party framework)
- programming tool (IDE)
- cooperation supporting tool (version control system, bug tracking system)
- Never be lazy to learn new things or else you will became forfeited!
- Your program is good if the user is satisfied. It is not enough to solve the
core of the problem. The handling interface of your program must not be bare
or
too clever (except on explicit need)! Always think about keeping
your program available for scripts if it is appliable.
- More exercises:
programming exercises
At this point everybody has a different urge and vision. If you are here it is likely
that you know what you want. These exercises are suitable for creating and improving
your skills of creating and implementing alhorithms. This is a bare skeleton which
is incomplete even on a theoretical basis. Let we see some illustration about this:
strong type system, weak type system, object oriented programming, generic programming,
operator overloading, functional languages, paralell programming, numerical recipies,
databases, compilers, distributed systems, ...
Recommended literature
- New algorithms
- The pragmatic programmer
- Design patterns
- Refactoring (in the last resort :-D)
- Books about special topics (graphic, sound processing, databases, web, UI design, modelling, networking, ...)
- Books about programming languages
-- Darabos Edvárd Konrád <voidnil on yahoo.com> | 2009-11-22, 2009-12-09, 2010-07-19
|