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

I\'ve finished most of the parts and started on the .cpp file which im having tr

ID: 3633431 • Letter: I

Question

I've finished most of the parts and started on the .cpp file which im having trouble with. Here's the instructions.

You will need to make an implementation file called DateTime.cpp. This file will need to include <cstring> and <cstdlib>.

Hint: You will want to use a temporary array to convert integers to ASCII (itoa), and use strcpy and strcat to build the string in your constructor since we are working with a c-string. Then create a short program that uses the original date and time classes as well as the DateTime.cpp(Franken class)..All of this can be placed in the DateTime.cpp


____________Time.h______________

#ifndef TIME_H
#define TIME_H

class Time
{
protected: //member variables
int hour;
int min;
int sec;
public: //accessor functions
int getHour(){return hour;}
int getMin(){return min;}
int getSec(){return sec;}
Time();
Time (int hr, int mn, int sc);
};

Time::Time()
{
hour = 0;
min = 0;
sec = 0;
}

Time::Time(int hr, int mn, int sc)
{
hour = hr;
min = mn;
sec = sc;
}

#endif

______________Date.h________

#ifndef DATE_H
#define DATE_H

class Date
{
protected: //member variables
int day;
int month;
int year;

public: //accessor functions
int getDay(){ return day;}
int getMonth(){return month;}
int getYear(){return year;}
Date();
Date(int dy, int mo, int yr);
};
Date::Date()
{
day = 0;
month = 0;
year = 0;
}

Date::Date (int dy, int mo, int yr)
{
  day = dy;
  month = mo;
  year = yr;
}

#endif

___________DateTime.h____________

// Specification file for the DateTime Class
#ifndef DATETIME_H
#define DATETIME_H

// we need to include both the date and time classes
#include "Date.h"
#include "Time.h"

class DateTime : public Date, public Time
{
protected:
char dateTimeString[20];
public:
DateTime(int dy, int mon, int yr, int hr, int mt, int sec); // Overloaded Constructor

const char *getDateTime()
{
  return dateTimeString;
}
}; // End DateTime Frankenclass

#endif

_________DateTime.cpp__________

#include <iostream>
#include <cstdlib>
#include "Time.h"
#include "Date.h"
#include "DateTime.h"
#include <cstring>
using namespace std;
int main()
{


DateTime(int dy, int mon, int yr, int hr, int mt, int sec); // Overloaded Constructor
char



return 0;
}

Explanation / Answer

Dear

//_________DateTime.cpp__________

#include <iostream>
#include <cstdlib>
#include "Time.h"
#include "Date.h"
#include "DateTime.h"
#include <cstring>
using namespace std;

DateTime::DateTime(int dy, int mon, int yr, int hr, int mt, int sec) // Overloaded Constructor
{
    char tmp[5] = "";
    strcpy(dateTimeString, "");   
    strcat(dateTimeString,itoa(dy,tmp,10));
    strcat(dateTimeString, "-");
    strcat(dateTimeString,itoa(mon,tmp,10));
    strcat(dateTimeString, "-");
    strcat(dateTimeString,itoa(yr,tmp,10));
    strcat(dateTimeString, ", ");
    strcat(dateTimeString,itoa(hr,tmp,10));
    strcat(dateTimeString, ":");
    strcat(dateTimeString,itoa(mt,tmp,10));
    strcat(dateTimeString, ":");
    strcat(dateTimeString,itoa(sec,tmp,10));
}

int main()
{
    Date d(15,11,2011);
    Time t(8,36,54);
    DateTime dt(15,11,2011,8,36,54);
    cout<<"DateTime: "<<dt.getDateTime() << endl;

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