1. Engineering
  2. Computer Science
  3. hello this is for programming in c below is the...

Question: hello this is for programming in c below is the...

Question details
Hello, this is for programming in C++. Below is the assignment, it deals with pointers and I am a bit lost on them so please include comments when you can. Thank you very much.

Below the assignment is the default programs associated with this assignment.
Overloading Operators in the Date Class 1. Take a look at the specification file for this class and nocehow it has been set up for operator overloading. Notice also the object otherTime of the Time type that has been added to the private section of this class. So, all Date objects will now have a time object within them. This is an example of containment. This means you will need to copy over your Time class specification and implementation fron last weeks lab to your current directory Type cp . ./Lab2/time. * to copy over these files. Notice that is a space and dot after the asterisk 2. Notice the friend function for operator < and how it is implemented within the specifi- cation file after the formal class definition. This is often done since this function is not a member per se of this class. The line return os; is included in te above function since we are actually changing the status of the buffer and sending this objects data out to actually be printed. 3. Now, lets modify our implementation file, date.cpp. Include a constructor initializer for the contained object otherTime. Also, be sure you have seven parameters for the Date constructor in the date.cpp file. It currently has only four, and must match the Date constructor in the date.h file A constructor initializer here would be the segment : otherTime(initHrs, initMins, initSecs) added after the ending parentheses of the constructor and before the curly braces. That is, Date: :Date int int int int int int const char* msgStrotherTine(initHrs, initMins, initSecs) initMo, initDay, initYr, initHre initMins initSeca, mo initMo; day initDay: yrinitYr: mag neu char[strlen (nsgStr; strcpy (msg, msgStr; 4. You will need to add a line to the end of your Date printing function so that it will call the WriteAmPm function within your Time object that is contained within each Date object. That is, otherTime.WriteA Pm);
5. Now, modify the headers for your three functions that use operator overloading so that they match the headers in your specification file. The CopyFrom function in Date will change to operatorthe LessThan function in Date will change to operator <, and the EqualTo function will change to operator-=. You must preserve the Date member operator. For example, bool Date: operatotDatat otherDate) coast 6. Add a CopyFrom function to your Time class that can be used to copy your three private Time variables to another object. That is void Time: :CopyFrom(Time otherTime) hrs-otherTime.hrs; míns otherTime . míns; secs otherTime.secs Remember to include an appropriate prototype in time.h 7. Youre all set to compile your client file, clientDate.cpp and test it with what youve done so far. Be sure to bring in both object files at compilation. That is, c++ clientDate.cpp time.o date.o.

Here are the default programs as followed: clientDate.cpp, time.cpp, time.h ... (separated by dash symbols)

------------------------------------------------------------------------------------------------
//clientDate.cpp

#include <iostream>
#include "date.h"
using namespace std;
int main()
{
Date date1 (9,2,2002,13,00,00,"Labor Day");
Date date2 (9,6,2002,13,00,00,"First Friday");
Date date3;
cout << "Date1 = " << date1 << endl;
cout << "Date2 = " << date2 << endl;
cout << "Date3 = " << date3 << endl;
date3 = date2;
cout << "Date3 = " << date3 << endl << endl;
if (date1 < date2)
cout << "Date1 Is Less Than Date2." << endl;
else if (date1 == date2)
cout << "Date1 Is Equal To Date2." << endl;
return 0;
}

----------------------------------------------------------------------------------------------------------------
//date.cpp

//******************************************************************
// IMPLEMENTATION FILE (date.cpp)
//******************************************************************
#include <cstring> // For strcpy() and strlen()
#include <iostream>
#include "date.h"
using namespace std;
//******************************************************************
Date::Date( int initMo,
int initDay,
int initYr,
const char* msgStr )
// Constructor
{
mo = initMo;
day = initDay;
yr = initYr;
msg = new char[strlen(msgStr) + 1];
strcpy(msg, msgStr);
}
//******************************************************************
Date::~Date()
{
delete [] msg;
}
//******************************************************************
Date::Date(const Date& otherDate)
{
mo = otherDate.mo;
day = otherDate.day;
yr = otherDate.yr;
msg = new char[strlen(otherDate.msg) + 1];
strcpy(msg, otherDate.msg);
otherTime.CopyFrom(otherDate.otherTime);
}
//******************************************************************
void Date::CopyFrom (const Date& otherDate)
{
mo = otherDate.mo;
day = otherDate.day;
yr = otherDate.yr;
delete [] msg; // Deallocate the
// original array
msg = new char[strlen(otherDate.msg) + 1]; // Allocate a new
// array
strcpy(msg, otherDate.msg); // Copy the chars
otherTime.CopyFrom(otherDate.otherTime);
}
//******************************************************************
void Date::Print() const
{
static char monthString[12][10] =
{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November",
"December"
};
cout << monthString[mo-1] << " " << day << ", " << yr
<< " " << msg << " ";
}
//******************************************************************
bool Date::LessThan (const Date& otherDate) const
{
if (yr < otherDate.yr)
return true;
else if ( (yr == otherDate.yr) && (mo < otherDate.mo) )
return true;
else if ( (yr == otherDate.yr) && (mo == otherDate.mo)
&& (day < otherDate.day) )
return true;
else if ( (yr == otherDate.yr) && (mo == otherDate.mo)
&& (day == otherDate.day) &&
otherTime.LessThan(otherDate.otherTime) )
return true;
else
return false;
}
//******************************************************************
bool Date::EqualTo(const Date& otherDate) const
{
if ( (yr == otherDate.yr) && (mo == otherDate.mo)
&& (day == otherDate.day) && otherTime.Equal(otherDate.otherTime) )
return true;
else
return false;
}
//******************************************************************

-------------------------------------------------------------------------------------------------------------------------
//date.h

//******************************************************************
// SPECIFICATION FILE (date.h)
//******************************************************************
#include "time.h"
using namespace std;
class Date
{
public:
void Print() const;
Date( int initMo = 1,
int initDay = 0,
int initYr = 0,
int initHrs = 0,
int initMins = 0,
int initSecs = 0,
const char* msgStr = "No Date");
Date( const Date& otherDate );
// Copy-constructor
~Date();
// Destructor
bool operator < (const Date& otherDate) const;
bool operator == (const Date& otherDate) const;
void operator = (const Date& otherDate);
private:
int mo;
int day;
int yr;
Time otherTime;
char* msg;
friend ostream& operator << (ostream& os, const Date& date)
{
date.Print();
return os;
}
};

--------------------------------------------------------------------------------------------------------


Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution