1、实验报告模板C+实验报告【实验报告模板】C+实验报告各位读友大家好,此文档由网络收集而来,欢迎您下载,谢谢C+实验报告实验1-1过程化编程【实验目的】理解、掌握过程化编程程序设计思想。【实验内容】1.程序填空,练习类、对象、继承的定义和实现方法。2.根据程序运行结果,补充完整程序。【实验要求】我们在进行英语阅读的时候,会发现一个有趣的现象:有些字串是左右对称的,如madam。我们把这种字串称为symmetry text 即“对称文”。现在有若干航字串,每一行可以由数字、标点符号、空格符以及英文字符(包括大小写)组成。要你帮忙编程判断是否是对称文,否则,就不能最大限度地发现有趣现象了。输入说明每
2、个字串为一行,每行结束以回车符为标志,可能有上百上千行业说不定。当字串为“000000”时,输入结束。英文字符不区分大小写,即Madam亦为对称文。不要忘了“”也是互为对称的。输出说明如果是对称文,则输出“Symmetry”,否则输出“Not symmetry”。每个结论占一行。图 1 图 2【程序代码】 #include#includeusing namespace std;bool isMatch(string s);int main() bool isMatch(string s) else if (si = A&si = a&slen - i - 1 = a&si = A&slen -
3、 i - 1 s;if (“000000”) = 0) if (isMatch(s) else cout ) 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;【运行结果】图 3 实验一运行结果实验1-2面向对象编程技术(1)最全面的范文参考写作网站【实验目的】理解面向对象的的程序设计思想。【实验内容】定义一个时间类Time,能提供和设置由
4、时、分、秒组成的时间,并编出应用程序,要求包括定义时间对象,设置时间,输出该对象提供的时间。并请将类定义作为界面,用多文件结构实现之。【程序代码】 /#includeclass Time public:;/#include “#includevoid Time:inputT()begin:int a,b,c;std:couta b c;if (c 60 | c 60 | b 24 | a p;if (p = n| p = N) std:cout C+实验报告 begin1:int a,b,c;std:cout a b c;if (c 60 | c 60 | b 24 | a void main
5、(void) Time time1;();();();(); std:cout #include#includeusing namespace std;class Vector;Vector:Vector(int s)Vector:Vector(const Vector&s) int i;sz = ;v = new intsz;for (i = 0;i= sz) return vi;cerr C+实验报告 int i,j;ifstream in(“);/文件名 int x,y;in x y;Matrix ma(x,y);for (i = 0;i(i,j);in x;Vector ve(x);f
6、or (i = 0;ivei;【实验结果】图 5 实验三运行结果实验4面向对象程序设计(3)【实验要求】请在程序中的日期类的基础上,实现一个可以进行加天数操作获得另一个日期,以及进行日期减日期操作获得相隔天数的日期类,并进行应用程序设计:创建和两个日期,并计算中间相隔的天数,前者加上300天会是什么日子呢?范文TOP100【实验程序】 一、头文件部分#pragma once/class Date with year-month-day version#include#includeusing namespace std;class Date ;二、函数定义 int year,month,day
7、;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&operator+=(int n) Date&operator+() int operator-(Date&d)const bool isLeapYear()const friend ostream&operator#include#includ
8、eusing 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 yearsconst int Y4 = 1461;/number of days of 4 yearsDate:Date(const string&s) (转载于: 在点 网)void Date:i2ymd(int absDay
9、) int Date:ymd2i()const int yearDay = (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;return yearDay + tiansmonth - 1 + (isLeapYear() &month 2) + day;year = absDay / Y400 * 400;int y = absDay%Y400;/被400年除得的天数 if (y = Y400 - 1) year += y / Y100 * 100;y %= Y100;year += y / Y4 *
10、 4;y%=Y4;if (y = Y4 - 1) year += y / 365;y %= 365;if (y = 0) year+;bool leap = isLeapYear();for (month = 1;monthtiansmonth + (month = 2 &leap);month+);day = y - tiansmonth - 1;month = 12,day = 31;return;month = 12,day = 30;return;month = 12,day = 30;return;year = atoi(0,4).c_str();month = atoi(5,2).
11、c_str();day = atoi(8,2).c_str();ostream&operatorusing namespace std;int main() Date d1(2005,8,21);Date d2(2008,8,8);cout#includeusing namespace std;class Date ;int year,month,day;static const int tians;Date(int n = 1) int ymd2i( )const;void i2ymd(int n);Date(const string&s );Date(int y,int m,int d)
12、: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&operatorC+实验报告二、头文件#pragma once/#include”“#include#includeusing namespace std;class WDate :public Date protected:WDate operator+(int n) const r
13、eturn Date:operator+(n); WDate&operator+=(int n) Date:operator+=(n);return *this; WDate&operator+() return *this += 1; int getWeekDay() return ymd2i() % 7;/0:Sunday,1:Monday,etc.int operator-(WDate&wd)const return ymd2i() - (); friend ostream&operator#include#includeusing namespace std;const int Dat
14、e: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 * 400;int y = absDay%Y
15、400;/被400年除得的天数 if (y = Y400 - 1) month = 12,day = 30;year = atoi(0,4).c_str();month = atoi(5,2).c_str();day = atoi(8,2).c_str(); return;year += y / Y100 * 100;y %= Y100;year += y / Y4 * 4;y %= Y4;if (y = Y4 - 1) year += y / 365;y %= 365;if (y = 0) year+;bool leap = isLeapYear();for (month = 1;month
16、tiansmonth + (month = 2 &leap);month+);day = y - tiansmonth - 1;month = 12,day = 31;return;month = 12,day = 30;return;int Date:ymd2i()const ostream&operator2) + day;四、/Class WDate with year-month-day Version#include”“#includeusing namespace std;ostream&operatorusing namespace std;int main() WDate d1(2005,8,21);WDate d2(2008,8,8);cout d1 ”n”;cout d2 ”n”;【实验结果】上页各位读友大家好,此文档由网络收集而来,欢迎您下载,谢谢
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1