Objectives and Overview: During the rest of the course our primary focus will be building data structures using the Class construct. The main purpose of this lab is for you to get used to creating and using classes. In addition the lab introduces the use of simple graphics in Code Warrior.
In the course folder you will find a file arrays.cpp which contains
starter code for this lab. The code implements a program similar
to the program in lab 1, except that the array is constantly kept in sorted
order and the contents of the array are graphically displayed as the numbers
are read in. Your goals for the lab are twofold. First, you
should implement a new array class called vector which is an improvement
over standard C++ arrays. There are a number of ways in which C++
arrays can be improved, including array bounds checking and initialization
of values. Second, and related to the first, you should make general
improvements to the program as a whole. For example, you might only
display parts of the array where values have been filled in, you might
perform some error checking, etc. When you are done your program
should represent a significant improvement over the arrays.cpp code.
Copy the arrays.cpp file to the desktop in the usual way. Within
Code Warrior you will want to make a new project. When you are creating
a project, in the very last step when you would normally select the Std
C++ Console, instead select the C++ Graphics Console. This will make
a number of useful graphical routines available to you. In the future
anytime you wish to use graphics you should select this Console.
Once you've created the project and added arrays.cpp to it, try running
the program to get a feel for its behavior. Can you "break" it?
Are there obvious improvements to make? Make sure you have a thorough
understanding of the code.
The main goal of this lab is to replace the global array currently used in the program with an improved version implemented as a class. You will need to creat a class to serve this purpose. At a minimum your vector class should do the following:
This is a good example of a program where you probably want to use your
own include file. Define the vector class and all of its corresponding
functions in a file called vector.h and then include that file in
your main program. This way you can use this class in any future
program in which you use arrays.
Once you have written your new class, update the program to include
it. Include other changes to improve the functionality of the program.
As with all labs, turn in hardcopy to me and place a copy of the program in the Dropbox (with the usual naming conventions). Meeting the minimum requirements of the assignment will get you an excellent score on this lab, but not a 100. To get a top score you will need to make some or all of the extra improvments suggested. Or come up with other improvements of your own. A good program should be well commented, readable, robust, and should like pretty nice when you run it.