码迷,mamicode.com
首页 > 编程语言 > 详细

C++ PRimer PLUS(第六版)中文版 第十一章chapter11答案 参考

时间:2018-10-23 21:00:57      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:lib   time   bre   The   wing   sign   direct   quit   mod   

#include <iostream>
#include <cstdlib>
#include <ctime>
#include "vector.h"

int main()
{
srand(time(0));
double direction;
VECTOR::Vector step;
VECTOR::Vector result(0.0, 0.0);
unsigned long steps = 0;
double target;
double dstep;
std::cout << "Enter target distance (q to quit): ";
while (std::cin >> target)
{
std::cout << "Enter step length: ";
if (!(std::cin >> dstep))
break;
while (result.magval() < target)
{
direction = rand() % 360;
step.reset(dstep, direction, VECTOR::Vector::POL);
result = result + step;
steps++;
}
std::cout << "After " << steps << " steps, the subject has the following location:\n";
std::cout << result << std::endl;
result.polar_mode();
std::cout << " or\n" << result << std::endl;
std::cout << "Average outward distance per step = " << result.magval() / steps << std::endl;
steps = 0;
result.reset(0.0, 0.0);
std::cout << "Enter target distance (q to quit): ";
}
std::cout << "Bye!\n";
std::cin.clear();
while(std::cin.get() != ‘\n‘)
continue;
return 0;
}

C++ PRimer PLUS(第六版)中文版 第十一章chapter11答案 参考

标签:lib   time   bre   The   wing   sign   direct   quit   mod   

原文地址:https://www.cnblogs.com/yejuelei/p/9838015.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!