已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/TS 21056:2025 EN Recycled aggregate concrete - Additional provisions and guidance for specification,performance,production and execution
- 贵港中环生物科技扩建项目环境影响报告表
- 八年级下册《北冥有鱼》过关训练-2024年中考语文课内文言文要点梳理与练习解析版
- 年产40万套新能源汽车电池盒组件项目可行性研究报告模板-申批备案
- 中级微观期末试题及答案
- 2025年高州初一政治试卷及答案
- 2025年大学植物地衣试题及答案
- 资产交接应急预案(3篇)
- 2025年上海舞蹈留学真题及答案
- 2025年星球地理七上题库及答案
- 认知域作战基础知识课件
- 大学生职业规划大赛《智能焊接技术专业》生涯发展展示
- 养老社区课件
- 学校流感宣传教学课件
- 车辆管理档案及相关表格
- 矿区钻探安全管理制度
- 德云社空降人员管理制度
- 2022浙DT9 民用建筑常用水泵和风机控制电路图
- 2024年江苏公务员考试申论试题(B卷)
- 工艺报警分级管理制度
- 2025+CSCO结直肠癌诊疗指南解读
评论
0/150
提交评论