Originally Posted by
matsp
Regarding the date-class, I would probably have a "date-time" class that goes to at least minutes (if not seconds).
I would also consider that the date/time is one unit - you don't set the month only. So your set/get function should take all the day, month, year, hour, minute (and second) as parameters. A getter may want to exist to get only month or some such, but for setter, you set all at once.
[But you may not care if the car is picked up at 00:01 and returned at 23:59 on the same day, and thus "free" to rent because it was out "no days", when in fact it was out 23h58m].
I would also recommend that you store the date/time as one integer (e.g. a 64-bit number representing seconds for 1st Jan 2000 or some such). It makes calculating date/time differences (which you probably will need to do if you are doing car-rentals) much easier. If you don't do that, then you will still need a function to either subtract one date from another and give the result in number of days.
Mats
Is this more like it?
Code:
using namespace std;
#ifndef DATE
#define DATE 1
#endif
class Date
{
public:
Date();
~Date();
Date(int d,int m,int y,int h,int mn,int s);
void setTimeDate(int d,int m,int y,int h,int mn,int s);
int getDay();
int getMonth();
int getYear();
int getHour();
int getMinute();
int getSecond();
private:
int day;
int month;
int year;
int hour;
int minute;
int second;
};
.cpp
Code:
#include "RentalDate.h"
Date::Date()
{
day=month=year=hour=minute=second=0;
}
Date:: ~Date() {}
Date::Date(int d,int m,int y,int h,int mn,int s)
{
setTimeDate(d,m,y,h,mn,s);
}
void Date::setTimeDate(int d,int m,int y,int h,int mn,int s)
{
day=d;
month=m;
year=y;
hour=h;
minute=mn;
second=s;
}
int Date::getDay()
{
return day;
}
int Date::getMonth()
{
return month;
}
int Date::getYear()
{
return year;
}
int Date::getHour()
{
return hour;
}
int Date::getMinute()
{
return minute;
}
int Date::getSecond()
{
return second;
}