P10_ex Example Date Class Interface |
|
Description: The purpose of this C++ programming example is to familiarize students
with defining classes from a Uniform Modeling Language (UML) Class Diagram. In prior assignments we saw how structure charts could be
used to design a modular program using the top-down design methodology and how flowcharts could be used to depict the detail logic of a specific module. To design an object-oriented program, we can also use symbolic notation. There are a few modeling languages to choose from, but UML has quickly become a de-facto standard.
The only thing included in this example
is the class definition. The functions for the class definition are defined in P11ex Date
Implementation.
In addition, a main function is required by the compiler in order for it to compile the program, so an
empty main function is defined.
UML - Class Diagram:
Symbol definitions:
- private
+ public
# protected
| DateMDY |
|---|
|
- int month - int day - int year |
|
+ DateMDY( ) //default constructor doesn't have parameters + DateMDY(int m, int d, int y) //overloaded constructor; //parameter names in overloaded constructors should be different //from the class variable names, because the parameter values //are going to be assigned to the class variables. + ~DateMDY( ) //destructor //Set accessors do NOT return a value (void) because they are used //to assign a value to a private variable. The value to assign is //passed through the parameter. + void setMonth(int m) + void setDay(int d) + void setYear(int y) //Get accessors are used to return the value stored in a private //variable, so a parameter is not passed. + int getMonth( ) + int getDay( ) + int getYear( ) //Input accessors prompt for, get, and store a value in a private //variable. A value is not returned and a parameter is not passed. + void inputMonth( ) + void inputDay( ) + void inputYear( ) |
Source Code:
//P10ex DateMDY Class - Juan Marquez
//
//This program only includes the DateMDY class definition
//
//class Interface
class DateMDY
{
private:
//private member variables require accessors
int month;
int day;
int year;
public:
//default constructor - will call input functions
DateMDY();
//overloaded constructor - will assign parameter values to private variables
DateMDY(int m, int d, int y);
//destructor
~DateMDY();
//accessors
void setMonth(int m);
void setDay(int d);
void setYear(int y);
int getMonth();
int getDay();
int getYear();
void inputMonth();
void inputDay();
void inputYear();
};
//Need empty main so program will compile
void main()
{
return;
}
//end of P10ex.cpp