Comments regarding design and documentation of functions.
Design: See Comments on software design for recent and upcoming assignments
Documentation: Each function should have its own documentation so that it can stand on its own, be removed from a program if necessary. This means the documentation should contain the name of the function, a statement of its purpose, a list of the input parameters with the type and function of each as well as any assumptions regarding the values or form of the parameter noted, a description of the resulting object including its type, the name of the author and when it was last modified. The purpose of the documentation is to help to make the function reusable by the author or someone else.
Classes
We’ll take a look at classes in the Java to C++ guide, “Book of C++”
Lab “Getting to know classes & objects in C++”
Tutorial: Compilation and Makefile Tutorial
Construct a makefile for the work we did with classes.
We have the files
MyClassDynamic.cpp MyClass.cpp MyClass.h
The dependencies are
MyClassDynamic: MyClassDynamic.o MyClass.o MyClass.h
g++ MyClassDynamic.o MyClass.o -o MyClassDynamic
MyClassDynamic.o: MyClassDynamic.cpp MyClass.h
g++ -c MyClassDynamic.cpp
MyClass.o: MyClass.cpp MyClass.h
g++ -c MyClass.cpp
put all these in a file and we have an easier way of building our executable file.
See example in class on paprika.
Take a look at the class for a six-sided die. This is from the book, Chapter 11
die.h – you can get it by
wget paprika.umw.edu/~ernie/cpsc230/dieclass/die.h
die.cpp - you can get it by
wget paprika.umw.edu/~ernie/cpsc23o/dieclass/die.cpp
Write an application that rolls two dice stopping when the sum of the dots on the faces is greater than 8.
HW for next Thursday. Implement Free the Animals