C++primer plus第六版课后编程题答案11.3
来源:互联网 发布:pcb线路板设计软件 编辑:程序博客网 时间:2024/06/05 00:11
那两个函数我就弄上来了,都是和11.1一样的
main113.cpp
#include <iostream>#include <fstream>#include <cstdio>#include <ctime>//#include <vector>#include "vector.h"using namespace std;using namespace VECTOR;void main113(){int MaxStep=-999;int MinStep=999;int sumS=0;int avg=0;int num;cout<<"Enter the number:"<<endl;cin>>num;srand(time(0));double direction;Vector step;Vector result(0.0,0.0);unsigned long steps=0;double target;//要走的距离double dstep;//每一步的距离cout<<"Enter step length:(q to quit:)";int number=num;while(cin>>target&&number--){cout<<"Enter step length:";if(!(cin>>dstep))break;int i=0;while(result.magval()<target){direction=rand()%360;step.reset(dstep,direction,Vector::POL);result=result+step;steps++;}sumS+=steps;if(steps>MaxStep)MaxStep=steps;if(steps<MinStep)MinStep=steps;cout<<"After "<<steps<<" steps ,the subject "<<" has the following location:"<<endl;result.polar_mode();cout<<"Average outward distance per step="<<result.magval()/steps<<endl;steps=0;result.reset(0.0,0.0);cout<<"Enter target distance (q to quit):";}cout<<"Max:"<<MaxStep<<endl;cout<<"Min:"<<MinStep<<endl;cout<<"avg:"<<sumS/num<<endl;cin.get();cin.clear();while(cin.get()!='\n')continue;}
0 0
- C++primer plus第六版课后编程题答案11.3
- C++primer plus第六版课后编程练习答案11.3
- C++primer plus第六版课后编程题答案 6.1
- C++primer plus第六版课后编程题答案 6.2
- C++primer plus第六版课后编程题答案 6.3
- C++primer plus第六版课后编程题答案 6.4
- C++primer plus第六版课后编程题答案 6.5
- C++primer plus第六版课后编程题答案 6.6
- C++primer plus第六版课后编程题答案 6.7
- C++primer plus第六版课后编程题答案 6.8
- C++primer plus第六版课后编程题答案 6.9
- C++primer plus第六版课后编程题答案7.1
- C++primer plus第六版课后编程题答案7.2
- C++primer plus第六版课后编程题答案7.3
- C++primer plus第六版课后编程题答案7.4
- C++primer plus第六版课后编程题答案7.5
- C++primer plus第六版课后编程题答案7.6
- C++primer plus第六版课后编程题答案 7.7
- ContentObserver与DatasetObserver区别
- C/C++程序中内存的分配和堆栈的区别总结
- 泛型于Dao中的应用案例一
- 使用GDI+进行图片处理时要注意的问题
- android中右下角老提示content loader的解决办法!!!
- C++primer plus第六版课后编程题答案11.3
- 关于Can't connect to MySQL server on 'localhost' (10061)的解决办法!
- MYSQL 常用函数
- setting up your robot with tf(二)
- Linux sar使用
- 插入排序 选择排序 冒泡排序 快速排序
- 归并排序-分治法
- CLR的一个核心——垃圾回收
- 大家好!