Programming Problems-Editor Application - Pascal programming

A programmer spends a great deal of time modifying already written programs, generally written by somebody else. We will therefore start with a series of program modification exercises. The following programs were introduced in, when you used them to get a beginning experience in actually using programs. The following problems show you the programs and ask you to change their behavior by modifying them.

1. Editor Application

TED is a Tiny Editor used to create and modify files of text. This editor acts on a line at a time. It requests operations by displaying a question mark “?” and the following commands may be given (by the first letter of the command: A, B, D, etc. in upper or lower case):

B to go to the Beginning of the file
D to Delete the line at the given position
T to Type out the entire file
P to move the Now pointer to the Previous line
N to move the Now pointer to the Next or following line
I to Insert one line after given line
F to Find a given string, starting at the present line
M to Modify the present line
H to provide Help, by listing all commands
R to replace a given line by another
S to Save a file
L to Load a previous file which was created and saved
E to End or exit the edit session

The Pascal program for TED is rather short because it makes use of data structures from the UNIT StackLib2. The source code for StackLib2 is:

The Pascal program for TED is:

You will notice that not all the commands in TED have been implemented; there are just place holders for them. Complete the implementation of TED and then:

  • Add more commands, such as Append, to insert more than one line
  • Output with line numbers for reference
  • Provide more detailed help or instructions

2. Typing

TypeTimer is an application program that presents a line of text to be typed in, and then indicates how quickly this line was typed. Accuracy is not measured because it is assumed that errors can easily be corrected. A typical run of this program is shown below; the part of the dialog that the user typed is shown in bold.

Typing Speed Test You are to type the following line Type Return when you are ready, and type Return when you are finished A quick brown fox jumps over the lazy dogA quick brown fox jumps overf the laxy dog The time taken is 50 units.

Time is measured by units, which are not seconds, but some arbitrary units that are consistent and serve to compare times to measure progress. The Pascal code for TypeTimer is:

Typer2 is another application program that presents a number of lines of various kinds of text and indicates whether the typed line is correct or has errors.

Typer2, as it stands has only two sentences, neither of them really serious. Extend the program to draw on a richer repertoire of sentences from a file. Other extensions to be made are:

  • to combine both speed and accuracy tests into one,
  • to keep track of your progress after each exercise.
  • to enter yet a third kind of file, “semi-serious”,
  • to count the number of errors.

3. Calculator Applications

Calculate is a calculator that is simulated by a computer. It provides the
typical four arithmetic functions (add, subtract, multiply, divide). Entering the letter “q” or “Q” causes the calculation to quit. The Pascal program for Calculate is

Extend this program to:

  • Compute squares and powers
  • Include trigonometric functions
  • Output results in scientific notation

Make another version of this calculator that uses ComplexLib from to work with complex numbers. Extend this version to:

  • Compute complex conjugates
  • Compute magnitudes and angles
  • Output results in polar notation.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Pascal programming Topics