新手初来乍到 最简单的一些求帮忙 刚从其他语言过来
1- Complete the implementation of the class date that represents dates written in the form day/month/year. Do not modify the main program. You must write the prototypes and the definitions of the methods of the class.
Declaration of Class Date
-----------------------------------------------------------------------------------------------------------------
/* File: date.h
A class representing dates in the form: day , month and year
dat e s are written to a stream in the form day/month/ year
day_number( ) returns the number of days since 1/1 of the current
year including the current day
days_between( ) returns the number of days between two dates not
including the first day but including the last day. */
#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <fstream>
using namespace std ;
class date {
private :
int day ;
int month ;
int year ;
public :
// you fill in the method prototypes
};
#endif /* DATE_H */
---------------------------------------------------------------------------------------------------
Implementation of Class Date
/* File : date.cpp
Implementation of class date */
#include "date.h"
#include <cmath>
// number of days in each month
const int DAYS[ 12 ] = {31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
///////////////////////// Methods of date ////////////////////////////
-------------------------------------------------------------------------------------------------
Main Program Using Class Date
/* File : testdate.cpp
Application program using class time
Programmer : your name Date : */
#include "date.h"
int main (void)
{
ofstream fout("date.txt");
date d(12 , 6 , 2016);
date e(14 , 9 , 2018);
fout << "For the date " ;
d.write( fout ) ;
fout << endl ;
fout << "Day number is " << d.day_number() << endl;
fout << "\nFor the date " ;
e.write(fout);
fout << endl;
fout << "Day number is "<< e.day_number() << endl;
fout << "\nDays between " ;
d.write(fout) ;
fout << " and ";
e.write(fout);
fout << " = " << d.days_between(e) << endl;
fout.close();
return 0 ;
}
Your program output should be:
For the date 12/6/2016
Day number is 163
For the date 14/9/2018
Day number is 257
Days between 12/6/2016 and 14/9/2018 = 824
compile code is
g++ date.cpp testDate.cpp -o testDate