CS 1440 Lab 7

Cover sheetPrevious ActivityNext Activity

Activity 7-3: Writing your own class

Activity Goals

        Understand C++ classes through experience and practice

Activity Procedure

Write a C++ program (in a file called money.C) that implements the class Money defined below.  You need to:

1.      Implement the member functions,

2.      Write a main function to “exercise” the class by calling all its member functions:

a.       declare several objects of type Money

b.      “Initialize” the objects with whatever values you choose

c.       “Add” some money together

d.      Display the money values to verify everything works.


class  Money
          int Dollars();  /* returns value of dollars data member */
          int Cents();    /* returns value of cents data member */
          void Initialize(int d, int c);  /* sets data members */
          void Add(Money m);  /* adds parameter’s money to data members */
          void Display();     /* prints out with $ and decimal pt. */

          int dollars;
          int cents;

Activity Followup

In your money.C program did you:

o       print the money after initializing?

o       try adding money values where the cents cause a carry into the dollars? (e.g., $2.67+$3.67)