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

#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;
}

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

时间: 2024-08-29 05:23:35

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

Objective-C 程序设计(第六版)第十一章习题答案

1. 1 #import "Fraction.h" 2 3 @interface Fraction (MathOps) 4 5 - (Fraction *) add: (Fraction *) f; 6 7 - (Fraction *) mul: (Fraction *) f; 8 9 - (Fraction *) sub: (Fraction *) f; 10 11 - (Fraction *) div: (Fraction *) f; 12 13 - (Fraction *) in

c++ primer plus(第6版)中文版 第十三章编程练习答案

第十三章编程练习答案 13.1根据Cd基类,完成派生出一个Classic类,并测试 //13.1根据Cd基类,完成派生出一个Classic类,并测试 #include <iostream> #include <cstring> using namespace std; // base class class Cd { char performers[50]; char label[20]; int selections; // number of selections double

c++ primer plus(第6版)中文版 第十章编程练习答案

第十章编程练习答案 10.1为复习题5类提供定义,并演示 //10.1为复习题5类提供定义,并演示 #include <iostream> using namespace std; class BankAccount { string m_name; string m_num; unsigned m_balance; public: BankAccount (string name, string num, unsigned balance) { m_name = name; m_num =

c++ primer plus(第6版)中文版 第八章编程练习答案

第八章编程练习答案 8.1编写一个输出字符串的函数,有一个默认参数表示输出次数,默认为1.(原题太扯啦,题意基础上小改动) //8.1编写一个输出字符串的函数,有一个默认参数表示输出次数,默认为1.(原题太扯啦,题意基础上小改动) #include <iostream> using namespace std; void show (const char* str, int time=1) { unsigned n=(time>0)?time:-time; for (unsigned i

c++ primer plus(第6版)中文版 第七章编程练习答案

第七章编程练习答案 7.1编写一个程序,用户不停输入两数,直到有0出现为止,计算调和平均数 //7.1编写一个程序,用户不停输入两数,直到有0出现为止,计算调和平均数 #include <iostream> using namespace std; double average (unsigned x, unsigned y) { return (2.0 * x * y / (x + y)); } int main () { while (true) { unsigned x, y; cout

Objective-C 程序设计(第六版)第七章习题答案

1.各个方法的实现 1 - (Fraction *) subtract: (Fraction *) f 2 { 3 Fraction *result = [[Fraction alloc] init]; 4 5 result.numerator = numerator *f.denominator - denominator *f.numerator; 6 result.denominator = denominator *f.denominator; 7 8 [result reduce];

Objective-C 程序设计(第六版)第四章习题答案

1.   非法常量 0x10.5    0X0G1    98.7U    17777s    0996    1.2Fe-7    15,000    . 2. //只需要列出表达式就可以 int F = 27; //设置F为华氏温度,赋值 27 float C ; //设置C为摄氏温度,类型为浮点类型 C = (F-32)/1.8; NSLog(@"%.1f",C); // %.1f 保留一位小数就可以 //输出结果 2014-09-17 14:58:48.259 prog1[60

Objective-C 程序设计(第六版)第五章习题答案

1. NSLog(@"数字N N的平方"); NSLog(@"--------------------"); for (int n = 1; n <= 10; n++) { NSLog(@"%2d %d",n,n*n); } //结果如下 2014-09-27 15:00:26.457 prog1[1218:303] 数字N N的平方 2014-09-27 15:00:26.459 prog1[1218:303] -------------

Objective-C 程序设计(第六版)第三章习题答案

1.   不合法:6_05 (不能以数字开头) A$ ($是非法符号). 2.   myBook  (openBook,closeBook,readBook,takeBook,putBook). 3.   [myBook takeBook]; [myBook openBook]; [myBook readBook]; [myBook closeBook]; [myBook putBook]; 4.   [myBoat driver]; [myMotorcycle driver]; [myCar