




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、xx年X月X日精品范文-C+实验报告_实习总结最近发表了一篇名为#includeiostream#includestringusing namespace std;bool isMatch(string s);int main() bool isMatch(string s) else if (si = A&;&;si = Z) &;&;(slen - i - 1 = a&;&;slen - i - 1 = if (si!= (slen - i - 1 - (a- A) return false; if (si!= (slen - i - 1 + (a- A) return false;int
2、 len = s.length();for (int i = 0;ilen / 2;i+) if (si = a&;&;si = z) &;&;(slen - i - 1 = A&;&;slen - i - 1 = Z) string s;while (1) return 0;cin s;if (spare(000000) = 0) if (isMatch(s) else cout Not symmetryendl;cout Symmetryendl;break;z) else if (si = &;&;slen - i - 1 = ) else if (si = &;&;slen - i -
3、 1 = ) else if (si = &;&;slen - i - 1 = ) else if (si = (&;&;slen - i - 1 = ) else if (si!= slen - i - 1) return false;continue;continue;continue;continue;return true;/Time.h#includeiostreamclass Time public:;/Time.cpp#include Time.h#includeiostreamvoid Time:inputT()begin:int a,b,c;std:coutInput tim
4、e(H:M:S)n;std:cin a b c;if (c 60 | c 0) else std:cout Wrong time!Please set again!n;goto begin;int h;int m;int s;void inputT();void changeT();void outputT(); if (b 60 | b 0) else if (a 24 | a 0) else if (a = 24) else h = a;m = b;s = c;if (b!=0 | c!=0) else h = a;m = b;s = c;std:cout Wrong time!Pleas
5、e set again!n;goto begin;std:cout Wrong time!Please set again!n;goto begin;std:cout Wrong time!Please set again!n;goto begin;void Time:changeT() char p;std:cout Do you wanna change time(Y/N): n;std:cin p;if (p = n| p = N) std:cout Thank you for your using!n;下页C+实验报告 begin1:int a,b,c;std:cout Input t
6、ime(H:M:S)n;std:cin a b c;if (c 60 | c 0) else if (b 60 | b 0) else if (a 24 | a 0) else if (a = 24) else h = a;m = b;s = c;if (b!= 0 | c!= 0) else h = a;m = b;s = c;std:cout Wrong time!Please set again!n;goto begin1;std:cout Wrong time!Please set again!n;goto begin1;std:cout Wrong time!Please set a
7、gain!n;goto begin1;std:cout Wrong time!Please set again!n;goto begin1;void Time:outputT()/testmain.cpp#includeTime.h#includeiostreamvoid main(void) Time time1;time(1)、inputT();time(1)、outputT();time(1)、changeT();time(1)、outputT(); std:cout Output time(H:M:S)nh :m :s;(一)、头文件部分#pragma once/class Date
8、with year-month-day version#includeiostream#includestringusing namespace std;class Date ;(二)、函数定义 int year,month,day;Date(int n = 1) int ymd2i()const;void i2ymd(int n);static const int tians;Date(const string&;s);Date(int y,int m,int d):year(y),month(m),day(d) Date operator+ (int n)const Date&;opera
9、tor+=(int n) Date&;operator+() int operator-(Date&;d)const bool isLeapYear()const friend ostream&;operator(ostream&;o,const Date&;d);return!(year % 4) &;&;(year % 100) |!(year % 400);return ymd2i() - d.ymd2i();return xthis += 1;i2ymd(ymd2i() + n);return xthis;return Date(ymd2i() + n);i2ymd(n);public
10、:/Date.cpp/Class Date with year-month-day Version#includeDate.h#includeiostream#includeiomanip#includestringusing namespace std;const int Date:tians = 0,31,59,90,120,151,181,212,243,273,304,334 ;const int Y400 = 146097;/number of days of 400 yearsconst int Y100 = 36524;/number of days of 100 yearsco
11、nst int Y4 = 1461;/number of days of 4 yearsDate:Date(const string&;s) (转载于:在点 网)void Date:i2ymd(int absDay) int Date:ymd2i()const int yearDay = (year - 1) x 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;return yearDay + tiansmonth - 1 + (isLeapYear() &;&;month 2) + day;year = absDay /
12、Y400 x 400;int y = absDay%Y400;/被400年除得的天数 if (y = Y400 - 1) year += y / Y100 x 100;y %= Y100;year += y / Y4 x 4;y%=Y4;if (y = Y4 - 1) year += y / 365;y %= 365;if (y = 0) year+;bool leap = isLeapYear();for (month = 1;month12 &;&;ytiansmonth + (month = 2 &;&;leap);month+);day = y - tiansmonth - 1;mon
13、th = 12,day = 31;return;month = 12,day = 30;return;month = 12,day = 30;return;year = atoi(s.substr(0,4).c_str();month = atoi(s.substr(5,2).c_str();day = atoi(s.substr(8,2).c_str();ostream&;operator(ostream&;o,const Date&;d) return o setfill(0) setw(4) d.year -setw(2) d.month -(三)、testmain/testmain.c
14、pp/using Date class#includeDate.h#includeiostreamusing namespace std;int main() Date d1(2xx,8,21);Date d2(2xx,8,8);cout2xx.(8)、)21与2xx.8,8中间相隔的天数是:d2 - d1 n;cout 2xx.(8)、)21加上300天是:d1 + 300 n; setw(2) d.day setfill();【程序结果】实验5 面向对象程序设计(4)【实验要求】在上题Date类的基础上,继承一个WDate类,它包含了星期几信息,因而,显示日期的成员要做修改,应同时显示星期
15、几。另外,还要增加获得星期几的成员。想一想,类中数据成员置年、月、日好呢,还是绝对天数好呢进而进行应用程序设计:创建2xx.(8)、)21和2xx.(8)、)8两个日期,分别显示这两个日期。【实验程序】(一)、头文件Date.h#pragma once/Date.h/class Date with year-month-day version#includeiostream#includestringusing namespace std;class Date ;int year,month,day;static const int tians;Date(int n = 1) int ymd2
16、i( )const;void i2ymd(int n);Date(const string&;s );Date(int y,int m,int d) :year(y),month(m),day(d) Date operator+(int n)const Date&;operator+=(int n) Date&;operator+() int operator-(Date&;d)const bool isLeapYear()const friend ostream&;operator(ostream&;o,const Date&;d);return!(year % 4) &;&;(year %
17、 100) |!(year % 400);return ymd2i() - d.ymd2i();return xthis += 1;i2ymd(ymd2i() + n);return xthis;return Date(ymd2i() + n);i2ymd(n);protected: public:上页下页余下全文C+实验报告(二)、头文件WDate.h#pragma once/WDate.h#includeDate.h#includeiostream#includestringusing namespace std;class WDate :public Date protected:WDa
18、te operator+(int n) const return Date:operator+(n); WDate&;operator+=(int n) Date:operator+=(n);return xthis; WDate&;operator+() return xthis += 1; int getWeekDay() return ymd2i() % 7;/0:Sunday,1:Monday, operator-(WDate&;wd)const return ymd2i() - wd.ymd2i(); friend ostream&;operator(ostream&;
19、o,const WDate&;wd);WDate(int n = 1) :Date(n) WDate(const Date&;d) :Date(d) WDate(const string&;s) :Date(s) WDate(int y,int m,int d) :Date(y,m,d) public:(三)、Date.cpp/Date.cpp/Class Date with year-month-day Version#includeDate.h#includeiostream#includeiomanip#includestringusing namespace std;const int
20、 Date:tians = 0,31,59,90,120,151,181,212,243,273,304,334 ;const int Y400 = 146097;/number of days of 400 yearsconst int Y100 = 36524;/number of days of 100 yearsconst int Y4 = 1461;/number of days of 4 yearsDate:Date(const string&;s) void Date:i2ymd(int absDay) year = absDay / Y400 x 400;int y = abs
21、Day%Y400;/被400年除得的天数 if (y = Y400 - 1) month = 12,day = 30;year = atoi(s.substr(0,4).c_str();month = atoi(s.substr(5,2).c_str();day = atoi(s.substr(8,2).c_str(); return;year += y / Y100 x 100;y %= Y100;year += y / Y4 x 4;y %= Y4;if (y = Y4 - 1) year += y / 365;y %= 365;if (y = 0) year+;bool leap = isLeapYear();for (month = 1;month12 &;&;ytiansmonth + (month = 2 &;&;leap);month+);day = y - tiansmonth - 1;month = 12,day = 31;return;month = 12,day = 30;return;int Date:ymd2i()const ostream&;operator(ostream&;o,const Date&;d) return o setfill(0) setw(4) d.year -setw(2) d.month -setw(2) d.day s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 设备预知维修管理制度
- 设计研发中心管理制度
- 评估外聘专家管理制度
- 诊所药品供货管理制度
- 2025年中国滑动窗行业市场全景分析及前景机遇研判报告
- 调度系统设备管理制度
- 财务风险预警管理制度
- 货代公司人员管理制度
- 货架物品摆放管理制度
- 货车油路直供管理制度
- 小儿高热惊厥急救与护理
- 云计算试题及答案
- 政治●湖北卷丨2024年湖北省普通高中学业水平选择性考试政治试卷及答案
- 中医医院现代医院管理制度章程
- 无锡市2024-2025学年四年级下学期数学期末试题一(有答案)
- 福建省2025年6月普通高中学业水平合格性考试地理模拟卷二(含答案)
- 2025年山东省济宁市泗水县中考三模地理试题(含答案)
- 2025年文件归档管理考试题及答案分析
- 文明小学生主题班会课件
- 2024年医生三基三严模拟习题(附答案解析)
- 2024年中考历史试题分类汇编:世界近代史(原卷版+解析)
评论
0/150
提交评论