Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION: What changes to the member functions of the DATE abstract data type wo

ID: 2246485 • Letter: Q

Question

QUESTION: What changes to the member functions of the DATE abstract data type would be required when Dr. Hanna modifies the data model as shown below? Hint The data member MM is no longer an integer; it is instead a pointer-to a NUL-terminated string which is dynamically-allocated from the run-time heap. Draw a picture of an instance of the DATE object pointed-to by the pointer DATE *date. Code is already completed below.

Create the C++ project named Problem for the client application program Problem.cpp—the project must contain the 3 files Dr. Hanna provided you—Date.h, Date.cpp, and Problem.cpp—you are not required to change my code in any way.

//-------------------------------------------------

// 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 <iostream>

#include <iomanip>

#include <cstdlib>

#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 <iostream>

#include <iomanip>

#include <cstdlib>

#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 );

}

Explanation / Answer

I have updated the code so that it now handles MM as c-string and not Integer

//-------------------------------------------------------------------------------------------//

//-------------------------------------------------

// Dr. Art Hanna

// Date.h

//-------------------------------------------------

#ifndef DATE_H

#define DATE_H

struct DATE

{

   char MM[10];

   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,char* MM);

void SetDateDD(DATE *date,int DD);

void SetDateYYYY(DATE *date,int YYYY);

char* GetDateMM(const DATE *date);

int GetDateDD(const DATE *date);

int GetDateYYYY(const DATE *date);

#endif

//-------------------------------------------------

// Dr. Art Hanna

// Date.cpp

//-------------------------------------------------

#include <iostream>

#include <iomanip>

#include <cstdlib>

#include <cstring>

#include ".Date.h"

using namespace std;

//-------------------------------------------------

void ConstructDate(DATE *date)

//-------------------------------------------------

{

   date->DD = 12; strcpy(date->MM, "Jan"); 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 << date->MM << "-" << setw(2) << date->DD << "-" << setw(4) << date->YYYY;

}

//-------------------------------------------------

void SetDateMM(DATE *date,char* MM)

//-------------------------------------------------

{

   strcpy(date->MM, MM);

}

//-------------------------------------------------

void SetDateDD(DATE *date,int DD)

//-------------------------------------------------

{

   date->DD = DD;

}

//-------------------------------------------------

void SetDateYYYY(DATE *date,int YYYY)

//-------------------------------------------------

{

   date->YYYY = YYYY;

}

//-------------------------------------------------

char* 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 <iostream>

#include <iomanip>

#include <cstdlib>

#include ".Date.h"

using namespace std;

//-------------------------------------------------

int main()

//-------------------------------------------------

{

   DATE date1,date2;

   ConstructDate(&date1);

   ConstructDate(&date2);

   SetDateMM(&date1,"Jan");

   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 << date2.MM << "/"

        << setw(2) << GetDateDD(&date2) << "/"

        << setw(4) << GetDateYYYY(&date2);

   cout << endl;

   DestructDate(&date2);

   DestructDate(&date1);

   system("PAUSE");

   return( 0 );

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote