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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 秋天的菠菜

大学计算机基础实验 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 }