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.      "Set" the objects to whatever values you choose

c.       Display the money values

d.      Set some of the money objects to different values.

e.       Display the money values

 

class  Money
{
     public:

                 /* Two member functions to return
                    data member values (accessors) */

          int Dollars();
          int Cents();
 
                 /* A member function to put
                    values into the data members */

          void Set_dollars_and_cents(int d, int c);
 
                 /* A member function to print
                    value with '$' and decimal point. */

          void Display();

     private:
          int dollars;
          int cents;
};

Activity Followup

Add code to the end of your money.C program to make it prompt the user for a values of dollars and cents to set an object to. Make sure you print the value before and after setting the data members.