COMP2012H

Honors OOP and Data Structures

Lab 8: Class Construction, Initialization and Use of Doxygen

Download Lab slides

Topics

Review

Default Constructor

Copy Constructor

Data Member Assignment (Memberwise Assignment)

Example:

class Word {
  public:
     Word (const char* s, int k=0);
  // ...
  };

Default copy constructor:

Word movie("Titanic");  // Word movie = "Titanic";
Word song(movie);     // Word song = movie;

There is associated default memberwise assignment:

Word movie("Titanic");   
Word song;
song = movie;

Function Overloading and Default Arguments

Member Initialization Lists

class Word
{
public:
   Word () { cout << "D" <<endl;}
   Word (char* s1) { cout << s1 << endl;}
   Word (const Word & w) { cout << "C\n";}
   Word & operator= (const Word & w) { cout << "A\n"; return *this;}
};
 
class Word_Pair 
{
public:
   Word w1;
   Word w2;
   // Word_Pair (char *s1, char *s2) : w1(s1), w2(s2) {}
   Word_Pair (char *s1, char *s2) 
   {
      w1 = s1; 
      w2 = s2;
   } 
};        
 
int main ()
{
   Word_Pair p("hello", "world");
   return 0;
}
 
The Doxygen documentation system

 

Using Doxygen via command line

doxygen -g <config-filename>

If you omit the file name, a file named Doxyfile will be created. 

Now, you can edit the configuration file using a text editor. The configuration file has a format that is similar to that of a (simple) Makefile. It consists of a number of assignments (tags) of the form:

TAGNAME = VALUE
TAGNAME = VALUE1 VALUE2 ...

You can leave most of the tags in the template configuration file to their default values.
Here are some tags that you probably need to update:

PROJECT_NAME

The PROJECT_NAME tag is a single word (or a sequence of words surrounded by double-quotes) that should identify the project for which the documentation is generated. This name is used in the title of most generated pages and in a few other places.

PROJECT_NUMBER

The PROJECT_NUMBER tag can be used to enter a project or revision number. This could be handy for archiving the generated documentation or if some version control system is used.

OUTPUT_DIRECTORY

The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path into which the generated documentation will be written. If a relative path is entered, it will be relative to the location where doxygen was started. If left blank the current directory will be used.

GENERATE_HTML

If the GENERATE_HTML tag is set to YES (the default) Doxygen will generate HTML output.

GENERATE_LATEX

If the GENERATE_LATEX tag is set to YES (the default) Doxygen will generate LaTeX output.

For more details about each tag, please read this page.

doxygen <config-filename>

Depending on your settings, Doxygen will create HTML, RTF, LaTeX, XML and/or man directories inside the output directory. As the names suggest, these directories contain the generated documentation in HTML, RTF, LaTeX, XML and Unix-man page format.

Example workflow:

               In the Linux console, type:

                               doxygen -g

               Then edit the default configuration file:

                               pico Doxyfile (or use vi/emacs)

       Change Project_Name to Test_Project, Project_Number to 1, Output_Directory to test_project, and save file.

              Generate documentation by typing:

                               doxygen Doxyfile

       A directory called “test_project” would appear, and by default Doxygen generates both html and latex documentations.

              Go into the html directory, open index.html, and you should see a piece of documentation like this:

               doxygen_example.jpg     


Lab Task

Part I:

Project - Money:

Download the following files: Money.h, Money.cpp main.cpp and place them in a folder named “money”.

 

Your task:

  1. Overload the default constructor of class MoneyType to set the initial value of the data members to be 0. (You need to declare the constructor in Money.h and implement it in Money.cpp.)
  2. Modify the member function Initialize to be another constructor. (You need to modify it in both Money.h and Money.cpp.)
  3. Implement the member function Normalize to normalize the cents to be between 0 and 99 and adjust the dollar amount accordingly. (e.g. 1 dollar and 150 cents should be 2 dollars and 50 cents after normalization.)

 

Project - Grid:

Download the following files: grid3d.h, grid3d.cpp and main.cpp and place them in a folder named “grid”.

 

In main.cpp:

 

Your task:

1.        Implement the following functions in grid3d.cpp.

·           grid3d::grid3d()

·           grid3d::grid3d(const grid3d& g)

·           grid3d::operator=(const grid3d& g)

·           grid3d::~grid3d()

·           grid3d::getx()

·           grid3d::gety()

·           grid3d::getz()

The output should look like this:

Point A is created by typical constructor
Point A is (3, 4, 5)

Point B is created by conversion constructor
Point B is (2, 0, 0)

Point C is created by default constructor
conversion constructor
In destructor
Point C is (-6, 0, 0)

Point D is created by copy constructor
Point D is (3, 4, 5)

Point E is created by typical constructor
Point E is (-2, 2, 7)

Creating an array of points...
default constructor
default constructor
The points in the array are (0, 0, 0)(0, 0, 0)

Please enter three integers to set a point in the array 3 4 5
The point is set to (3, 4, 5)

Start to compute centroid
copy constructor
copy constructor
copy constructor
typical constructor
In destructor
In destructor
In destructor
The centroid of triange (3, 4, 5)(2, 0, 0)(-2, 2, 7) is (1, 2, 4)

Start to compute area
copy constructor
copy constructor
copy constructor
In destructor
In destructor
In destructor
The area of triangle (3, 4, 5)(2, 0, 0)(-2, 2, 7) is 18.554

In destructor
In destructor
In destructor
In destructor
In destructor
In destructor
In destructor
In destructor

Part II:

Your task:

1.        Use Doxygen on Unix to generate HTML documentation for Project Grid in Part I. (Refer to the instructions above or in the slides.)

 

You can try exploring other tags not covered above. Usage of the tags are explained in the default configuration file.

 

Expected Doxygen HTML output for Class grid3d: html\classgrid3d.html