header

Lab 11

In this lab, you will begin a project that ultimately will allow you to perform some simple manipulations of grayscale images. This program will use a command line interface. That is, the program will allow you to type in a command and then it will execute that command. When it is done executing the command, it will wait for you to type in another command. In this lab, you will write only the code necessary to interpret the commands entered by the user. For the most part, the program will not actually execute any of the commands. That functionality will be added later on.

The command line interpreter is a function (named "execute" in this program) whose only parameter is the command (as a string). This function parses the line into its component parts and then invokes another function which is responsible for the actual execution of the command. In effect, the execute function takes the command and determines which function needs to be invoked to execute the command. In some cases, the interpreter must also provide parameters to the function that executes the command. These parameters are part of the command line.

Available Commands

This application has 10 commands that the user can enter. The commands are not case sensitive so they can be entered in any combination of upper and lower case letters. In the descriptions below, square brackets are used to denote optional items. The user may enter them but doesn't have to.

a[djust] b[rightness] [delta#]

This command allows the user to adjust the brightness of the current image. It can be entered as "a b", "adjust brightness", "adjust b", "a brightness", and a whole slew of other ways using different combinations of upper and lower case letters. The point is that the text "djust" and/or "rightness" is optional. The integer argument, delta#, is also optional. The function responsible for executing this command is part of the image class:

void adjustBrightness(bool autoAdjust, int delta)

If the optional delta# argument is omitted, the actual parameters in the function invocation are true and 0. Otherwise, the actual parameters are false and the value of delta#.

a[djust] c[ontrast] [low# high#]

This command allows the user to adjust the contrast of the current image. It has two optional arguments; low# and high#. They are both needed. If only one is present, it should be ignored. The function responsible for executing this command is part of the image class:

void adjustContrast(bool autoAdjust, int low, int high)

If the optional integer arguments are omitted, the actual parameters in the invocation of this function are true, 0, and 0. Otherwise, the actual parameters are false, the value of low#, and the value of high#.

b[lur]

This command allows the user to blur or soften the current image. The function responsible for executing this command is part of the image class:

void blur()

e[nlarge]

This command allows the user to double the size of the current image. The function responsible for executing this command is part of the image class:

void enlarge()

h[elp]

This command displays a help message in the console window. The function responsible for executing this command is part of the application:

void displayHelp()

This function has already been written for you.

l[oad] i[ndex] or li

This command loads the contents of an index file into memory. The function responsible for executing this command is part of the application:

void loadIndexFile()

l[oad] f[ile] or lf

This command reads a grayscale image into memory. The function responsible for executing this command is part of the application:

void loadImageFile()

q[uit]

This command terminates the application.

r[educe]

This command allows the user to reduce the current image to half its size (i.e., the width and height are both divided by two). The function responsible for executing this command is part of the image class:

void reduce()

s[harpen]

This command allows the user to sharpen the current image. The function responsible for executing this command is part of the image class:

void sharpen()

The Lab11.cpp File

I've done some of the work for you in Lab11.cpp. This file compiles and runs but doesn't actually execute any command except "quit". Your job is to write the code for the execute function. All of the functions needed to execute the commands are present in skeleton form. They do not yet perform their intended tasks but each function will display a message on the console window indicating that it has been invoked. To test your command line interpreter, you need to make sure that the message displayed on the screen corresponds to the command that you typed in. Here is what was displayed on the console window during a sample run:

LandSat Image Viewer

This is a command line interface. To see a list of the available
commands enter the "help" command.

> adjust brightness
Adjust Brightness automatically.
> a b 100
Adjust Brightness by adding 100.
> a c
Adjust contrast automatically.
> a c 10 100
Adjust contrast from 10 to 100.
> a c 10
Adjust contrast automatically.
> b
Blur image.
> blur
Blur image.
> e
Enlarge image.
> enlarge
Enlarge image.
> load index
Load index file.
> l

Unrecognized command. Enter "help" to see list of commands.

> l i
Load index file.
> li
Load index file.
> l f
Load image file
> load file
Load image file
> lf
Load image file
> s
Sharpen image.
> sharpen
Sharpen image.
> reduce
Reduce image.
> r
Reduce image.
> q

You should also make sure the help command works. Notice (about in the middle) that when an invalid command is entered, the execute function displays an appropriate error message.

Submit your finished assignment by sending me your Lab11.cpp file as an email attachment. (Note: you will not need to create a project file for this assignment since we are not yet actually doing anything with the graphics package.)