惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
D
Docker
GbyAI
GbyAI
Y
Y Combinator Blog
C
Check Point Blog
M
MIT News - Artificial intelligence
Martin Fowler
Martin Fowler
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Blog — PlanetScale
Blog — PlanetScale
P
Palo Alto Networks Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
V
Vulnerabilities – Threatpost
I
InfoQ
Simon Willison's Weblog
Simon Willison's Weblog
博客园_首页
T
Threat Research - Cisco Blogs
J
Java Code Geeks
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
阮一峰的网络日志
阮一峰的网络日志
O
OpenAI News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
Forbes - Security
Forbes - Security
AWS News Blog
AWS News Blog
雷峰网
雷峰网
博客园 - 三生石上(FineUI控件)
S
Security Affairs
H
Heimdal Security Blog
Engineering at Meta
Engineering at Meta
T
Troy Hunt's Blog
T
Tenable Blog
MongoDB | Blog
MongoDB | Blog
H
Hacker News: Front Page
IT之家
IT之家
N
News and Events Feed by Topic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
S
Secure Thoughts
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss

博客园 - 秋天的菠菜

大学计算机基础实验 2013年信1204-1-2班小学期<程序设计技能训练>作品 C++程序设计(第2版)课后习题答案--第14章 C++程序设计(第2版)课后习题答案--第12章 C++程序设计(第2版)课后习题答案--第11章 C++程序设计(第2版)课后习题答案--第8章 C++程序设计(第2版)课后习题答案--第4章 关于指针的经典例题 Java多线程读文件比单线程提高效率的实例 第一门编程语言选谁?(转) C语言程序设计实验指导书 寂寞让生命如此美丽 循环结构经典程序 C语言初学者最容易犯的错误 正则表达式 用脚本类IDS抵御针对WEB的攻击 java实验一 方法和构造方法 java实验二 类和对象 java实验四 面向对象的综合应用 java实验三 类的继承与多态
C++程序设计(第2版)课后习题答案--第13章
秋天的菠菜 · 2013-03-25 · via 博客园 - 秋天的菠菜

P317,13.3

View Code

 1 #include <iostream>
 2 #include <stdlib.h>
 3 using namespace std;
 4 
 5 static char daytable[2][13]={
 6     {0,31,28,31,30,31,30,31,31,30,31,30,31},
 7     {0,31,29,31,30,31,30,31,31,30,31,30,31}
 8 };
 9 class Date
10 {    
11     //重载为友元
12     //friend Date & operator+(Date &date,int d);
13     friend ostream & operator<<(ostream &output,Date &d);
14 public:
15     Date();
16     Date(int y,int m,int d);
17     ~Date();
18     //重载为成员函数
19     Date & operator+(int d);
20     static int isLeap(int y);
21     
22 protected:
23     int year,month,day;
24 };
25 
26 Date::Date()
27 {
28     year=2013;
29     month=3;
30     day=25;
31 }
32 
33 Date::Date(int y,int m,int d)
34 {
35     year=y;
36     month=m;
37     day=d;
38 }
39 
40 int Date::isLeap(int y)
41 {
42     return (y%4==0 && y%100 || y%400==0);
43 }
44 
45 Date::~Date()
46 {}
47 
48 Date & Date::operator+(int d)
49 {
50     while(day+d>daytable[isLeap(year)][month])
51     {
52         d-=daytable[isLeap(year)][month]-day;
53         if(month==12)
54         {
55             year++;
56             month=1;
57         }
58         else
59             month++;
60         day=0;
61     }
62     day+=d;
63     
64     return *this;
65 }
66 
67 
68 ostream & operator<<(ostream &output,Date &d)
69 {
70     output<<d.year<<"-"<<d.month<<"-"<<d.day<<endl;
71     return output;
72 }
73 
74 /*
75 Date & operator+(Date &date,int d)
76 {
77 while(date.day+d>daytable[Date::isLeap(date.year)][date.month])
78 {
79 d-=daytable[Date::isLeap(date.year)][date.month]-date.day;
80 if(date.month==12)
81 {
82 date.year++;
83 date.month=1;
84 }
85 else
86 date.month++;
87 date.day=0;
88 }
89 date.day+=d;
90 return date;
91 }*/
92 
93 void main()
94 {
95     Date d(2013,3,25);
96     d=d+365;
97     cout<<d;
98     //system("pause");
99 }

P317,13.7

View Code

 1 #include <iostream>
 2 #include <iomanip>
 3 //#include <stdlib.h>
 4 using namespace std;
 5 
 6 class Time
 7 {
 8     friend ostream & operator<<(ostream &output,Time &time);
 9     friend istream & operator>>(istream &input,Time &time);
10 public:
11     Time(int h=0,int m=0,int s=0);
12 private:
13     int hour,minute,second;
14 };
15 
16 Time::Time(int h,int m,int s)
17 {
18     hour=(h>=0 && h<=23)?h:0;
19     minute=(m>=0 && m<=59)?m:0;
20     second=(s>=0 && s<=59)?s:0;
21 }
22 
23 ostream & operator<<(ostream &output,Time &time)
24 {
25     output<<setw(2)<<setfill('0')<<time.hour<<":"
26         <<setw(2)<<setfill('0')<<time.minute<<":"
27         <<setw(2)<<setfill('0')<<time.second<<endl;
28     //output<<time.hour<<":"<<time.minute<<":"<<time.second;
29     return output;
30 }
31 
32 istream & operator>>(istream &input,Time &time)
33 {
34     char buffer[81];
35     input.getline(buffer,3,'-');
36     time.hour=atoi(buffer);
37     input.getline(buffer,3,'-');
38     time.minute=atoi(buffer);
39     input.getline(buffer,3,'\n');
40     time.second=atoi(buffer);
41     return input;
42 }
43 
44 void main(void)
45 {
46     Time time(12,36,25);
47     cout<<"hh-mm-ss:"<<endl;
48     cin>>time;
49     cout<<time;
50     //system("pause");
51 }