Question
Characterize each DATE member function as either constructor , destructor , accessor , or mutator Code is already completed below. //------------------------------------------------- // Dr. Art Hanna
Characterize each DATE member function as either constructor, destructor, accessor, or mutator
Code is already completed below.
//-------------------------------------------------
// Dr. Art Hanna
// Date.h
//-------------------------------------------------
#ifndef DATE_H
#define DATE_H
struct DATE
{
int MM;
int DD;
int YYYY;
};
void ConstructDate(DATE *date);
void DestructDate(DATE *date);
void InputDate(DATE *date);
void OutputDate(const DATE *date);
void SetDateMM(DATE *date,int MM);
void SetDateDD(DATE *date,int DD);
void SetDateYYYY(DATE *date,int YYYY);
int GetDateMM(const DATE *date);
int GetDateDD(const DATE *date);
int GetDateYYYY(const DATE *date);
#endif
//-------------------------------------------------
// Dr. Art Hanna
// Date.cpp
//-------------------------------------------------
#include
#include
#include
#include ".\Date.h"
using namespace std;
//-------------------------------------------------
void ConstructDate(DATE *date)
//-------------------------------------------------
{
date->DD = 12; date->MM = 1; date->YYYY = 1993;
cout << "Date construction of "; OutputDate(date); cout << endl;
}
//-------------------------------------------------
void DestructDate(DATE *date)
//-------------------------------------------------
{
cout << "Date destruction of "; OutputDate(date); cout << endl;
}
//-------------------------------------------------
void InputDate(DATE *date)
//-------------------------------------------------
{
cout << " MM? "; cin >> date->MM;
cout << " DD? "; cin >> date->DD;
cout << "YYYY? "; cin >> date->YYYY;
}
//-------------------------------------------------
void OutputDate(const DATE *date)
//-------------------------------------------------
{
// Use the format MM-DD-YYYY
cout << setw(2) << date->MM << "-" << setw(2) << date->DD << "-" << setw(4) << date->YYYY;
}
//-------------------------------------------------
void SetDateMM(DATE *date,int MM)
//-------------------------------------------------
{
date->MM = MM;
}
//-------------------------------------------------
void SetDateDD(DATE *date,int DD)
//-------------------------------------------------
{
date->DD = DD;
}
//-------------------------------------------------
void SetDateYYYY(DATE *date,int YYYY)
//-------------------------------------------------
{
date->YYYY = YYYY;
}
//-------------------------------------------------
int GetDateMM(const DATE *date)
//-------------------------------------------------
{
return( date->MM );
}
//-------------------------------------------------
int GetDateDD(const DATE *date)
//-------------------------------------------------
{
return( date->DD );
}
//-------------------------------------------------
int GetDateYYYY(const DATE *date)
//-------------------------------------------------
{
return( date->YYYY );
}
//-------------------------------------------------
// Dr. Art Hanna
// Chapter #3 Problem, Part 1
// Problem.cpp
//-------------------------------------------------
#include
#include
#include
#include ".\Date.h"
using namespace std;
//-------------------------------------------------
int main()
//-------------------------------------------------
{
DATE date1,date2;
ConstructDate(&date1);
ConstructDate(&date2);
SetDateMM(&date1,1);
SetDateDD(&date1,30);
SetDateYYYY(&date1,1979);
OutputDate(&date1); cout << endl;
cout << "date2? " << endl; InputDate(&date2);
// OMG! An example of the violation of the principle of information hiding!!!
cout << setw(2) << date2.MM << "/"
<< setw(2) << GetDateDD(&date2) << "/"
<< setw(4) << GetDateYYYY(&date2);
cout << endl;
DestructDate(&date2);
DestructDate(&date1);
system("PAUSE");
return( 0 );
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started