Create a Date class with three integer instance variables named day,month,year.
It has a constructor with three parameters for initializing the instance variables,and it has one method named daysSinceJan1(). It computes and returns the number of days since January 1 of the same year,including January 1 and the day in the Date object.
For example,if day is a Date object with day=1,month=3,and year=2000,then the calldate.daysSinceJan1() should return 61 since there are 61 days between the dates of January 1,2000,and March 1,2000,including January 1 and March 1. Don’t forget to consider leap years.
#include <iostream>
#include <string>
using namespace std;
class Date
{
private:
int month, day, year;
public:
Date();
Date(int month, int day, int year) {
this->day = day;
this->month = month;
this->year = year;
}
~Date(){}
void setDay(int day){
this->day = day;
}
void setMonth(int month){
this->month = month;
}
void setYear(int){
this->year = year;
}
};
Comments
Leave a comment