




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第 6 周: 生成 N 个随机数(1-100) ,排序后输出。要求 1、使用数组实现。2 、使用 vector 实现。 #include using namespace std; int main() const int N=100; vector vec; srand(time(0); for(int i=0;i); print(vec); coutvecj) k=j; int temp=veck;veck=veci;veci=temp; 第 7 周 : 1生成 N 个随机数( 0-99) ,统计落在区间10*i,10*i+9(i:0-9)内的整数个数。 #include #include using namespace std; int main() const int N=10000; int cnt=0; bool isPrime(int); for(int i=0;i!=N;+i) int temp=rand()%10000+1; if(isPrime(temp) +cnt; cout #include #include using namespace std; int main() const int N=10000; static bool aN+1; for(auto al=false; for(int i=2;i using namespace std; int main() const int N=100; vector vec; srand(time(0); for(int i=0;i); print(vec); coutvecj) k=j; int temp=veck;veck=veci;veci=temp; 第 11 周 1. 实现一个 Point 类并测试;(要求 Point 类至少有一个或多个构造函数,一个求两点之 间的距离函数,和一个求该点到原点距离的函数) #include using namespace std; int main() Point p1(1,2); Point p2(3,4); cout #include using namespace std; class Point public: Point(int x,int y) this-x=x; this-y=y; double dist(Point p) return sqrt(x-p.x)*(x-p.x)+(y-p.y)*(y-p.y); private: int x; int y; ; class Triangle public: Triangle(Point p1,Point p2,Point p3) a=p1.dist(p2); b=p1.dist(p3); c=p2.dist(p3); double circumference() return (a+b+c); double area() double p=(a+b+c)/2.0; return sqrt(p*(p-a)*(p-b)*(p-c); private: double a; double b; double c; ; int main() Point p1(1,1); Point p2(1,5); Point p3(4,1); Triangle T(p1,p2,p3); cout using namespace std; class Complex public: Complex()real=0;imag=0; Complex(double r,double i)real=r;imag=i; Complex add(Complex c2); Complex sub(Complex c2); double real; double imag; ; int main() Complex c1; c1.real=1.1;c1.imag=1.2; cout #include #include using namespace std; string haab19=“pop“,“no“,“zip“,“zotz“,“tzec“,“xul“,“yoxkin“,“mol“,“chen“,“yax“,“zac“,“ceh“,“mac“,“k ankin“,“muan“,“pax“,“koyab“,“cumhu“,“uayet“; string tzolkin20=“imix“,“ik“,“akbal“,“kan“,“chicchan“,“cimi“,“manik“,“lamat“,“muluk“,“ok“,“chuen“,“ eb“,“ben“,“ix“,“mem“,“cib“,“caban“,“eznab“,“canac“,“ahau“; int main() int turns; int day,year; string month; char dot; cinturns; cout0) cinday; cindot; cinmonth; cinyear; int i; for(i=0;i using namespace std; int leapYear(int year); int main() cout a b c; int i, result = 0; for(i=1;i using namespace std; class Person public: Person(); person(string newname); void PrintName(); private: string name; person:person(string newname) name=newname; void person:person(string newname) cout using namespace std; class Base public: Base(int i)cout using namespace std; class Complex public: Complex(double r=0.0,double i=0.0) real=r; imag=i; Complex operator+(const Complex Complex operator-(const Complex Complex operator+() return Complex(+real,+imag); Complex operator+(int) return Complex(real+,imag+); Complex operator-() return Complex(-real,-imag); Complex operator-(int) return Complex(real-,imag-); void display()const cout“(“real“,“imag“)“endl; private: double real; double imag; ; int main() Complex c1(5,4),c2(2,10),c3; cout“c1=“;c1.display(); cout“c2=“;c2.display(); c3=c1+c2; cout“c3=c1+c2=“;c3.display(); c3=c1-c2; cout“c3=c1-c2=“;c3.display(); c3=c1;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025官方版设备购买借款合同范本
- 2025合作出版合同模板
- 2025美容院正式劳动合同书
- 2025授权代理协议合同示范文本
- 2 高级仪表工选择练习题含答案-3
- 外卖门店订单管理制度
- 党员学习讲堂管理制度
- 公司晨会考勤管理制度
- 培训课堂用具管理制度
- 医院员工待岗管理制度
- 2025年暑假安全教育家长会
- 23《祖先的摇篮》(教学设计)2023-2024学年统编版语文二年级下册
- 2024年深圳市烟草专卖局招聘笔试真题
- 齐鲁名校大联考2025届山东省高三第七次学业水平联合检测语文试题及答案
- 外科肛肠科试题及答案
- 骨科围手术期的疼痛护理
- 子宫颈炎护理查房
- 严重过敏反应诊断和临床管理专家共识(2025年版)解读
- 中国2型糖尿病运动治疗指南(2024版)解读 2
- 北师大版五年级数学下册典型例题第六单元:确定位置和描述路线专项练习(原卷版+解析)
- 旱地划龙舟课件
评论
0/150
提交评论