那两个函数我就弄上来了,都是和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; }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————