Delphi Programming Exercises 1
- (Type integer, arithmetic operators, integer operators,
TEdit, TLabel, TButton, TEdit.Text, StrToInt, IntToStr). Write a program
which reads two integers and then displays their sum.
Solution
- (Type integer, arithmetic operators, integer operators,
TEdit, TLabel, TButton, TEdit.Text, StrToInt, IntToStr). Extend exercise 1 so
that the product and quotient (first div second) are displayed.
Solution
- (Constants, FloatToStr) Write a program which takes the radius of a circle as
input and returns its area and circumference (pi = 3.14159).
Solution
- (FloatToStrF) Write a program that inputs three real numbers, computes their sum and
outputs the result to a specified number of decimal places.
Solution
- (Constants) Write a program which sets up constants for base rate and
higher rate tax (try 20% and 40%) and the tax thresholds for basic and
higher rates (try £5,000 and £40,000). After inputting the gross pay the
program should return the net pay according to the thresholds and rates.
Provide a suitable interface for the user.
- (If, else, and, showmessage) Amend program 1 so that only three-digit
positive integers are
accepted.
- (If, Repeat..until, and) Amend program 2 so that only values in the range -100 to +100 are
accepted.
- (If..then, showmessage) Write a program which accepts a temperature value and then
offers the user a choice between converting from C to F or from F to C.
Provide a suitable interface for the user.
- (if, repeat..until, global variables, onCreate) Write a
program that accepts a sequence of numbers and calculates their sum and
average. Provide a suitable interface for the user.
- (for, listbox) Write a program that outputs triangle numbers - 1, 3, 6, 10, 15, etc.
- (for, listbox, memo) Write a program that outputs the multiplication table of the
user's choice. Each line should read, for example, "3 x 13 = 39",
where 13 was the number entered by the user.
- (for loop, list box) Write a program that outputs the Fibonacci sequence up to a
user-supplied value and displays the 'golden ratio' each time. The output
should be displayed as pairs of Fibonacci numbers followed by the golden
ratio between them, eg f1, f2, f1/f2; f2, f3, f2/f3, etc.
- (case, ComboBox) Extend the first program so that the user can choose the operation on the two
variables from a drop-down list (ComboBox).
- (case, ComboBox, onChange) Write a program that presents
a list of the planets in a ComboBox and displays a brief message in response
to a selection.
- (Image control, multiple forms and units) Write a program that includes
a start form with an image and buttons that link to a second form. Provide a
link from the second form back to the first.
- (screen.fonts, listbox, memo) Write a program that provides a list of fonts from
the current system list, displays each font in its actual face and applies
the font to text in a memo box.
- (Array) Write a program that fills an array with a
sequence of numbers such as a multiplication table. The user should then be
able to specify a value from the table by its index value. For example, if
the table contains 5, 10, 15...50, the user should be able to input 6 and
obtain the result 30 from the table (6x5).
- (Array) Write a program which reverses a sequence of
numbers. Solution
- (Array) Write a program that creates an array of numbers
and then allows the user to see if particular values are in it (linear
search).
- (sort) Write a program that defines a list of numbers in random order
and outputs them in ascending order.
- (spinner, printing) Write a program that presents a menu of items in a fast food restaurant,
provides spinners for input of the number required and produces a total bill for
the customer. Print a receipt. (Chapter 4)
- (record) Write a program which that defines a record for pupils with
fields for name, form and year of entry. Input data from edit boxes into the
fields of the record.
- (record, array) Write a program that reads a series of pupil records
into an array. Add a routine to sort the array by a specific field.
- (record, file) Write a program that reads a record pupil and saves it
into a file.
- (Finite state machines) Imagine a door that opens and closes
automatically. There is a sensor outside the building to detect when someone
is near the door and one inside with a similar purpose. When the door is
closed and someone approaches from either inside or outside the door will
open. When the door is open and there is no one on either sensor then it
will close. There are six further states (eight in total) based on the
combinations of the state of the door and the sensors. List all possible
states for the door. Now create a simulation of the door using suitable
techniques. A console program would start in state closed and change
according to the input. A GUI program would be preferable as you could model
the sensors with buttons and the door itself could be drawn in an animated
graphic.
- (Finite state machines) Write a program that accepts strings in alphabet
Σ={a,b} of the form a, b, aa, bb, bab, aba, but not ab, ba or bbba, etc. You
will need to draw the fsm for this first. The machine begins in state S when
a letter is read. If the symbol is a the machine proceeds to acceptance
state q1, where it may read further characters from the alphabet: if it
reads a it stays in state q1; if it reads b it moves to non-acceptance state
q2. The pattern for reading symbol b is the same as for a. Provide a
suitable interface for the user as the letters are read.
- Write a program that allows a person to play noughts and crosses against
the computer.
f
Travel tickets
Saving records
Loops and arrays
Back