




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/you must konw the differences between BASIC and C+/in c+ ,= do not mean equal!while = has the meaning !#include stdafx.h#include using namespace std;int n;bool flag=true;int main(int argc, char* argv)coutn;for(int i=2;i!=n;+i)if(n%i=0)cout这是一个非质数iendl;flag=false;break;if(flag=true) cout你输入了一个质数endl;return 0;88*/*这个习题考察的是对初始值的理解;在定义func这个函数的时候 对C,D规定了初始值,但是如果在调用的时候对于CD有了重新的定义,。那么输出的值就不熟3和4了;这里的理解有误*/#include stdafx.h#includeusing namespace std;void func(int a,int b,int c=4,int d=5)coutatbtctdendl;int main(int argc, char* argv)func(10,25,35,40);func(10,11,12);func(113,13); return 0;/简单的四舍五入程序,自己的想法,很不错#include stdafx.h#includeusing namespace std;int f(double n)int n1=n;if(n-n10&0.5n-n1) return n1;if(n-n1=0.5) return n1+1;int main(int argc, char* argv) double x;cinx;coutxtf(x)endl;return 0;*#include stdafx.h# include#includeusing namespace std;int re;int main(int argc, char* argv) srand(unsigned)time(NULL); int ran1,ran2; ran1=rand()%100+1; ran2=rand()%100+1; coutran1+ran2re; if(re=ran1+ran2) cout真棒,答对了endl; else cout再算一次吧 ran1+ran2re; if(re=ran1+ran2)cout真棒,答对了endl; else cout 真遗憾,答错了endl; return 0;/ 习题3点11.cpp : Defines the entry point for the console application./ 判断这个函数的的结果/ when you do such kind of exercise ,pay attention to the progress/make sure that you konw the progress well,if not ,calm down#include stdafx.h#includeusing namespace std;int main(int argc, char* argv) int a10=77,83,72,54,92,65,75,81,43,96;int b5=60,70,80,90,100;int c5=0;for(int i=0;i=bj)j+;cj+;for(i=0;i5;i+)coutci;coutendl;return 0;/ 测试复制构造函数.cpp : Defines the entry point for the console application./ 对象与类的测试.cpp : Defines the entry point for the console application./this code is an example of the destructor and the copy consturctor;pay attention to the result and understand the execute progress;/ take notice of of mark 1 and mark2;mark1 is about the definition of the destructor; #include stdafx.h#includeusing namespace std;class rectfloat x,y;public:rect(float a=1, float b=1)x=a,y=b; coutnow lets do the constructor=,=endl; void set(float a=0,float b=0)x=a,y=b;rect(rect & obj4)x=obj4.x; y=obj4.y;coutexecute copy constructorendl;/ 1float peri();float area();rect()coutexecute the destructorendl;/2;float rect:peri()float z;z=2*x+2*y;return z;float rect:area()float z;z=x*y;return z;void main()rect obj(78.5,52),obj2,obj3(obj);coutThe first time calculation results: endl;coutThe perimeter of rectangle No1: obj.peri(), area: obj.area()endl;coutthe perimeter of rectangle No2: obj2.area(), area: obj2.area()endl; coutthe perimeter of rectangle No3: obj3.peri(), area: obj3.area()endl;obj.set(12,34);obj2.set(34,78);coutnow ,lets do the second time calculation: endl;coutthe perimeter of rectangle No1: obj.peri(), area: obj.area()endl;coutthe perimeter of rectangle No2: obj2.area(), area: obj2.area()endl;*8/ 对象与类的测试.cpp : Defines the entry point for the console application./#include stdafx.h#includeusing namespace std;class rectfloat x,y;public:rect(float a=1, float b=1)x=a,y=b; void set(float a=0,float b=0)x=a,y=b;float peri();float area();float rect:peri()float z;z=2*x+2*y;return z;float rect:area()float z;z=x*y;return z;void main()rect obj(78.5,52),obj2;coutThe first time calculation results: endl;coutThe perimeter of rectangle No1: obj.peri(), area: obj.area()endl;coutthe perimeter of rectangle No2: obj2.area(), area: obj2.area()endl;obj.set(12,34);obj2.set(34,78);coutnow ,lets do the second time calculation: endl;coutthe perimeter of rectangle No1: obj.peri(), area: obj.area()endl;coutthe perimeter of rectangle No2: obj2.area(), area: obj2.area()endl;#include stdafx.h#include#includeusing namespace std;int white,black,sum,ran1,ran2;int main(int argc, char* argv)srand(unsigned)time(NULL);coutwhite;coutblack;sum=black+white;while(black+white!=1) ran1=rand()%sum+1; ran2=rand()%sum+1;if(ran1,ran2white ) white-;sum-; if(ran1white) black-;sum-; if(ran2white) black-;sum-;if(white=1)cout最后一个球的颜色是:白色endl;else cout最后一个球的颜色是:黑色endl;return 0;#include stdafx.h#includeusing namespace std;const max=100;class arrayprivate:int shuzumax;int last;public: array(); void isfull(); void isempty(); void delete_date(); int insert();array:array(int,int)for(size_t i=0; i!=99;+i)shuzui=0; array:isempty()if(shuzu.0=0) coutisempty() tell that the arr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 药店员工培训模式创新-洞察阐释
- 乒乓球培训机构运营管理方案
- 三峡旅游职业技术学院《外国史学史》2023-2024学年第二学期期末试卷
- 青岛农业大学海都学院《现代农业发展与实践案例》2023-2024学年第二学期期末试卷
- 增材制造技术对玻璃陶瓷性能的优化研究-洞察阐释
- 贵州工业职业技术学院《普通话》2023-2024学年第二学期期末试卷
- 中南财经政法大学《压力容器与安全工程》2023-2024学年第二学期期末试卷
- 枣庄学院《西方经济学实验》2023-2024学年第二学期期末试卷
- 烤肉店运营管理方案
- 高校资助育人模式的研究与探讨
- 肝硬化护理查房课件
- 竞赛试卷(试题)-2023-2024学年六年级下册数学人教版
- 网络空间安全概论智慧树知到期末考试答案2024年
- MOOC 管理学原理-东北财经大学 中国大学慕课答案
- 政务新闻摄影技巧培训课件
- 2024年山东公务员考试行测真题及解析【完美打印版】
- 中国十大名画
- 岗位胜任力评估表
- 夏季企业安全知识培训
- 立式机组轴线调整及瓦间隙计算
- 23秋国家开放大学《素质与思想品德教育》形考任务1-3参考答案
评论
0/150
提交评论