.H
suffix. For example,
class Foo
would be defined in the file
Foo.H
.
.H
suffix) is to be
guarded using the
#ifndef FOO_H #define FOO_H . . #endifstyle. This style is used to avoid multiple includes of the header.
.C
) file. The one exception: an accessor or a mutator
method for a data member may be done inline and defined in the
header file, outside the class definition. The GetSize()
method is an example in the sample header
below.
.C
suffix. For example,
the Foo
class would be implemented in the file
Foo.C
.
.H
) and the implementation file
(.C
). Exception: a pure abstract class will have just
the header file.
main
function is to be in its own file, named
after the project and with a .C
suffix. For example, the
main
function for project 3 would be in the file
Proj3.C
.
Proj3
file.
The header file for a class presents the public interface for the class. We adopt the convention that class documentation is done in the header file. Implementation files may be documented also, but this is documentation for the programmer, not for the class user.
For an example of header file documentation, see the sample header below. You are encouraged to adopt this sample style. If you prefer your own style, that's ok, but it must meet the specifications laid out here.
Documentation of a class is to include the following information:
private
. You may document a data field if necessary for
clarity.
For projects in this class, use the following coding standard:
private
, protected
and
public
section in a class definition. private
precedes protected
precedes public
.
private
.
const
variables
globally - nothing else.
const
variables for constants.
inline
functions except accessors/mutators
for data members. Define inline
functions in the
class header file, not in the implementation file.
virtual
methods, provide a
virtual
destructor.
const int MAXSIZE
class DoubleLinkNode
class Matrix
void SetSize(int)
int Inverse(int)
int _length
Matrix mat
int bi_arr
Makefile
or
makefile
, your choice.
The grader will compile your submitted project by typing
'make
,' so your makefile must correctly make your
project. This includes correct naming of the executable.
See below for an example makefile. This
example can be easily modified for each project; change the
PROJ and SOURCES definitions and make the
appropriate changes in the targets and commands.
The example makefile can be used to obtain a nice-looking printout of your code. Just type make print and a Postscript file will be produced, ready for printing on any Postscript printer.
The makefile can also be used to submit your project. As long as you have SOURCES correctly defined, it will submit all the required files. Just type make submit to submit your project.
Remember that the command lines following the target line are indented
by the TAB
character, not by spaces.
# Makefile # CMSC-341 Spring 1999 Project 1 # Thomas Anastasio # Created: 23 November 1998 # Current: 23 November 1998 # PROJ = Proj1 CC = CC CCFLAGS = -g -n32 SOURCES = \ $(PROJ).C \ Array.H \ Array.C \ Matrix.H \ Matrix.C OBJECTS = \ Array.o \ Matrix.o SUBMITCLASS = cs341-03 PRINTPGM = /usr/lib/print/lptops PRINTFLAGS = -G -U -H -M2 -O0.4pt PRINTFILE = $(PROJ).ps $(PROJ): $(PROJ).C $(OBJECTS) $(CC) $(CCFLAGS) -o $(PROJ) $(PROJ).C $(OBJECTS) Array.o: Array.C Array.H $(CC) $(CCFLAGS) -c Array.C Matrix.o: Matrix.C Matrix.H $(CC) $(CCFLAGS) -c Matrix.C print: $(SOURCES) - $(PRINTPGM) $(PRINTFLAGS) $(SOURCES) Makefile > $(PRINTFILE) submit: submit $(SUBMITCLASS) $(PROJ) $(SOURCES) Makefile clean: - rm -f *~ cleaner: - make clean; rm -f *.o cleanest: - make cleaner; rm -f $(PROJ)
/* Array.H CMSC-341 Spring 1999 Section 3 Project 1 Array ADT from Heileman text (Exercise 4.11) Thomas Anastasio Created: 23 November 1998 Current: 24 January 1999 */ #ifndef ARRAY_H #define ARRAY_H #include <iostream.h> /* Improved array that allows dynamic resizing, range checking, and assignment to another Array. An Array "knows" its own size. Author: Thomas Anastasio Version: 24 January 1999 */ template <class T> class Array { private: int _size; T* _array; public: // Default constructor. Array size is zero. Array(); // Construct new Array of size sz, elements unspecified. // Param sz: the size of this Array. // Precondition: sz > 0. If sz <= 0, Array size will be // taken as zero. Array(int sz); // Construct new Array of size sz_bi with initial // elements from bi_aray (a built-in array of size sz_bi) // Param bi_aray: a built-in array from which to draw the // initial elements of this Array // Param sz_bi: the size of bi_aray // Precondition: bi_aray must really be of size sz_bi. If // sz_bi <= 0, an empty Array is constructed. If sz_bi // exceeds the actual size of bi_aray, errors may occur due // to array access boundary violations. If sz_bi is less than // the actual size of bi_aray, initialization of the Array // will be incomplete. Array(T* bi_aray, int sz_bi); // Copy constructor // Param arr: the Array to copy Array( Array<T>& arr); // Destructor ~Array(); // Accessor for size of this Array. // Return: the size of this Array. inline int GetSize() const; // Increase this Array's size. // Param delta: the amount by which to increase this // Array's size // Pre-condition: delta greater than or equal to zero. This // is enforced by an assertion. void Grow(int delta); // Decrease this Array's size. // Elements are removed from the right (elements from // A[size - delta] through A[size - 1] are lost). // Param delta: the amount by which to decrease this // Array's size. // Pre-condition: delta greater than or equal to zero and // no greater than present size of this Array. This is // enforced by an assertion. void Shrink(int delta); // Assignment operator // Assign ar to this Array // Param: arr is the Array to assign (the rvalue) // Return: this Array after modification. Array<T>& operator= ( Array<T> & arr); // Index operator. Retrieve element at the specified index. // Param: indx is the index // Return: the element at index in this Array. // Pre-condition: 0 <= indx < size. This is enforced by // an assertion. T& operator[] (int indx) const; // Output operator // Param: os the stream to which to write arr // Param: arr is the Array to write // Return: os friend ostream& operator<< (ostream& os, const Array<T>& arr); }; template<class T> inline int Array<T>::GetSize() const { return _size; } #endif