Question: Complete the program date.cpp which uses the class date to represent dates written in the form day/month/year. Do not modify the main program. You must

Complete the program date.cpp which uses the class date to represent dates written in the

form day/month/year. Do not modify the main program.

You must write the prototypes and the denitions of the methods of the class. Keep the

following rules in mind:

Rule regarding pass by reference:

When deciding how to pass function arguments:

if the argument must be changed by the function {

pass by reference

}

else if the argument is an object {

pass by reference but declare the object to be const

}

else{

pass by value

}

Rule regarding const methods:

If a method does not change the object then the keyword const is placed after the function.

/* File: date.cpp

A class representing dates in the form: day, month and year

dates are written to a stream in the form day/month/year

Assignment 2 6

day_number() returns the number of days since 1/1 of the current year

including the current day

#include

#include

using namespace std;

class date {

private:

int day;

int month;

int year;

public:

// you fill in the method prototypes

};

// number of days in each month

const int DAYS[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

int main(void)

{

ofstream fout("date.out");

date d(12, 6, 2010);

date e(19, 9, 2013);

fout << "For the date is ";

d.write(fout);

fout << endl;

fout << "Day number is " << d.day_number() << endl;

fout << " For the date is ";

e.write(fout);

fout << endl;

fout << "Day number is " << e.day_number() << endl;

return 0;

}

///////////////////////// Methods of date ////////////////////////////

/////////////////////////////////////////////////////////////////////////////

Your program output should be:

For the date is 12/6/2010

Day number is 163

For the date is 19/9/2013

Day number is 262

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!