class constructor to create date and time
Write your question here.
im trying to create two classes: a Date class and a Time class. The Date class has to have three private data members: day, month and year. The Time class should have two private data members: hour and minute. Each class should have two member functions: a constructor and display.
im lost and my code won't run
class Date {
private:
int month, day, year;
public:
Date(int m, int d, int y){
month = m;
day = d;
year = y;
}
};
#endif
#include<iostream>
#include "Date.h"
Date::
void Date::Display( int m, int d, int y)
{
month = m;
day = 0;
year = y;
cout<<month<<" "<<date<<", "<<year<<endl;
}
#include "Date.h"
#include "Time.h"
int main()
{
Date dt(7,4,1776);
Time tm(12,3);
dt.display();
tm.display();
return 0;
Re: class constructor to create date and time
Define "won't run".
I also cannot understand the purpose of these two classes.
for example: what could this mean:
Code:
Date dt(7777 ,-3444444, -117769999);
Time tm(4512, -888888883);
Re: class constructor to create date and time
Before posting code, please format properly and use code tags. Go advanced, select the code and click '#'.
Your class Date definition doesn't have a member function for display either declared or defined.
Code:
Date:: void Date::display( int m, int d, int y)
{
This is an invalid construct. If you have declared the function in the class definition then it should be
Code:
void Date::display(int m, int d, int y)
As Victor notes in post #2, there is no error checking of constructor parameters to make sure they are a valid date.