• Homework
  • Thirds
  • Upper Thirds
  • Fourth
  • Divisions
    • ICT
    • Computer Science
  • Fifth
  • Lower Sixth
  • Upper Sixth
    • Upper Sixth Theory
  • Blog
  • Careers
  • Unity
  • Networking
computinglesson.com

Divisions Computer Science Programming Challenges in Delphi

Section 1.  Input and Output


1

Picture
Write a program that will display a joke.

Don't display the punchline until the reader hits the enter key.

Can you extend this so that the computer tells you a Knock Knock joke?

You'll need to use the writeln command and the readln command to wait until the user types something.



2

Picture
Write a program that will ask you your name.
It will then display 'Hello Name' when 'Name' is the name you have entered.

You'll need to use the readln command and assign it to a variable


3

Picture
Write a program that will work out the areas of a rectangle.

Collect the width and height of the rectangle from the keyboard.

Calculate the area and display the result.

You'll need two variables this time, use the multiplication operator *


Section 2 - Date and time

For the challenges below you'll need to create special variables with the type TDateTime
Display the current time

4

Picture
Write a program that will find and display the current time.
use the Now command to get the time from the system.
Now, can you display it in a sensible format?
Not so easy.
Use Pascal functions to convert the special type into something more sensible.
DateToStr(myTimeVariable) and TimeToStr(myTimeVariable)


5

Picture
Write a program that will find out how quickly the user can type all the letters of the alphabet in order.
Store the time at the beginning and end of the exercise
Check that the letters entered are correct, by comparing the inputln with the correct input.
Complain if the letters are not right or in order.

Section 3 - Advanced challenges

These challenges might be completed in a graphic user interface (VCL or Firemonkey)

Most will need to use Delphi's random number generator - click here for information

6

Picture
Create a game of 'Hangman'

Keep a list of words - perhaps stored in an external text file.  Choose a word at random and prompt the player to guess the letters.  Match the letters and display both the correct guesses in position, the number of turns taken, the number of wrong guesses and the letters guessed.


7

Picture
Make a random playing card generator

Write a program that will generate a random playing card e.g. ‘9 Hearts’, ‘Queen Spades’ when the return key is pressed. Rather than generate a random number from 1 to 52. Create two random numbers – one for the suit and one for the card.


8

Picture
Write a program that will generate prime numbers

There are some quite sophisticated ways to do this.  An easy way is to count up from one, and for each number - use the mod(x) function to see if the number divides without a remainder.  Keep going and see how large a prime number you can generate.


9

Picture
Make a 'guess the number' game

The computer selects a random number between 1 and 100.

The user keeps guessing which number the computer has chosen until they get it right.
The computer responds ‘got it’ or ‘too high’ or ‘too low’ after each guess.
After the user has guessed the number the computer tells them how many attempts they have made.  If that works, then r everse the game. You think of a number. Get the computer to guess a number and you respond with too high(H), too low(L) or got it(G). Make sure the computer has a game plan—don't just let it guess at random!

Powered by Create your own unique website with customizable templates.
Photos from bertknot, heliosphan, Luigi Rosa, Filter Forge, Matt McGee