




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 艺术品交易中介服务协议
- 旅游规划与设计服务合同
- 隧道机械租赁合同
- 项目团队月度工作总结报告书
- 7《一匹出色的马》教学设计-2023-2024学年二年级下册语文统编版
- Unit 1 Family Lesson3(教学设计)-2024-2025学年北师大版(三起)(2024)英语三年级上册
- 第6单元 20陀螺(教学设计)2024-2025学年四年级语文上册同步教学(统编版)
- 西宁高铁u型渠施工方案
- 济宁钢质入户门施工方案
- 北京拼接式蓄水池施工方案
- 院感考核表(门-诊)
- 建筑工程综合评估法Ⅱ评标办法
- 钠离子电池工艺与材料
- 初中语文九年级下册阅读理解50篇附答案解析
- 《陶瓷造型工艺》课程标准
- 火电厂各指标指标解析(最新版)
- 病毒性脑炎患者的护理查房ppt课件
- TPU材料项目可行性研究报告写作参考范文
- 第二编 债权总论
- 试用期考核合格证明表
- 常见八种疾病
评论
0/150
提交评论