新手初来乍到 最简单的一些求帮忙 刚从其他语言过来

Changgg_ 2019-06-10 03:43:43
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
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andy1989630 2019-06-11
  • 打赏
  • 举报
回复
你是求帮忙翻译么?
Changgg_ 2019-06-10
  • 打赏
  • 举报
回复
Changgg_ 2019-06-10
  • 打赏
  • 举报
回复

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧