.H
or .h
It's a good
idea, but not required, to name this file after the class.
For example, class Foo
would be defined in a file named
Foo.H
or Foo.h
#ifndef FOO_H #define FOO_H . . #endifstyle. This style is used to avoid multiple includes of the header.
.C
or .CC
or
.cpp
It's a good idea but not required to name this file after the class.
For example, the Foo
class
would be implemented in a file named Foo.C
or
Foo.CC
or Foo.cpp
.
Foo.h
refers to an
ostream
entity and a string
entity. Then,
definitely do include iostream.h
and mystring.h
in Foo.h
. Now, suppose the implementation file
Foo.C
refers to an ostream
entity, but not
a string
entity. Then Foo.C
should include
Foo.h
and iostream.h
, but not
mystring.h
. Note that iostream.h
is included
even though its inclusion is also caused by including Foo.h
.
Guarded header files keep this from causing multiple definition and your
code becomes cleaner and more readable.
main
function is to be in its own file. The
file extension must be .C
, .CC
, or
.cpp
It's a
good idea, but not required to name the file after the project.
For example, the main
function
for project 3 would be in a file named
Proj3.C
, Proj3.CC
or Proj3.cpp
Proj3
file. This is very important because the grader
will look for that file to run your program. The grader will not
run a.out
or any other executable. The executable name
is controlled by your makefile - get it right. Do not submit your
executable, the grader will construct it by using your makefile.
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. public
comes first, followed by protected
and private
,
in that order.
private
.
const
variables globally - nothing else.
#define
) for constants. Use
const
variables for constants.
virtual
methods, provide a
virtual
destructor.
const
method. Example:
int getSize() const
void
. Example:
void setSize(int newsize)
const int MAXSIZE
class DoubleLinkNode
class Matrix
void setSize(int) int inverse(int) Matrix mat int arraySize
int _length
. Remember, all class data members must
be private
.
Makefile
or
makefile
, your choice. No other names are acceptable
for your makefile.
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. A sample
makefile is provided:
/afs/umbc.edu/users/a/n/anastasi/pub/CMSC-341/Proj1/Makefile
It is pretty much ready to use for Project 1 and can be easily
modified for other projects. Copy it to your directory and make any
necessary changes. In some cases, the copy process converts the TAB
characters to spaces. The makefile requires the TAB characters. If they
were converted to spaces, change them back to TABs.
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. Sometimes the
copying process converts TAB
to spaces. Check your copy
to be sure you have tabs.
A number of tutorials on makefiles are available. One is the UCS tutorial. Another is an excerpt from the GNU tutorial. Links to them are on the "Projects" page of the course web page.
/* Array.H CMSC-341 Fall 1999 Section 4 Project 1 Array ADT Thomas Anastasio Created: 1 August 1999 Current: 8 August 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: 8 August 1999 */ template <class T> class 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(const Array<T>& arr); // Destructor ~Array(); // Accessor for size of this Array. // Return: the size of this Array. 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. const 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); private: int _size; T* _array; }; #endif