I need suggestions on my piece of code.

The purpose of this code is to try and output a start time, start date, finish time, and finish date for an event calling on header files and another .cpp file. I believe i am on the right track but could really use some help!

Header file.

#ifndef EVENT_H
#define EVENT_H
// Event class declaration.
#include <string>
#include <iostream>
#include <cstring>
using namespace std;

class Event
{
public:
Event(); //Default Constructor
Event(string name, int sday, int smonth, int syear, int fday, int fmonth, int fyear,
int shour, int smin, int fhour, int fmin); //Constructor
Event(Event & Event); //Copy Constructor
~Event(); //Destructor
void Print() const;
Date GetStartDate() const;
Date GetFinishDate() const;
Time GetStartTime() const;
Time GetStartTime() const;
float GetDuration() const;
void SetEventName(const string name);
void SetStartDate(const int day, const int month, const int year);
void SetFinishDate(const int day, const int month, const int year);
void SetStartTime(const int hours, const int mins);
void SetFinishTime(const int hours, const int mins);
private:
string name;
Date startDate;
Date finishDate;
Time startTime;
Time finishTime;
};
#endif /* EVENT_H */


#ifndef TIME_H
#define TIME_H

class Time
{
public:
Time();
Time(int,int,int,int);
Time(const Time&);
void setshour(int);
void setsmin(int);
void setfhour(int);
void setfmin(int);
int getshour();
int getsmin ();
int getfhour();
int getfmin();
void printTime();
private:
int shour;
int smin;
int fmin;
int fhour;
};

#endif /* TIME_H */

// Constants
const int NUM_MONTHS = 12;
const int NAME_SIZE = 10;

// Declaration of the Date class

class Date
{
private:
int smonth; // To hold the month
int fmonth;
int sday; // To hold the day
int fday;
int syear; // To hold the year
int fyear;

// An array of char arrays to hold
// the names of the months
char names[NUM_MONTHS][NAME_SIZE];

// Private member function to assign
// the month names to the names array
void setNames();

public:
// Constructors
Date();
Date(int, int, int, int, int, int);
~Date();

// Mutators
void setsmonth(int smo);
void setfmonth (int fmo);
void setsday (int sd);
void setfday(int fd);
void setsyear(int sy);
void setfyear (int fy);

// Functions to print the date
void showDate1()const;
};


Main.cpp (havent gotten to work on this part much yet, trying to get the other two parts done first)
#include <cstdlib>
#include "Event.h"
using namespace std;

int main()
{
Event event1;

event1.Print();

return 0;
}


Alternate.cpp

#include <iostream>
#include "Event.h"
using namespace std;

//----------------------------------------
// Default Constructor
//----------------------------------------
Event::Event()
{

// replace with code to initialize an event
const int size;
char name;

cout<< "what is the name of our event?"<< endl;
cin<<name<<endl

cout << "Constructing an Event" << endl;
}

//----------------------------------------
// Print Method
//----------------------------------------
void Event::Print() const
{
// replace with code to print an event

cout << "Printing an event\n";
}

//Date.cpp
//**********************************
// Default constructor *
//**********************************

Date::Date()
{
setNames();
}

//**********************************
// Overloaded constructor *
// Parameters: mo is the month *
// d is the day *
// y is the year
// s/f are start and finish*
//**********************************

Date::Date(int smo,int fmo, int sd,int fd, int sy, int fy)
{
setsmonth(smo);
setfmonth (fmo);
setsday(sd);
setfday(fd);
setsyear(sy);
setfyear(fy)
setNames();
}

Date::~Date()
{

}

//**********************************
// Member function setNames *
// This function assigns the names *
// of the months to the names *
// array. *
//**********************************

void Date::setNames()
{
strcpy(names[0], "January");
strcpy(names[1], "Febraury");
strcpy(names[2], "March");
strcpy(names[3], "April");
strcpy(names[4], "May");
strcpy(names[5], "June");
strcpy(names[6], "July");
strcpy(names[7], "August");
strcpy(names[8], "September");
strcpy(names[9], "October");
strcpy(names[10], "November");
strcpy(names[11], "December");
}

//**********************************
// Member function setMonth *
//**********************************

void Date::setsmonth(int smo)
{
if (smo >= 1 && smo <= 12)
smonth = smo;
else
{
cout << smo << " is not a valid
<< "value for the month.\n";
exit (EXIT_FAILURE);
}
}
void Date::setfmonth(int fmo)
{
if (fmo >= 1 && fmo <= 12)
fmonth = fmo;
else
{
cout << fmo << " is not a valid "
<< "value for the month.\n";
exit (EXIT_FAILURE);
}
}
//**********************************
// Member function setDay *
//**********************************

void Date::setsday(int sd)
{
if (sd >= 1 && sd <= 31)
sday = sd;
else
{
cout << sd << " is not a valid "
<< "value for the start day.\n";
exit(EXIT_FAILURE);
}
}

//**********************************
// Member function setYear *
//**********************************

void Date::setsyear(int sy)
{
syear = sy;
}

//**********************************
// Member function showDate1 *
// Displays the date in the form *
// MM/DD/YY *
// Example: 12/25/06 *
//**********************************

void Date::showDate1()const
{
cout << smonth << "/"
<< sday << "/"
<< syear <<
<<fmonth<<"/"
<<fday<<"/"
<<fyear<<"/"endl;
}



//*************************************
// Function main *
//*************************************


//time.cpp
Time::Time()
{
shour=smin=fhour=fmin=0;
}

Time::Time(int sh,int fh, int sm,int fm)
{
setshour(sh);
setsmin(sm);
setfmin (fm);
setshour (sh);



}

Time::Time(const Time& obj)
{
shour=obj.shour;
fhour= obj.fhour;
smin=obj.smin;
fmin=obj.fmin;

}

void Time::setshour(int sh)
{
if(0<=sh && sh<24)
shour=sh;
else
shour=0;
}

void Time::setsmin(int sm)
{
if(0<=sm && sm<60)
smin=sm;
else
smin=0;
}
void Time::setfhour(int fh)
{
if(0<=fh && fh<24)
fhour=fh;
else
fhour=0;
}
void Time::setfmin(int fm)
{
if(0<=fm && fm<60)
fmin=fm;
else
fmin=0;
}


int Time::getshour()
{
return shour;
}
int Time:: getfhour()
{
return fhour;
}

int Time::getsmin()
{
return smin;
}
int Time::getfmin()
{
return fmin;
}


void Time::printTime()
{
cout<<shour<<':'<<smin<<':'<<fhour;':'<<fmin << endl;
}


please only write the part of the code you are having problems with
Topic archived. No new replies allowed.