diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/10_1.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/10_1.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..c313f7e8168eba32820c29bce01d3cb0bd6ec41c --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/10_1.cpp" @@ -0,0 +1,44 @@ +#include "10_1.h" +#include +#include + +Account::Account() +{ + strcpy_s(_name, LEN, "no name"); + strcpy_s(_number, LEN, "no number"); + _money = 0.0; +} + +Account::Account(const char name[], const char number[], double money) +{ + strcpy_s(_name, LEN, name); + strcpy_s(_number, LEN, number); + _money = money; +} + +Account::~Account() +{ +} + +void Account::pushMoney(double money) +{ + using namespace std; + cout << _name << "的账户存入" << money << "元" << endl; + _money += money; +} + +void Account::pullMoney(double money) +{ + using namespace std; + cout << _name << "的账户取出" << money << "元" << endl; + _money -= money; +} + +void Account::showAccount() +{ + using namespace std; + cout << "姓名:" << _name << endl; + cout << "账户:" << _number << endl; + cout << "余额:" << _money << endl; + cout << endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/10_1.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/10_1.h" new file mode 100644 index 0000000000000000000000000000000000000000..de8811a02b9e3f54e78256d4c30d1efff21ad634 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/10_1.h" @@ -0,0 +1,22 @@ +#pragma once +#ifndef _ACCOUNT_H_ +#define _ACCOUNT_H_ + +const int LEN = 40; + +class Account { +private: + char _name[LEN]; //姓名 + char _number[LEN]; //账号 + double _money; //存款 +public: + Account(); //默认构造函数 + Account(const char name[], const char number[], double money); //构造函数 + ~Account(); //析构函数 + void pushMoney(double money); //存款 + void pullMoney(double money); //取款 + void showAccount(); +}; + + +#endif \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..e0ba874f99a6737039c5965f66a0ed4deba14e20 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_1/main.cpp" @@ -0,0 +1,19 @@ +#include"10_1.h" +#include + + +int main() { + Account user1; + Account user2("SuJianrong", "202407", 10000); + + user1.showAccount(); + user2.showAccount(); + + user1.pushMoney(2000); + user1.showAccount(); + + user2.pullMoney(200); + user2.showAccount(); + + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/10_2.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/10_2.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..11532321b5f249c8a805d191c7eda88781953995 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/10_2.cpp" @@ -0,0 +1,23 @@ +#include "10_2.h" +#include + + +Person::Person(const string& ln, const char* fn) +{ + _lname = ln; + strcpy_s(_fname, LIMIT, fn); +} + +void Person::Show() const +{ + using namespace std; + cout << "lastname: " << _lname << endl; + cout << "firstname: " << _fname << endl; +} + +void Person::FormalShow() const +{ + using namespace std; + cout << "firstname: " << _fname << endl; + cout << "lastname: " << _lname << endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/10_2.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/10_2.h" new file mode 100644 index 0000000000000000000000000000000000000000..293b8a7a8b617eaca1bf96678a4ce84f96593300 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/10_2.h" @@ -0,0 +1,16 @@ +#pragma once +#include +using namespace std; + +class Person { +private: + static const int LIMIT = 25; + string _lname; // Person's last name + char _fname[LIMIT]; // Person's first name +public: + Person() { _lname = ""; _fname[0] = '\0'; } // #1 + Person(const string& ln, const char* fn = "Heyyou"); // #2 + // the following methods display lname and fname + void Show() const; // firstname lastname format + void FormalShow() const; // lastname, firstname format +}; diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..8874f3741958801ce0506d043d982abd19d5839d --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_2/main.cpp" @@ -0,0 +1,16 @@ +#include +#include"10_2.h" + +int main() { + Person one; + Person two("Smythecraft"); + Person three("Dimwiddy", "Sam"); + one.Show(); + one.FormalShow(); + two.Show(); + two.FormalShow(); + three.Show(); + three.FormalShow(); + + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/10_3.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/10_3.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..f0f78721a9b60c6e90eb5170a1502343f5da1121 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/10_3.cpp" @@ -0,0 +1,34 @@ +#include +#include "10_3.h" +#include + +Golf::Golf() +{ + using namespace std; + cout << "Please input fullname: "; + cin.getline(_fullname, Len); + cout << "Please input handicap: "; + cin >> _handicap; +} + +Golf::Golf(const char fn[], int hd) +{ + strcpy_s(_fullname, Len, fn); + _handicap = hd; +} + +Golf::~Golf() +{ +} + +void Golf::resetHandicap(int hc) +{ + _handicap = hc; +} + +void Golf::showGolf() +{ + using namespace std; + cout << "fullname: " << _fullname << endl; + cout << "handicap: " << _handicap << endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/10_3.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/10_3.h" new file mode 100644 index 0000000000000000000000000000000000000000..e766eafe79044042d902c057fa244dc8da66df33 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/10_3.h" @@ -0,0 +1,17 @@ +#pragma once +#include + +const int Len = 40; +class Golf +{ +private: + char _fullname[Len]; + int _handicap; + +public: + Golf(); + Golf(const char fn[], int hd); + ~Golf(); + void resetHandicap(int hc); + void showGolf(); +}; diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..350ec360301111e884d673a711047f7bb5ab3dfe --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_3/main.cpp" @@ -0,0 +1,12 @@ +#include"10_3.h" +#include + +int main() { + Golf g1; + Golf g2("User2", 10); + g1.showGolf(); + g2.showGolf(); + g1.resetHandicap(20); + g1.showGolf(); + +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/10_4.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/10_4.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..001c65bdc0228112f9a183afc4750de1abd30041 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/10_4.cpp" @@ -0,0 +1,72 @@ +#include +#include "10_4.h" + +namespace SALES +{ + Sales::Sales() + { + using namespace std; + double max, min, total; + cout << "请分别输入四个季度的销售额:"; + for (int i = 0; i < 4; i++) { + cin >> _sales[i]; + } + max = min = total = _sales[0]; + for (int i = 1; i < 4; i++) { + if (_sales[i] > max) { + max = _sales[i]; + } + if (_sales[i] < min) { + min = _sales[i]; + } + total += _sales[i]; + } + _average = total / 4; + _max = max; + _min = min; + } + + Sales::Sales(const double ar[], int n) + { + int i = 0; + double max = 0, min = ar[0], avg = 0, total = 0; + for (i = 0; i < n; i++) { + _sales[i] = ar[i]; + if (ar[i] > max) { + max = ar[i]; + } + if (ar[i] < min) { + min = ar[i]; + } + total += ar[i]; + } + _average = total / n; + _max = max; + _min = min; + if (i < 4) { + for (int j = i; j < 4; j++) { + _sales[j] = 0; + } + } + } + + Sales::~Sales() + { + } + + + void Sales::showSales() const + { + using namespace std; + cout << "四个季度的销售额分别为:"; + for (int i = 0; i < 4; i++) { + cout << _sales[i] << " "; + } + cout << endl; + cout << "最大值:" << _max << endl; + cout << "最小值:" << _min << endl; + cout << "平均值:" << _average << endl; + } + +} + diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/10_4.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/10_4.h" new file mode 100644 index 0000000000000000000000000000000000000000..e8dfb07828da99830b1747608557e988a1635436 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/10_4.h" @@ -0,0 +1,20 @@ +#pragma once +#include + +namespace SALES +{ + const int QUARTERS = 4; + class Sales + { + private: + double _sales[QUARTERS]; + double _average; + double _max; + double _min; + public: + Sales(); + Sales(const double ar[], int n); + ~Sales(); + void showSales() const; + }; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..41fbf9fc97a813e553060955e638f47f632dad65 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_4/main.cpp" @@ -0,0 +1,12 @@ +#include +#include"10_4.h" +using namespace SALES; + +int main() { + const double arr[3] = { 100.0,200.0,300.0 }; + Sales s1(arr, 3); + Sales s2 = Sales(); + s1.showSales(); + s2.showSales(); + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/10_5.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/10_5.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..9c077aabbd3fd6fcfc4828e684f9135c86d54321 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/10_5.cpp" @@ -0,0 +1,46 @@ +// stack.cpp -- Stack member functions +#include "10_5.h" +#include + +Stack::Stack() // create an empty stack +{ + top = 0; +} + +bool Stack::isempty() const +{ + return top == 0; +} + +bool Stack::isfull() const +{ + return top == MAX; +} + +bool Stack::push(const Item& item) +{ + if (top < MAX) + { + items[top++] = item; + return true; + } + else + return false; +} + +bool Stack::pop(Item& item) +{ + if (top > 0) + { + item = items[--top]; + total += item.payment; + return true; + } + else + return false; +} + +void Stack::showTotal() +{ + std::cout << "总数为:" << total << std::endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/10_5.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/10_5.h" new file mode 100644 index 0000000000000000000000000000000000000000..5abbec2dbe6fc82e552d4feda963b444a59195e0 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/10_5.h" @@ -0,0 +1,31 @@ +// stack.h -- class definition for the stack ADT +#ifndef STACK_H_ +#define STACK_H_ + +struct customer { + char fullname[35]; + double payment; +}; + +typedef customer Item; + +class Stack +{ +private: + enum { MAX = 10 }; // constant specific to class + Item items[MAX]; // holds stack items + int top; // index for top stack item + double total = 0; + +public: + Stack(); + bool isempty() const; + bool isfull() const; + // push() returns false if stack already is full, true otherwise + bool push(const Item& item); // add item to stack + // pop() returns false if stack already is empty, true otherwise + bool pop(Item& item); // pop top into item + void showTotal(); +}; + +#endif diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..2aae788f280c84e3e739d1a57729e5e903cd7b64 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_5/main.cpp" @@ -0,0 +1,52 @@ +// stacker.cpp -- testing the Stack class +#include +#include // or ctype.h +#include "10_5.h" + +int main() +{ + using namespace std; + Stack st; // create an empty stack + char ch; + customer po; + cout << "Please enter A to add a purchase order,\n" + << "P to process a PO, or Q to quit.\n"; + while (cin >> ch && toupper(ch) != 'Q') + { + while (cin.get() != '\n') + continue; + if (!isalpha(ch)) + { + cout << '\a'; + continue; + } + switch (ch) + { + case 'A': + case 'a': + cout << "Enter a PO number to add: "; + cin.get(po.fullname, 35); + cout << "Enter a PO payment to add: "; + cin >> po.payment; + if (st.isfull()) + cout << "stack already full\n"; + else + st.push(po); + break; + case 'P': + case 'p': + if (st.isempty()) + cout << "stack already empty\n"; + else { + st.pop(po); + cout << po.fullname << "已出栈,payment的值添加到总数中" << endl; + st.showTotal(); + } + break; + } + cout << "Please enter A to add a purchase order,\n" + << "P to process a PO, or Q to quit.\n"; + } + cout << "Bye\n"; + return 0; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/10_6.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/10_6.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..61be0238cf40f5fd086be8de39c5654c585bfa14 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/10_6.cpp" @@ -0,0 +1,26 @@ +#include "10_6.h" +#include + +Move::Move(double a, double b) +{ + x = a; + y = b; +} + +void Move::showMove() const +{ + using namespace std; + cout << "横坐标:" << x << endl; + cout << "纵坐标:" << y << endl; +} + +Move Move::add(const Move& m) const +{ + return Move(x + m.x, y + m.y); +} + +void Move::resetMove(double a, double b) +{ + x = a; + y = b; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/10_6.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/10_6.h" new file mode 100644 index 0000000000000000000000000000000000000000..53077d4c6878dfd3d41a8ca0397836cf56eddf79 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/10_6.h" @@ -0,0 +1,13 @@ +#pragma once + +class Move +{ +private: + double x; + double y; +public: + Move(double a = 0, double b = 0); + void showMove() const; + Move add(const Move& m) const; + void resetMove(double a = 0, double b = 0); +}; \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..921db103ee2ace39714e188fd457b5eaad914660 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_6/main.cpp" @@ -0,0 +1,15 @@ +#include"10_6.h" +#include + +int main() { + Move p0 = Move(); + Move p1(2, 3); + Move p2(3, 7); + p0.showMove(); + p1.showMove(); + p2.showMove(); + Move p3 = p1.add(p2); + p3.showMove(); + + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/10_7.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/10_7.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..6c86dbe860f42c21d07c6a5de4a318e8290586fa --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/10_7.cpp" @@ -0,0 +1,31 @@ +#include "10_7.h" +#include +#include + +Plorg::Plorg() +{ + strcpy_s(m_name, 20, "Plorga"); + m_CI = 50; +} + +Plorg::Plorg(const char name[]) +{ + strcpy_s(m_name, 20, name); + m_CI = 50; +} + +Plorg::~Plorg() +{ +} + +void Plorg::resetCI(int CI) +{ + m_CI = CI; +} + +void Plorg::showPlorg() const +{ + using namespace std; + cout << "name: " << m_name << endl; + cout << "CI: " << m_CI << endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/10_7.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/10_7.h" new file mode 100644 index 0000000000000000000000000000000000000000..0825d4943d3cf56034da220477971f9f236ff652 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/10_7.h" @@ -0,0 +1,16 @@ +#pragma once + +class Plorg +{ +private: + char m_name[20]; + int m_CI; + +public: + Plorg(); + Plorg(const char name[]); + ~Plorg(); + void resetCI(int CI); + void showPlorg() const; + +}; \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..b9bbe6c2be24033c074622a565d5748eb9203b88 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter10/10_7/main.cpp" @@ -0,0 +1,13 @@ +#include +#include"10_7.h" + +int main() { + Plorg p1 = Plorg(); + Plorg p2("sujianrong"); + p1.showPlorg(); + p2.showPlorg(); + p2.resetCI(25); + p2.showPlorg(); + + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/randwalk.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/randwalk.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..949f62d711addb5a36843a91ca14a4438dcbed8d --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/randwalk.cpp" @@ -0,0 +1,69 @@ +// randwalk.cpp -- using the Vector class +// compile with the vect.cpp file +#include +#include // rand(), srand() prototypes +#include // time() prototype +#include "vector.h" +#include + +int main() +{ + using namespace std; + using VECTOR::Vector; + srand(time(0)); // seed random-number generator + double direction; + Vector step; + Vector result(0.0, 0.0); + unsigned long steps = 0; + double target; + + ofstream fout; + fout.open("thewalk.txt"); + fout << "0: " << result << endl; + + double dstep; + cout << "Enter target distance (q to quit): "; + while (cin >> target) + { + cout << "Enter step length: "; + if (!(cin >> dstep)) + break; + + int cnt = 1; + while (result.magval() < target) + { + direction = rand() % 360; + step.reset(dstep, direction, Vector::POL); + result = result + step; + fout << cnt << ": " << result << endl; + cnt++; + steps++; + } + + cout << "After " << steps << " steps, the subject " + << "has the following location:\n"; + cout << result << endl; + + fout << "After " << steps << " steps, the subject " + << "has the following location:\n"; + fout << result << endl; + + result.polar_mode(); + cout << " or\n" << result << endl; + cout << "Average outward distance per step = " + << result.magval() / steps << endl; + + fout << " or\n" << result << endl; + fout << "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 << "Bye!\n"; + cin.clear(); + while (cin.get() != '\n') + continue; + return 0; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/thewalk.txt" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/thewalk.txt" new file mode 100644 index 0000000000000000000000000000000000000000..240463704011b8eeaafef71cebd87cbcb2f1980f --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/thewalk.txt" @@ -0,0 +1,684 @@ +0: (x,y) = (0, 0) +1: (x,y) = (1.31212, -1.50942) +2: (x,y) = (-0.219971, -2.79499) +3: (x,y) = (0.529242, -0.940627) +4: (x,y) = (1.27846, 0.913741) +5: (x,y) = (2.18644, -0.868272) +6: (x,y) = (2.67028, 1.07232) +7: (x,y) = (2.01914, 2.96336) +8: (x,y) = (3.69649, 4.05263) +9: (x,y) = (1.72111, 3.73977) +10: (x,y) = (1.27121, 1.79103) +11: (x,y) = (1.37588, -0.206233) +12: (x,y) = (3.17347, -1.08298) +13: (x,y) = (1.66405, -2.39509) +14: (x,y) = (3.50506, -1.61363) +15: (x,y) = (2.44522, 0.0824646) +16: (x,y) = (1.41514, -1.63187) +17: (x,y) = (1.79676, -3.59512) +18: (x,y) = (3.16076, -2.13242) +19: (x,y) = (4.55007, -0.693737) +20: (x,y) = (2.67069, -1.37778) +21: (x,y) = (4.15698, -0.0395164) +22: (x,y) = (2.81872, -1.52581) +23: (x,y) = (4.70975, -0.87467) +24: (x,y) = (2.71097, -0.944469) +25: (x,y) = (0.747718, -0.562851) +26: (x,y) = (-1.11944, 0.153885) +27: (x,y) = (0.771594, -0.497251) +28: (x,y) = (-0.994301, -1.43619) +29: (x,y) = (-2.99156, -1.54087) +30: (x,y) = (-0.992778, -1.61067) +31: (x,y) = (-1.64391, 0.280372) +32: (x,y) = (-1.92226, -1.70016) +33: (x,y) = (-3.89188, -2.04746) +34: (x,y) = (-1.98976, -1.42943) +35: (x,y) = (0.00262613, -1.60374) +36: (x,y) = (-1.98247, -1.84748) +37: (x,y) = (-0.00193003, -2.12582) +38: (x,y) = (-1.76783, -3.06477) +39: (x,y) = (0.0592657, -3.87824) +40: (x,y) = (0.644009, -5.79085) +41: (x,y) = (-0.386067, -7.50518) +42: (x,y) = (-2.34236, -7.92101) +43: (x,y) = (-4.18337, -7.13954) +44: (x,y) = (-2.65128, -8.42512) +45: (x,y) = (-4.57381, -8.97639) +46: (x,y) = (-4.88668, -10.9518) +47: (x,y) = (-5.06099, -12.9442) +48: (x,y) = (-6.99284, -13.4618) +49: (x,y) = (-7.30571, -11.4864) +50: (x,y) = (-7.653, -13.456) +51: (x,y) = (-8.85663, -15.0533) +52: (x,y) = (-7.653, -13.456) +53: (x,y) = (-6.50585, -11.8177) +54: (x,y) = (-6.71491, -9.82869) +55: (x,y) = (-4.88782, -10.6422) +56: (x,y) = (-3.52382, -9.17946) +57: (x,y) = (-2.58488, -10.9454) +58: (x,y) = (-3.43011, -12.758) +59: (x,y) = (-2.34084, -11.0806) +60: (x,y) = (-3.93811, -12.2843) +61: (x,y) = (-4.14716, -10.2952) +62: (x,y) = (-2.15204, -10.1557) +63: (x,y) = (-1.468, -12.0351) +64: (x,y) = (-1.78086, -14.0105) +65: (x,y) = (-3.59348, -14.8557) +66: (x,y) = (-5.55673, -15.2373) +67: (x,y) = (-4.55673, -13.5053) +68: (x,y) = (-2.55673, -13.5053) +69: (x,y) = (-2.62653, -15.504) +70: (x,y) = (-0.72442, -16.1221) +71: (x,y) = (1.10267, -16.9356) +72: (x,y) = (2.3063, -15.3383) +73: (x,y) = (0.36571, -15.8221) +74: (x,y) = (0.713006, -13.8525) +75: (x,y) = (0.922063, -11.8635) +76: (x,y) = (1.1658, -9.87837) +77: (x,y) = (3.13542, -9.53108) +78: (x,y) = (1.42108, -8.501) +79: (x,y) = (-0.481031, -9.11904) +80: (x,y) = (-2.23027, -8.14942) +81: (x,y) = (-1.14099, -6.47208) +82: (x,y) = (0.090331, -4.89605) +83: (x,y) = (-1.50694, -6.09968) +84: (x,y) = (-3.01636, -7.4118) +85: (x,y) = (-1.0191, -7.51647) +86: (x,y) = (-0.984195, -5.51678) +87: (x,y) = (-2.88631, -6.13481) +88: (x,y) = (-2.10485, -4.2938) +89: (x,y) = (-0.164255, -4.77765) +90: (x,y) = (-2.10485, -5.26149) +91: (x,y) = (-3.22323, -6.91957) +92: (x,y) = (-4.79925, -5.68824) +93: (x,y) = (-4.55551, -7.67333) +94: (x,y) = (-6.30475, -8.64295) +95: (x,y) = (-7.45191, -10.2813) +96: (x,y) = (-6.51296, -12.0472) +97: (x,y) = (-4.73095, -12.9551) +98: (x,y) = (-2.96506, -13.8941) +99: (x,y) = (-1.32675, -15.0412) +100: (x,y) = (-0.326752, -16.7733) +101: (x,y) = (-0.466264, -14.7782) +102: (x,y) = (-1.34301, -16.5757) +103: (x,y) = (0.646037, -16.3667) +104: (x,y) = (1.06186, -18.323) +105: (x,y) = (2.57128, -19.6351) +106: (x,y) = (1.482, -17.9578) +107: (x,y) = (1.06618, -16.0015) +108: (x,y) = (0.68456, -14.0382) +109: (x,y) = (2.3619, -15.1275) +110: (x,y) = (0.76463, -16.3311) +111: (x,y) = (-0.112112, -14.5335) +112: (x,y) = (-1.95312, -13.7521) +113: (x,y) = (-2.57116, -15.6542) +114: (x,y) = (-3.80248, -14.0782) +115: (x,y) = (-2.7724, -15.7925) +116: (x,y) = (-1.59683, -14.1745) +117: (x,y) = (-0.847619, -16.0288) +118: (x,y) = (-0.262875, -17.9414) +119: (x,y) = (1.68586, -17.4915) +120: (x,y) = (3.64912, -17.1099) +121: (x,y) = (1.89988, -16.1403) +122: (x,y) = (3.1312, -14.5643) +123: (x,y) = (2.85286, -16.5448) +124: (x,y) = (3.7296, -18.3424) +125: (x,y) = (3.3823, -16.3728) +126: (x,y) = (1.44171, -15.8889) +127: (x,y) = (1.54638, -13.8917) +128: (x,y) = (-0.376141, -13.3404) +129: (x,y) = (0.623859, -11.6084) +130: (x,y) = (-0.157603, -9.76734) +131: (x,y) = (-0.157603, -11.7673) +132: (x,y) = (0.78134, -10.0014) +133: (x,y) = (0.711541, -12.0002) +134: (x,y) = (1.68116, -13.7495) +135: (x,y) = (1.23126, -15.6982) +136: (x,y) = (2.71755, -17.0365) +137: (x,y) = (4.6494, -16.5188) +138: (x,y) = (3.18669, -17.8828) +139: (x,y) = (4.69611, -16.5707) +140: (x,y) = (3.9469, -14.7163) +141: (x,y) = (5.94416, -14.6117) +142: (x,y) = (4.50548, -13.2224) +143: (x,y) = (2.86717, -12.0752) +144: (x,y) = (3.31708, -10.1265) +145: (x,y) = (3.17756, -12.1216) +146: (x,y) = (1.29818, -12.8056) +147: (x,y) = (-0.499411, -13.6824) +148: (x,y) = (1.24983, -14.652) +149: (x,y) = (2.68851, -16.0413) +150: (x,y) = (3.59649, -17.8233) +151: (x,y) = (2.39286, -16.2261) +152: (x,y) = (0.595271, -17.1028) +153: (x,y) = (-0.249965, -15.2902) +154: (x,y) = (1.36807, -16.4657) +155: (x,y) = (3.22244, -15.7165) +156: (x,y) = (1.73615, -17.0548) +157: (x,y) = (1.28624, -15.1061) +158: (x,y) = (2.62451, -13.6198) +159: (x,y) = (4.43712, -14.465) +160: (x,y) = (2.46174, -14.1521) +161: (x,y) = (0.549135, -13.5674) +162: (x,y) = (2.54792, -13.6372) +163: (x,y) = (0.782022, -14.5761) +164: (x,y) = (1.46606, -12.6967) +165: (x,y) = (-0.413323, -13.3808) +166: (x,y) = (0.104315, -11.4489) +167: (x,y) = (-1.55376, -10.3306) +168: (x,y) = (0.415855, -9.98325) +169: (x,y) = (2.24295, -10.7967) +170: (x,y) = (4.19169, -10.3468) +171: (x,y) = (2.19656, -10.4863) +172: (x,y) = (0.832562, -11.949) +173: (x,y) = (-0.106382, -10.1832) +174: (x,y) = (-1.85562, -11.1528) +175: (x,y) = (0.136768, -10.9785) +176: (x,y) = (1.62306, -12.3167) +177: (x,y) = (1.55326, -14.3155) +178: (x,y) = (2.78458, -12.7395) +179: (x,y) = (1.6953, -11.0621) +180: (x,y) = (3.67068, -10.7493) +181: (x,y) = (1.85807, -11.5945) +182: (x,y) = (3.85807, -11.5945) +183: (x,y) = (3.34043, -9.66265) +184: (x,y) = (4.34043, -7.9306) +185: (x,y) = (2.80834, -6.64503) +186: (x,y) = (1.7485, -4.94893) +187: (x,y) = (0.436381, -6.45835) +188: (x,y) = (-1.443, -7.14239) +189: (x,y) = (-1.23395, -5.15335) +190: (x,y) = (-0.295004, -6.91924) +191: (x,y) = (0.389037, -8.79863) +192: (x,y) = (0.770655, -6.83537) +193: (x,y) = (-1.21839, -7.04443) +194: (x,y) = (-3.131, -6.45969) +195: (x,y) = (-4.97201, -7.24115) +196: (x,y) = (-2.97475, -7.34582) +197: (x,y) = (-1.14766, -6.53235) +198: (x,y) = (-1.7324, -4.61974) +199: (x,y) = (-2.51386, -2.77873) +200: (x,y) = (-3.165, -0.887692) +201: (x,y) = (-1.28562, -0.203651) +202: (x,y) = (-1.04188, -2.18874) +203: (x,y) = (-2.0115, -3.93798) +204: (x,y) = (-3.76074, -2.96836) +205: (x,y) = (-2.22865, -4.25394) +206: (x,y) = (-1.98491, -6.23903) +207: (x,y) = (-1.70656, -4.2585) +208: (x,y) = (0.273975, -4.53684) +209: (x,y) = (0.413488, -6.53197) +210: (x,y) = (0.0318697, -8.49522) +211: (x,y) = (2.02426, -8.32091) +212: (x,y) = (0.292208, -9.32091) +213: (x,y) = (-0.677411, -7.57167) +214: (x,y) = (-1.76669, -9.24901) +215: (x,y) = (-3.76547, -9.31881) +216: (x,y) = (-5.56306, -10.1956) +217: (x,y) = (-3.68367, -10.8796) +218: (x,y) = (-4.36771, -9.00021) +219: (x,y) = (-3.68367, -10.8796) +220: (x,y) = (-4.65329, -9.13036) +221: (x,y) = (-4.40955, -11.1154) +222: (x,y) = (-6.22217, -10.2702) +223: (x,y) = (-4.66788, -11.5289) +224: (x,y) = (-6.66514, -11.4242) +225: (x,y) = (-7.34918, -13.3036) +226: (x,y) = (-9.21634, -12.5868) +227: (x,y) = (-9.90038, -10.7074) +228: (x,y) = (-11.0759, -12.3255) +229: (x,y) = (-10.5247, -14.248) +230: (x,y) = (-11.8887, -12.7853) +231: (x,y) = (-13.8884, -12.8202) +232: (x,y) = (-13.7837, -10.8229) +233: (x,y) = (-15.6509, -11.5397) +234: (x,y) = (-15.7904, -9.54455) +235: (x,y) = (-14.1723, -8.36898) +236: (x,y) = (-12.5963, -9.6003) +237: (x,y) = (-11.042, -10.8589) +238: (x,y) = (-11.1118, -8.86016) +239: (x,y) = (-9.32981, -9.76814) +240: (x,y) = (-11.2617, -10.2858) +241: (x,y) = (-13.1027, -9.50432) +242: (x,y) = (-11.9555, -7.86601) +243: (x,y) = (-10.9859, -9.61525) +244: (x,y) = (-12.0752, -11.2926) +245: (x,y) = (-12.2147, -13.2877) +246: (x,y) = (-10.5764, -14.4349) +247: (x,y) = (-12.5518, -14.122) +248: (x,y) = (-11.0891, -12.758) +249: (x,y) = (-9.53476, -14.0166) +250: (x,y) = (-9.22189, -15.992) +251: (x,y) = (-9.3614, -13.9969) +252: (x,y) = (-10.9374, -15.2282) +253: (x,y) = (-12.5347, -16.4319) +254: (x,y) = (-14.1107, -17.6632) +255: (x,y) = (-12.1544, -18.079) +256: (x,y) = (-14.0338, -18.763) +257: (x,y) = (-12.1928, -19.5445) +258: (x,y) = (-10.5955, -20.7481) +259: (x,y) = (-11.5345, -22.514) +260: (x,y) = (-11.0846, -20.5653) +261: (x,y) = (-12.1146, -18.851) +262: (x,y) = (-13.0843, -17.1017) +263: (x,y) = (-11.4262, -18.2201) +264: (x,y) = (-9.8719, -19.4787) +265: (x,y) = (-8.55978, -17.9693) +266: (x,y) = (-7.07349, -16.6311) +267: (x,y) = (-8.22064, -18.2694) +268: (x,y) = (-7.80482, -16.3131) +269: (x,y) = (-9.67198, -17.0298) +270: (x,y) = (-7.68294, -16.8207) +271: (x,y) = (-6.12864, -18.0794) +272: (x,y) = (-4.59655, -16.7938) +273: (x,y) = (-2.64781, -17.2437) +274: (x,y) = (-4.6466, -17.3135) +275: (x,y) = (-6.03591, -15.8748) +276: (x,y) = (-6.31426, -13.8943) +277: (x,y) = (-8.04631, -12.8943) +278: (x,y) = (-9.88732, -13.6758) +279: (x,y) = (-11.8192, -14.1934) +280: (x,y) = (-13.751, -14.711) +281: (x,y) = (-14.0639, -16.6864) +282: (x,y) = (-12.132, -16.1688) +283: (x,y) = (-10.2095, -15.6175) +284: (x,y) = (-8.53218, -14.5282) +285: (x,y) = (-10.4885, -14.944) +286: (x,y) = (-11.2377, -16.7984) +287: (x,y) = (-11.0982, -18.7935) +288: (x,y) = (-10.0982, -17.0615) +289: (x,y) = (-9.75087, -19.0311) +290: (x,y) = (-7.75118, -19.066) +291: (x,y) = (-5.95359, -19.9428) +292: (x,y) = (-6.76706, -21.7698) +293: (x,y) = (-8.3851, -20.5943) +294: (x,y) = (-7.20953, -22.2123) +295: (x,y) = (-7.34904, -20.2172) +296: (x,y) = (-8.03308, -22.0966) +297: (x,y) = (-6.25107, -21.1886) +298: (x,y) = (-5.59993, -19.2975) +299: (x,y) = (-7.44094, -20.079) +300: (x,y) = (-9.37279, -20.5966) +301: (x,y) = (-9.61653, -18.6116) +302: (x,y) = (-9.20071, -20.5678) +303: (x,y) = (-10.1087, -22.3499) +304: (x,y) = (-11.595, -23.6881) +305: (x,y) = (-10.9109, -21.8087) +306: (x,y) = (-8.93556, -21.4959) +307: (x,y) = (-10.8377, -22.1139) +308: (x,y) = (-12.7398, -21.4959) +309: (x,y) = (-11.3011, -20.1066) +310: (x,y) = (-9.91179, -18.6679) +311: (x,y) = (-8.29376, -19.8434) +312: (x,y) = (-6.35317, -19.3596) +313: (x,y) = (-8.2442, -20.0107) +314: (x,y) = (-10.2247, -20.2891) +315: (x,y) = (-12.2171, -20.4634) +316: (x,y) = (-13.3643, -18.8251) +317: (x,y) = (-15.1463, -17.9171) +318: (x,y) = (-14.6287, -19.849) +319: (x,y) = (-14.7333, -21.8462) +320: (x,y) = (-16.7029, -22.1935) +321: (x,y) = (-17.4522, -20.3391) +322: (x,y) = (-16.1935, -18.7849) +323: (x,y) = (-17.5575, -20.2476) +324: (x,y) = (-15.8255, -19.2476) +325: (x,y) = (-15.5817, -21.2327) +326: (x,y) = (-16.5207, -19.4668) +327: (x,y) = (-15.4608, -17.7707) +328: (x,y) = (-16.8501, -19.2093) +329: (x,y) = (-17.3, -17.2606) +330: (x,y) = (-19.2022, -17.8786) +331: (x,y) = (-20.4058, -16.2814) +332: (x,y) = (-18.4932, -16.8661) +333: (x,y) = (-20.0905, -15.6625) +334: (x,y) = (-18.1014, -15.8715) +335: (x,y) = (-18.1014, -17.8715) +336: (x,y) = (-20.014, -18.4563) +337: (x,y) = (-21.9946, -18.7346) +338: (x,y) = (-21.6473, -16.765) +339: (x,y) = (-23.2233, -17.9963) +340: (x,y) = (-21.7846, -16.607) +341: (x,y) = (-22.4686, -18.4864) +342: (x,y) = (-21.21, -20.0407) +343: (x,y) = (-23.1796, -20.388) +344: (x,y) = (-24.0876, -18.606) +345: (x,y) = (-22.3733, -17.5759) +346: (x,y) = (-20.8638, -18.888) +347: (x,y) = (-22.6459, -17.98) +348: (x,y) = (-20.6507, -18.1196) +349: (x,y) = (-20.7902, -16.1244) +350: (x,y) = (-21.2401, -18.0732) +351: (x,y) = (-21.4492, -16.0841) +352: (x,y) = (-22.1003, -14.1931) +353: (x,y) = (-22.3094, -12.204) +354: (x,y) = (-20.6321, -13.2933) +355: (x,y) = (-20.5274, -15.2906) +356: (x,y) = (-21.8914, -13.8279) +357: (x,y) = (-22.861, -12.0786) +358: (x,y) = (-21.6574, -13.6759) +359: (x,y) = (-19.9081, -12.7063) +360: (x,y) = (-18.3987, -11.3942) +361: (x,y) = (-18.4685, -9.39538) +362: (x,y) = (-20.4609, -9.22107) +363: (x,y) = (-18.695, -10.16) +364: (x,y) = (-20.6076, -10.7448) +365: (x,y) = (-22.5301, -11.296) +366: (x,y) = (-22.0463, -13.2366) +367: (x,y) = (-23.485, -11.8473) +368: (x,y) = (-23.2066, -13.8278) +369: (x,y) = (-21.2069, -13.8627) +370: (x,y) = (-20.268, -15.6286) +371: (x,y) = (-19.2379, -13.9143) +372: (x,y) = (-19.447, -11.9253) +373: (x,y) = (-17.5449, -11.3072) +374: (x,y) = (-18.2616, -13.1744) +375: (x,y) = (-19.3214, -11.4783) +376: (x,y) = (-21.2777, -11.8941) +377: (x,y) = (-23.0903, -12.7394) +378: (x,y) = (-21.2632, -11.9259) +379: (x,y) = (-20.9504, -13.9013) +380: (x,y) = (-22.6996, -14.8709) +381: (x,y) = (-21.524, -13.2528) +382: (x,y) = (-19.6447, -13.9369) +383: (x,y) = (-21.5118, -14.6536) +384: (x,y) = (-22.4814, -16.4029) +385: (x,y) = (-20.5688, -16.9876) +386: (x,y) = (-19.3102, -15.4333) +387: (x,y) = (-21.2012, -16.0844) +388: (x,y) = (-22.9832, -15.1765) +389: (x,y) = (-21.1289, -14.4273) +390: (x,y) = (-21.3379, -12.4382) +391: (x,y) = (-21.4426, -10.4409) +392: (x,y) = (-19.5201, -9.88967) +393: (x,y) = (-17.6407, -9.20563) +394: (x,y) = (-19.6395, -9.13583) +395: (x,y) = (-21.6392, -9.17074) +396: (x,y) = (-22.4526, -7.34365) +397: (x,y) = (-22.6964, -5.35856) +398: (x,y) = (-20.8838, -4.51332) +399: (x,y) = (-21.8534, -6.26256) +400: (x,y) = (-22.3372, -8.20315) +401: (x,y) = (-21.3983, -6.43725) +402: (x,y) = (-21.0167, -8.40051) +403: (x,y) = (-19.8983, -6.74243) +404: (x,y) = (-19.5854, -8.71781) +405: (x,y) = (-19.3071, -6.73727) +406: (x,y) = (-20.5926, -5.20519) +407: (x,y) = (-18.5926, -5.20519) +408: (x,y) = (-19.2438, -3.31415) +409: (x,y) = (-17.5294, -4.34422) +410: (x,y) = (-16.5905, -2.57833) +411: (x,y) = (-14.6995, -1.92719) +412: (x,y) = (-16.1137, -3.34141) +413: (x,y) = (-16.0788, -1.34171) +414: (x,y) = (-16.6635, -3.25432) +415: (x,y) = (-17.7528, -4.93166) +416: (x,y) = (-17.2352, -2.99981) +417: (x,y) = (-17.4095, -1.00742) +418: (x,y) = (-15.9232, -2.34568) +419: (x,y) = (-17.2353, -3.8551) +420: (x,y) = (-16.2353, -2.12305) +421: (x,y) = (-14.2365, -2.05325) +422: (x,y) = (-12.5222, -1.02318) +423: (x,y) = (-11.1329, -2.46185) +424: (x,y) = (-11.098, -4.46155) +425: (x,y) = (-12.4873, -3.02287) +426: (x,y) = (-13.1713, -1.14349) +427: (x,y) = (-13.9205, -2.99785) +428: (x,y) = (-14.8901, -1.24861) +429: (x,y) = (-16.0373, 0.38969) +430: (x,y) = (-17.6756, 1.53684) +431: (x,y) = (-19.2516, 0.30552) +432: (x,y) = (-18.734, 2.23737) +433: (x,y) = (-19.4832, 4.09174) +434: (x,y) = (-18.7017, 5.93275) +435: (x,y) = (-17.1257, 4.70143) +436: (x,y) = (-19.0051, 4.01739) +437: (x,y) = (-19.8818, 5.81497) +438: (x,y) = (-19.2638, 7.71709) +439: (x,y) = (-17.7095, 8.97573) +440: (x,y) = (-17.9879, 6.99519) +441: (x,y) = (-19.8289, 6.21373) +442: (x,y) = (-21.8286, 6.24863) +443: (x,y) = (-19.916, 5.66389) +444: (x,y) = (-21.2015, 4.1318) +445: (x,y) = (-20.6168, 2.21919) +446: (x,y) = (-18.6244, 2.3935) +447: (x,y) = (-20.5563, 2.91114) +448: (x,y) = (-18.5866, 3.25844) +449: (x,y) = (-19.1043, 1.32659) +450: (x,y) = (-20.567, 2.69058) +451: (x,y) = (-18.5719, 2.55107) +452: (x,y) = (-20.5037, 3.06871) +453: (x,y) = (-21.8158, 4.57813) +454: (x,y) = (-23.6134, 3.70139) +455: (x,y) = (-22.3548, 2.14709) +456: (x,y) = (-20.5889, 3.08604) +457: (x,y) = (-22.491, 3.70407) +458: (x,y) = (-21.0283, 2.34007) +459: (x,y) = (-22.5826, 3.59872) +460: (x,y) = (-24.558, 3.28585) +461: (x,y) = (-26.449, 2.63471) +462: (x,y) = (-24.9863, 3.99871) +463: (x,y) = (-22.9939, 3.8244) +464: (x,y) = (-24.8849, 3.17326) +465: (x,y) = (-23.7378, 4.81156) +466: (x,y) = (-25.701, 5.19318) +467: (x,y) = (-23.7205, 4.91483) +468: (x,y) = (-25.3978, 6.00411) +469: (x,y) = (-27.2999, 5.38608) +470: (x,y) = (-28.7862, 6.72434) +471: (x,y) = (-26.7862, 6.72434) +472: (x,y) = (-28.0718, 8.25643) +473: (x,y) = (-29.6261, 6.99779) +474: (x,y) = (-30.9382, 5.48837) +475: (x,y) = (-32.7041, 4.54943) +476: (x,y) = (-30.9898, 5.5795) +477: (x,y) = (-30.405, 7.49211) +478: (x,y) = (-32.3856, 7.77046) +479: (x,y) = (-33.3552, 6.02122) +480: (x,y) = (-34.1687, 4.19413) +481: (x,y) = (-35.5829, 5.60834) +482: (x,y) = (-34.3516, 7.18436) +483: (x,y) = (-32.9129, 5.79505) +484: (x,y) = (-31.6816, 7.37107) +485: (x,y) = (-33.1678, 8.70933) +486: (x,y) = (-33.7191, 6.7868) +487: (x,y) = (-31.8648, 7.53602) +488: (x,y) = (-32.6462, 9.37703) +489: (x,y) = (-31.801, 11.1896) +490: (x,y) = (-32.709, 12.9717) +491: (x,y) = (-31.2463, 11.6077) +492: (x,y) = (-29.8076, 10.2183) +493: (x,y) = (-28.8996, 8.43633) +494: (x,y) = (-28.8647, 10.436) +495: (x,y) = (-30.8644, 10.4709) +496: (x,y) = (-32.677, 9.62569) +497: (x,y) = (-31.0189, 10.7441) +498: (x,y) = (-30.2375, 12.5851) +499: (x,y) = (-32.0501, 13.4303) +500: (x,y) = (-30.9608, 15.1077) +501: (x,y) = (-30.9608, 17.1077) +502: (x,y) = (-31.3766, 15.1514) +503: (x,y) = (-29.3876, 14.9423) +504: (x,y) = (-29.0747, 16.9177) +505: (x,y) = (-29.5246, 14.969) +506: (x,y) = (-30.4326, 16.751) +507: (x,y) = (-31.8953, 18.115) +508: (x,y) = (-33.2336, 19.6013) +509: (x,y) = (-31.7709, 18.2373) +510: (x,y) = (-33.7599, 18.0282) +511: (x,y) = (-32.2278, 16.7426) +512: (x,y) = (-31.3198, 18.5246) +513: (x,y) = (-29.5072, 17.6794) +514: (x,y) = (-28.4179, 16.0021) +515: (x,y) = (-26.4228, 16.1416) +516: (x,y) = (-24.424, 16.2114) +517: (x,y) = (-25.9783, 17.47) +518: (x,y) = (-25.0703, 19.252) +519: (x,y) = (-23.6317, 20.6413) +520: (x,y) = (-23.4573, 22.6337) +521: (x,y) = (-21.482, 22.9466) +522: (x,y) = (-19.7676, 23.9767) +523: (x,y) = (-19.6978, 21.9779) +524: (x,y) = (-19.9762, 23.9584) +525: (x,y) = (-18.4899, 25.2967) +526: (x,y) = (-20.3571, 24.58) +527: (x,y) = (-22.0714, 23.5499) +528: (x,y) = (-24.0711, 23.515) +529: (x,y) = (-22.759, 25.0244) +530: (x,y) = (-21.8822, 26.822) +531: (x,y) = (-23.8141, 26.3043) +532: (x,y) = (-25.2283, 24.8901) +533: (x,y) = (-24.9154, 22.9148) +534: (x,y) = (-24.6371, 20.9342) +535: (x,y) = (-22.905, 21.9342) +536: (x,y) = (-22.1558, 20.0798) +537: (x,y) = (-20.5585, 21.2835) +538: (x,y) = (-22.2729, 20.2534) +539: (x,y) = (-21.1545, 21.9115) +540: (x,y) = (-19.3569, 21.0347) +541: (x,y) = (-20.889, 22.3203) +542: (x,y) = (-20.7843, 24.3176) +543: (x,y) = (-22.7734, 24.1085) +544: (x,y) = (-20.7843, 24.3176) +545: (x,y) = (-21.8144, 22.6032) +546: (x,y) = (-23.5964, 23.5112) +547: (x,y) = (-24.5044, 25.2932) +548: (x,y) = (-23.6909, 23.4661) +549: (x,y) = (-22.4323, 21.9118) +550: (x,y) = (-24.1982, 22.8508) +551: (x,y) = (-25.9802, 21.9428) +552: (x,y) = (-24.1531, 22.7563) +553: (x,y) = (-22.1558, 22.861) +554: (x,y) = (-22.807, 20.9699) +555: (x,y) = (-20.8146, 21.1442) +556: (x,y) = (-22.0182, 19.547) +557: (x,y) = (-23.8854, 18.8302) +558: (x,y) = (-25.8659, 19.1086) +559: (x,y) = (-27.2552, 17.6699) +560: (x,y) = (-25.3881, 18.3866) +561: (x,y) = (-24.1567, 16.8106) +562: (x,y) = (-25.9543, 17.6873) +563: (x,y) = (-23.9789, 17.3745) +564: (x,y) = (-25.964, 17.1307) +565: (x,y) = (-27.2762, 15.6213) +566: (x,y) = (-26.6914, 13.7087) +567: (x,y) = (-26.7612, 15.7075) +568: (x,y) = (-25.2749, 17.0458) +569: (x,y) = (-26.305, 15.3314) +570: (x,y) = (-27.9433, 14.1843) +571: (x,y) = (-25.946, 14.0796) +572: (x,y) = (-24.328, 15.2552) +573: (x,y) = (-25.7173, 16.6938) +574: (x,y) = (-27.6869, 17.0411) +575: (x,y) = (-26.5686, 15.3831) +576: (x,y) = (-25.5087, 17.0792) +577: (x,y) = (-27.3759, 17.7959) +578: (x,y) = (-25.3808, 17.6564) +579: (x,y) = (-24.6967, 19.5358) +580: (x,y) = (-25.2143, 21.4676) +581: (x,y) = (-26.0278, 23.2947) +582: (x,y) = (-27.8688, 22.5132) +583: (x,y) = (-28.0431, 20.5209) +584: (x,y) = (-30.0282, 20.2771) +585: (x,y) = (-29.4435, 18.3645) +586: (x,y) = (-27.463, 18.6429) +587: (x,y) = (-25.8247, 17.4957) +588: (x,y) = (-25.2066, 15.5936) +589: (x,y) = (-26.2066, 17.3256) +590: (x,y) = (-25.9283, 19.3062) +591: (x,y) = (-25.2771, 17.4151) +592: (x,y) = (-27.2259, 17.865) +593: (x,y) = (-28.7353, 19.1772) +594: (x,y) = (-28.3537, 21.1404) +595: (x,y) = (-28.2839, 19.1416) +596: (x,y) = (-29.9019, 17.9661) +597: (x,y) = (-31.598, 19.0259) +598: (x,y) = (-30.8165, 17.1849) +599: (x,y) = (-31.1294, 19.1603) +600: (x,y) = (-32.9565, 18.3468) +601: (x,y) = (-32.3385, 16.4447) +602: (x,y) = (-31.7204, 14.5426) +603: (x,y) = (-33.3587, 15.6897) +604: (x,y) = (-33.5331, 17.6821) +605: (x,y) = (-35.3601, 16.8686) +606: (x,y) = (-35.1511, 14.8796) +607: (x,y) = (-33.2967, 14.1304) +608: (x,y) = (-31.3404, 14.5462) +609: (x,y) = (-31.5842, 12.5611) +610: (x,y) = (-29.6821, 11.9431) +611: (x,y) = (-30.1659, 13.8837) +612: (x,y) = (-29.3207, 15.6963) +613: (x,y) = (-31.035, 16.7264) +614: (x,y) = (-32.8894, 17.4756) +615: (x,y) = (-32.0441, 15.663) +616: (x,y) = (-32.079, 13.6633) +617: (x,y) = (-33.7371, 12.5449) +618: (x,y) = (-32.041, 13.6047) +619: (x,y) = (-30.3267, 14.6348) +620: (x,y) = (-32.0926, 13.6958) +621: (x,y) = (-32.3709, 11.7153) +622: (x,y) = (-33.0221, 9.82427) +623: (x,y) = (-31.9037, 11.4824) +624: (x,y) = (-32.9635, 13.1784) +625: (x,y) = (-34.9623, 13.1086) +626: (x,y) = (-32.9817, 13.387) +627: (x,y) = (-32.8074, 15.3794) +628: (x,y) = (-34.8047, 15.2747) +629: (x,y) = (-34.3209, 13.3341) +630: (x,y) = (-36.3181, 13.2294) +631: (x,y) = (-36.1438, 11.2371) +632: (x,y) = (-34.3167, 12.0505) +633: (x,y) = (-36.2188, 11.4325) +634: (x,y) = (-35.1295, 9.75516) +635: (x,y) = (-34.3803, 11.6095) +636: (x,y) = (-35.2256, 9.79691) +637: (x,y) = (-34.7417, 7.85632) +638: (x,y) = (-36.296, 9.11496) +639: (x,y) = (-35.7113, 7.20235) +640: (x,y) = (-37.6519, 6.7185) +641: (x,y) = (-39.2902, 5.57135) +642: (x,y) = (-38.4134, 3.77376) +643: (x,y) = (-39.5606, 2.13546) +644: (x,y) = (-38.0285, 3.42103) +645: (x,y) = (-37.0285, 1.68898) +646: (x,y) = (-38.2041, 0.0709498) +647: (x,y) = (-36.9727, -1.50507) +648: (x,y) = (-38.7048, -0.505072) +649: (x,y) = (-39.1206, 1.45122) +650: (x,y) = (-37.8085, 2.96064) +651: (x,y) = (-39.731, 2.40937) +652: (x,y) = (-39.3837, 0.439752) +653: (x,y) = (-37.6017, 1.34773) +654: (x,y) = (-39.5713, 1.00044) +655: (x,y) = (-41.5409, 0.653141) +656: (x,y) = (-40.2554, -0.878948) +657: (x,y) = (-42.068, -1.72418) +658: (x,y) = (-44.0677, -1.75909) +659: (x,y) = (-42.5134, -0.500449) +660: (x,y) = (-40.5909, -1.05172) +661: (x,y) = (-42.5035, -1.63647) +662: (x,y) = (-43.7071, -0.0391958) +663: (x,y) = (-42.5315, 1.57884) +664: (x,y) = (-40.551, 1.30049) +665: (x,y) = (-42.392, 0.51903) +666: (x,y) = (-44.2046, -0.326207) +667: (x,y) = (-46.1897, -0.0824681) +668: (x,y) = (-47.1897, -1.81452) +669: (x,y) = (-45.2092, -2.09287) +670: (x,y) = (-46.1172, -0.310852) +671: (x,y) = (-45.2404, 1.48674) +672: (x,y) = (-43.3086, 2.00437) +673: (x,y) = (-44.3386, 0.29004) +674: (x,y) = (-46.1362, 1.16678) +675: (x,y) = (-47.6225, -0.171479) +676: (x,y) = (-47.3442, -2.15202) +677: (x,y) = (-49.1262, -1.24403) +678: (x,y) = (-50.9933, -0.527299) +After 678 steps, the subject has the following location: +(x,y) = (-50.9933, -0.527299) + or +(m,a) = (50.9961, -179.408) +Average outward distance per step = 0.0752154 diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/vector.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/vector.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..bd8493dd21a99cd067475fd757a82568ed49c8e3 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/vector.cpp" @@ -0,0 +1,167 @@ +// vect.cpp -- methods for the Vector class +#include +#include "vector.h" // includes +using std::sqrt; +using std::sin; +using std::cos; +using std::atan; +using std::atan2; +using std::cout; + +namespace VECTOR +{ + // compute degrees in one radian + const double Rad_to_deg = 45.0 / atan(1.0); // should be about 57.2957795130823 + + // private methods + // calculates magnitude from x and y + void Vector::set_mag() + { + mag = sqrt(x * x + y * y); + } + + void Vector::set_ang() + { + if (x == 0.0 && y == 0.0) + ang = 0.0; + else + ang = atan2(y, x); + } + + // set x from polar coordinate + void Vector::set_x() + { + x = mag * cos(ang); + } + + // set y from polar coordinate + void Vector::set_y() + { + y = mag * sin(ang); + } + + // public methods + Vector::Vector() // default constructor + { + x = y = mag = ang = 0.0; + mode = RECT; + } + + // construct vector from rectangular coordinates if form is RECT (the default) + // or else from polar coordinates if form is POL + Vector::Vector(double n1, double n2, Mode form) + { + mode = form; + if (form == RECT) + { + x = n1; + y = n2; + set_mag(); + set_ang(); + } + else if (form == POL) + { + mag = n1; + ang = n2 / Rad_to_deg; + set_x(); + set_y(); + } + else + { + cout << "Incorrect 3rd argument to Vector() -- "; + cout << "vector set to 0\n"; + x = y = mag = ang = 0.0; + mode = RECT; + } + } + + // reset vector from rectangular coordinates if form is RECT (the default) + // or else from polar coordinates if form is POL + void Vector::reset(double n1, double n2, Mode form) + { + mode = form; + if (form == RECT) + { + x = n1; + y = n2; + set_mag(); + set_ang(); + } + else if (form == POL) + { + mag = n1; + ang = n2 / Rad_to_deg; + set_x(); + set_y(); + } + else + { + cout << "Incorrect 3rd argument to Vector() -- "; + cout << "vector set to 0\n"; + x = y = mag = ang = 0.0; + mode = RECT; + } + } + + Vector::~Vector() // destructor + { + } + + void Vector::polar_mode() // set to polar mode + { + mode = POL; + } + + void Vector::rect_mode() // set to rectangular mode + { + mode = RECT; + } + + // operator overloading + // add two Vectors + Vector Vector::operator+(const Vector& b) const + { + return Vector(x + b.x, y + b.y); + } + + // subtract Vector b from a + Vector Vector::operator-(const Vector& b) const + { + return Vector(x - b.x, y - b.y); + } + + // reverse sign of Vector + Vector Vector::operator-() const + { + return Vector(-x, -y); + } + + // multiply vector by n + Vector Vector::operator*(double n) const + { + return Vector(n * x, n * y); + } + + // friend methods + // multiply n by Vector a + Vector operator*(double n, const Vector& a) + { + return a * n; + } + + // display rectangular coordinates if mode is RECT, + // else display polar coordinates if mode is POL + std::ostream& operator<<(std::ostream& os, const Vector& v) + { + if (v.mode == Vector::RECT) + os << "(x,y) = (" << v.x << ", " << v.y << ")"; + else if (v.mode == Vector::POL) + { + os << "(m,a) = (" << v.mag << ", " << v.ang * Rad_to_deg << ")"; + } + else + os << "Vector object mode is invalid"; + return os; + } + +} // end namespace VECTOR diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/vector.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/vector.h" new file mode 100644 index 0000000000000000000000000000000000000000..4e9c645812d5611026c04c514562631144be4c62 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_1/vector.h" @@ -0,0 +1,47 @@ +// vect.h -- Vector class with <<, mode-state +#ifndef VECTOR_H_ +#define VECTOR_H_ +#include +namespace VECTOR +{ + class Vector + { + public: + enum Mode { RECT, POL }; // RECT for rectangular, POL for Polar modes + private: + double x; // horizontal value + double y; // vertical value + double mag; // length of vector + double ang; // direction of vector in degrees + Mode mode; // RECT or POL + + // private methods for setting values + void set_mag(); + void set_ang(); + void set_x(); + void set_y(); + public: + Vector(); + Vector(double n1, double n2, Mode form = RECT); + void reset(double n1, double n2, Mode form = RECT); + ~Vector(); + double xval() const { return x; } // report x value + double yval() const { return y; } // report y value + double magval() const { return mag; } // report magnitude + double angval() const { return ang; } // report angle + void polar_mode(); // set mode to POL + void rect_mode(); // set mode to RECT + + // operator overloading + Vector operator+(const Vector& b) const; + Vector operator-(const Vector& b) const; + Vector operator-() const; + Vector operator*(double n) const; + + // friends + friend Vector operator*(double n, const Vector& a); + friend std::ostream& operator<<(std::ostream& os, const Vector& v); + }; +} // end namespace VECTOR + +#endif diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/randwalk.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/randwalk.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..949f62d711addb5a36843a91ca14a4438dcbed8d --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/randwalk.cpp" @@ -0,0 +1,69 @@ +// randwalk.cpp -- using the Vector class +// compile with the vect.cpp file +#include +#include // rand(), srand() prototypes +#include // time() prototype +#include "vector.h" +#include + +int main() +{ + using namespace std; + using VECTOR::Vector; + srand(time(0)); // seed random-number generator + double direction; + Vector step; + Vector result(0.0, 0.0); + unsigned long steps = 0; + double target; + + ofstream fout; + fout.open("thewalk.txt"); + fout << "0: " << result << endl; + + double dstep; + cout << "Enter target distance (q to quit): "; + while (cin >> target) + { + cout << "Enter step length: "; + if (!(cin >> dstep)) + break; + + int cnt = 1; + while (result.magval() < target) + { + direction = rand() % 360; + step.reset(dstep, direction, Vector::POL); + result = result + step; + fout << cnt << ": " << result << endl; + cnt++; + steps++; + } + + cout << "After " << steps << " steps, the subject " + << "has the following location:\n"; + cout << result << endl; + + fout << "After " << steps << " steps, the subject " + << "has the following location:\n"; + fout << result << endl; + + result.polar_mode(); + cout << " or\n" << result << endl; + cout << "Average outward distance per step = " + << result.magval() / steps << endl; + + fout << " or\n" << result << endl; + fout << "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 << "Bye!\n"; + cin.clear(); + while (cin.get() != '\n') + continue; + return 0; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/thewalk.txt" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/thewalk.txt" new file mode 100644 index 0000000000000000000000000000000000000000..96b37410e1cbb77d0d009c6399ffe7ba9f5d5abe --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/thewalk.txt" @@ -0,0 +1,1224 @@ +0: (x,y) = (0, 0) +1: (x,y) = (0.258819, 0.965926) +2: (x,y) = (0.758819, 0.0999004) +3: (x,y) = (1.27386, 0.957068) +4: (x,y) = (0.63107, 0.191023) +5: (x,y) = (1.08506, -0.699983) +6: (x,y) = (0.194053, -1.15397) +7: (x,y) = (-0.804576, -1.10164) +8: (x,y) = (-0.995385, -2.08326) +9: (x,y) = (-1.98307, -2.2397) +10: (x,y) = (-2.97334, -2.37887) +11: (x,y) = (-2.1962, -1.74955) +12: (x,y) = (-2.55456, -2.68313) +13: (x,y) = (-1.64102, -3.08987) +14: (x,y) = (-2.50704, -3.58987) +15: (x,y) = (-1.83791, -2.84672) +16: (x,y) = (-2.43973, -3.64536) +17: (x,y) = (-3.26877, -3.08617) +18: (x,y) = (-4.17507, -2.66355) +19: (x,y) = (-3.29213, -2.19408) +20: (x,y) = (-4.23182, -2.5361) +21: (x,y) = (-5.21951, -2.37966) +After 21 steps, the subject has the following location: +(x,y) = (-5.21951, -2.37966) + or +(m,a) = (5.73638, -155.491) +Average outward distance per step = 0.273161 +1: (x,y) = (-1.74924, -0.969619) +2: (x,y) = (-2.92481, 0.648415) +3: (x,y) = (-3.34063, 2.60471) +4: (x,y) = (-1.78634, 3.86335) +5: (x,y) = (-0.0720068, 2.83327) +6: (x,y) = (-1.85402, 1.92529) +7: (x,y) = (0.115596, 1.578) +8: (x,y) = (1.92821, 2.42323) +9: (x,y) = (3.31753, 3.86191) +10: (x,y) = (2.69949, 5.76403) +11: (x,y) = (2.04836, 7.65506) +12: (x,y) = (0.266345, 8.56304) +13: (x,y) = (1.57846, 10.0725) +14: (x,y) = (-0.420319, 10.0027) +15: (x,y) = (0.943678, 11.4654) +16: (x,y) = (2.8662, 10.9141) +17: (x,y) = (4.84674, 11.1924) +18: (x,y) = (2.84948, 11.2971) +19: (x,y) = (0.860434, 11.5062) +20: (x,y) = (0.513138, 9.53656) +21: (x,y) = (2.40418, 8.88542) +22: (x,y) = (0.513138, 8.23428) +23: (x,y) = (2.39252, 7.55024) +24: (x,y) = (4.37762, 7.79398) +25: (x,y) = (6.30947, 7.27634) +26: (x,y) = (5.24963, 5.58025) +27: (x,y) = (3.53529, 4.55017) +28: (x,y) = (2.88416, 6.44121) +29: (x,y) = (1.28689, 5.23758) +30: (x,y) = (1.39156, 7.23484) +31: (x,y) = (-0.578057, 7.58213) +32: (x,y) = (-2.06435, 6.24387) +33: (x,y) = (-0.917194, 7.88218) +34: (x,y) = (-1.40104, 5.94159) +35: (x,y) = (0.596222, 6.04626) +36: (x,y) = (-0.842458, 7.43557) +37: (x,y) = (-0.598719, 9.42067) +38: (x,y) = (1.16718, 10.3596) +39: (x,y) = (3.15957, 10.1853) +40: (x,y) = (2.64193, 12.1172) +41: (x,y) = (4.08061, 10.7278) +42: (x,y) = (4.39348, 12.7032) +43: (x,y) = (2.40443, 12.4942) +44: (x,y) = (4.29547, 13.1453) +45: (x,y) = (2.40443, 13.7964) +46: (x,y) = (2.12609, 15.777) +47: (x,y) = (3.89198, 16.7159) +48: (x,y) = (1.89959, 16.5416) +49: (x,y) = (3.3623, 15.1776) +50: (x,y) = (1.76503, 16.3812) +51: (x,y) = (-0.126009, 15.7301) +52: (x,y) = (1.68661, 16.5753) +53: (x,y) = (-0.313089, 16.6102) +54: (x,y) = (0.102734, 14.6539) +55: (x,y) = (-1.79938, 14.0359) +56: (x,y) = (0.163876, 14.4175) +57: (x,y) = (-1.32241, 13.0793) +58: (x,y) = (0.459599, 13.9872) +59: (x,y) = (1.20881, 12.1329) +60: (x,y) = (-0.229867, 10.7436) +61: (x,y) = (-1.90721, 9.65428) +62: (x,y) = (-2.93728, 7.93994) +63: (x,y) = (-2.76297, 9.93233) +64: (x,y) = (-4.15229, 11.371) +65: (x,y) = (-5.49055, 12.8573) +66: (x,y) = (-7.47564, 12.6136) +67: (x,y) = (-7.1973, 14.5941) +68: (x,y) = (-8.31568, 12.936) +69: (x,y) = (-6.41357, 12.318) +70: (x,y) = (-5.10145, 10.8086) +71: (x,y) = (-6.46545, 9.34586) +72: (x,y) = (-4.5336, 8.82823) +73: (x,y) = (-4.81194, 10.8088) +74: (x,y) = (-4.77704, 12.8085) +75: (x,y) = (-5.08991, 14.7838) +76: (x,y) = (-5.77395, 12.9044) +77: (x,y) = (-6.65069, 11.1069) +78: (x,y) = (-8.26872, 12.2824) +79: (x,y) = (-10.1231, 13.0316) +80: (x,y) = (-11.4352, 14.5411) +81: (x,y) = (-11.5399, 16.5383) +82: (x,y) = (-13.4525, 17.1231) +83: (x,y) = (-12.1669, 15.591) +84: (x,y) = (-13.0122, 13.7784) +85: (x,y) = (-13.5969, 11.8658) +86: (x,y) = (-12.2586, 10.3795) +87: (x,y) = (-10.2696, 10.5885) +88: (x,y) = (-9.68485, 12.5011) +89: (x,y) = (-10.4341, 10.6468) +90: (x,y) = (-11.6377, 9.04949) +91: (x,y) = (-10.4621, 10.6675) +92: (x,y) = (-11.9942, 9.38195) +93: (x,y) = (-13.4084, 10.7962) +94: (x,y) = (-14.0265, 12.6983) +95: (x,y) = (-14.9961, 10.949) +96: (x,y) = (-13.1167, 11.6331) +97: (x,y) = (-11.6073, 12.9452) +98: (x,y) = (-10.4601, 11.3069) +99: (x,y) = (-12.2727, 12.1521) +100: (x,y) = (-11.9944, 14.1327) +101: (x,y) = (-10.3363, 15.251) +102: (x,y) = (-12.0684, 14.251) +103: (x,y) = (-11.79, 12.2705) +104: (x,y) = (-10.9133, 14.0681) +105: (x,y) = (-11.0528, 12.073) +106: (x,y) = (-9.2552, 11.1962) +107: (x,y) = (-11.2185, 10.8146) +108: (x,y) = (-11.3231, 12.8119) +109: (x,y) = (-10.9758, 10.8423) +110: (x,y) = (-9.31775, 9.72387) +111: (x,y) = (-7.85505, 8.35987) +112: (x,y) = (-7.47343, 10.3231) +113: (x,y) = (-6.82229, 8.43209) +114: (x,y) = (-8.7349, 7.84735) +115: (x,y) = (-10.7045, 8.19464) +116: (x,y) = (-8.87743, 7.38117) +117: (x,y) = (-7.25939, 8.55674) +118: (x,y) = (-5.32754, 8.0391) +119: (x,y) = (-7.12513, 7.16236) +120: (x,y) = (-9.04765, 6.61109) +121: (x,y) = (-8.42962, 4.70897) +122: (x,y) = (-9.14635, 6.57613) +123: (x,y) = (-9.92782, 4.73512) +124: (x,y) = (-8.21348, 3.70505) +125: (x,y) = (-7.59545, 1.80293) +126: (x,y) = (-7.73496, 3.79806) +127: (x,y) = (-8.3861, 5.6891) +128: (x,y) = (-8.0388, 3.71948) +129: (x,y) = (-7.76046, 1.73895) +130: (x,y) = (-9.39876, 2.8861) +131: (x,y) = (-10.5459, 4.52441) +132: (x,y) = (-11.6931, 2.8861) +133: (x,y) = (-12.5383, 1.07349) +134: (x,y) = (-10.6711, 0.35675) +135: (x,y) = (-8.71485, 0.772573) +136: (x,y) = (-6.88775, -0.0409001) +137: (x,y) = (-5.24945, 1.10625) +138: (x,y) = (-7.24671, 1.00158) +139: (x,y) = (-9.11387, 1.71832) +140: (x,y) = (-7.36463, 2.68794) +141: (x,y) = (-9.14664, 1.77996) +142: (x,y) = (-7.48857, 0.661569) +143: (x,y) = (-6.58059, -1.12044) +144: (x,y) = (-7.91885, -2.60673) +145: (x,y) = (-9.68474, -3.54568) +146: (x,y) = (-8.71512, -1.79644) +147: (x,y) = (-8.75003, -3.79613) +148: (x,y) = (-10.6172, -4.51287) +149: (x,y) = (-9.96605, -2.62183) +150: (x,y) = (-11.3301, -1.15912) +151: (x,y) = (-10.3301, 0.572927) +152: (x,y) = (-8.3982, 0.0552888) +153: (x,y) = (-6.53104, 0.772025) +154: (x,y) = (-8.45356, 0.22075) +155: (x,y) = (-9.68488, -1.35527) +156: (x,y) = (-11.6255, -0.871428) +157: (x,y) = (-11.3126, -2.8468) +158: (x,y) = (-12.1578, -4.65942) +159: (x,y) = (-13.6441, -3.32116) +160: (x,y) = (-15.5929, -3.77106) +161: (x,y) = (-14.2808, -2.26164) +162: (x,y) = (-16.0934, -1.41641) +163: (x,y) = (-14.239, -2.16562) +164: (x,y) = (-12.9269, -3.67504) +165: (x,y) = (-13.3768, -5.62378) +166: (x,y) = (-12.8929, -7.56437) +167: (x,y) = (-13.4777, -9.47698) +168: (x,y) = (-11.4886, -9.26792) +169: (x,y) = (-12.3021, -11.095) +170: (x,y) = (-12.6494, -13.0646) +171: (x,y) = (-14.1588, -11.7525) +172: (x,y) = (-14.0542, -13.7498) +173: (x,y) = (-12.1223, -14.2674) +174: (x,y) = (-13.3809, -15.8217) +175: (x,y) = (-14.6396, -14.2674) +176: (x,y) = (-12.6472, -14.4417) +177: (x,y) = (-11.5874, -12.7456) +178: (x,y) = (-12.8995, -11.2362) +179: (x,y) = (-12.7252, -9.24381) +180: (x,y) = (-13.1751, -11.1926) +181: (x,y) = (-15.0294, -10.4433) +182: (x,y) = (-16.7255, -9.3835) +183: (x,y) = (-18.7228, -9.27883) +184: (x,y) = (-17.9413, -7.43782) +185: (x,y) = (-15.966, -7.75069) +186: (x,y) = (-17.7635, -6.87395) +187: (x,y) = (-19.7559, -7.04826) +188: (x,y) = (-21.452, -8.1081) +189: (x,y) = (-19.7028, -7.13848) +190: (x,y) = (-18.5556, -8.77678) +191: (x,y) = (-16.8595, -9.83662) +192: (x,y) = (-15.4955, -8.37391) +193: (x,y) = (-17.4761, -8.65226) +194: (x,y) = (-17.1288, -10.6219) +195: (x,y) = (-18.1288, -8.88982) +196: (x,y) = (-16.5315, -7.68619) +197: (x,y) = (-14.7823, -6.71658) +198: (x,y) = (-12.826, -7.1324) +199: (x,y) = (-11.9492, -8.92999) +200: (x,y) = (-10.3312, -7.75442) +201: (x,y) = (-10.6095, -5.77388) +202: (x,y) = (-8.61716, -5.59957) +203: (x,y) = (-6.86792, -6.56919) +204: (x,y) = (-7.68139, -4.7421) +205: (x,y) = (-7.75119, -6.74088) +206: (x,y) = (-8.98251, -5.16486) +207: (x,y) = (-10.1861, -3.56759) +208: (x,y) = (-12.118, -4.08522) +209: (x,y) = (-13.7563, -5.23238) +210: (x,y) = (-12.9111, -7.04499) +211: (x,y) = (-13.5622, -8.93603) +212: (x,y) = (-13.2493, -10.9114) +213: (x,y) = (-13.4931, -8.92631) +214: (x,y) = (-15.2751, -9.83429) +215: (x,y) = (-13.4931, -10.7423) +216: (x,y) = (-12.875, -12.6444) +217: (x,y) = (-14.3377, -14.0084) +218: (x,y) = (-15.3377, -15.7404) +219: (x,y) = (-13.3487, -15.9495) +220: (x,y) = (-11.4943, -16.6987) +221: (x,y) = (-13.3737, -17.3827) +222: (x,y) = (-11.5761, -16.506) +223: (x,y) = (-13.3581, -17.414) +224: (x,y) = (-12.8405, -15.4821) +225: (x,y) = (-13.3918, -17.4047) +226: (x,y) = (-11.5942, -18.2814) +227: (x,y) = (-9.89809, -19.3412) +228: (x,y) = (-7.9057, -19.1669) +229: (x,y) = (-7.76619, -21.1621) +230: (x,y) = (-9.70678, -21.6459) +231: (x,y) = (-8.55963, -20.0076) +232: (x,y) = (-9.7352, -21.6256) +233: (x,y) = (-8.3712, -20.1629) +234: (x,y) = (-9.43104, -18.4668) +235: (x,y) = (-7.92162, -19.7789) +236: (x,y) = (-5.94109, -19.5006) +237: (x,y) = (-6.88003, -21.2665) +238: (x,y) = (-8.86512, -21.5102) +239: (x,y) = (-10.1238, -19.9559) +240: (x,y) = (-11.4878, -18.4932) +241: (x,y) = (-12.9264, -17.1039) +242: (x,y) = (-12.8218, -19.1012) +243: (x,y) = (-11.4578, -17.6385) +244: (x,y) = (-13.2849, -18.4519) +245: (x,y) = (-11.4722, -17.6067) +246: (x,y) = (-12.8105, -16.1204) +247: (x,y) = (-14.5925, -17.0284) +248: (x,y) = (-13.9745, -15.1263) +249: (x,y) = (-15.8016, -14.3128) +250: (x,y) = (-17.7712, -14.6601) +251: (x,y) = (-15.7739, -14.5554) +252: (x,y) = (-17.7663, -14.7297) +253: (x,y) = (-15.8257, -15.2136) +254: (x,y) = (-14.949, -17.0112) +255: (x,y) = (-14.3977, -18.9337) +256: (x,y) = (-15.0489, -17.0427) +257: (x,y) = (-13.5394, -18.3548) +258: (x,y) = (-11.7418, -19.2315) +259: (x,y) = (-12.5233, -17.3905) +260: (x,y) = (-14.5157, -17.5648) +261: (x,y) = (-15.9784, -18.9288) +262: (x,y) = (-17.8578, -19.6129) +263: (x,y) = (-16.7394, -17.9548) +264: (x,y) = (-14.8169, -17.4035) +265: (x,y) = (-12.8536, -17.7851) +266: (x,y) = (-12.8885, -15.7854) +267: (x,y) = (-13.5726, -13.906) +268: (x,y) = (-15.3046, -14.906) +269: (x,y) = (-17.2452, -15.3899) +270: (x,y) = (-19.1362, -16.041) +271: (x,y) = (-20.5749, -17.4303) +272: (x,y) = (-22.0136, -16.041) +273: (x,y) = (-23.9361, -15.4898) +274: (x,y) = (-22.0235, -14.905) +275: (x,y) = (-22.2326, -16.8941) +276: (x,y) = (-21.3558, -15.0965) +277: (x,y) = (-21.1815, -13.1041) +278: (x,y) = (-23.1621, -12.8257) +279: (x,y) = (-23.4058, -10.8406) +280: (x,y) = (-24.251, -12.6533) +281: (x,y) = (-25.9831, -11.6533) +282: (x,y) = (-24.5444, -13.0426) +283: (x,y) = (-25.1955, -14.9336) +284: (x,y) = (-26.6342, -16.3229) +285: (x,y) = (-24.671, -15.9413) +286: (x,y) = (-26.0092, -17.4276) +287: (x,y) = (-26.7907, -19.2686) +288: (x,y) = (-26.5816, -21.2576) +289: (x,y) = (-26.2343, -23.2273) +290: (x,y) = (-28.0002, -22.2883) +291: (x,y) = (-28.6514, -20.3973) +292: (x,y) = (-26.7493, -21.0153) +293: (x,y) = (-28.7493, -21.0153) +294: (x,y) = (-28.5749, -19.0229) +295: (x,y) = (-26.5777, -18.9183) +296: (x,y) = (-28.4048, -18.1048) +297: (x,y) = (-26.4075, -18.2095) +298: (x,y) = (-24.485, -18.7607) +299: (x,y) = (-26.1431, -17.6423) +300: (x,y) = (-24.1434, -17.6074) +301: (x,y) = (-22.1946, -17.1575) +302: (x,y) = (-20.5766, -15.982) +303: (x,y) = (-19.5766, -14.2499) +304: (x,y) = (-20.9659, -12.8112) +305: (x,y) = (-21.3132, -10.8416) +306: (x,y) = (-19.7811, -9.55605) +307: (x,y) = (-17.8586, -10.1073) +308: (x,y) = (-16.3723, -8.76906) +309: (x,y) = (-14.775, -7.56543) +310: (x,y) = (-16.3931, -8.741) +311: (x,y) = (-18.1423, -9.71062) +312: (x,y) = (-19.0191, -7.91303) +313: (x,y) = (-17.0558, -8.29465) +314: (x,y) = (-16.2423, -6.46756) +315: (x,y) = (-17.9197, -5.37828) +316: (x,y) = (-15.9391, -5.65663) +317: (x,y) = (-17.8412, -5.03859) +318: (x,y) = (-16.4026, -3.64928) +319: (x,y) = (-14.8705, -2.3637) +320: (x,y) = (-14.4889, -4.32696) +321: (x,y) = (-16.2548, -5.2659) +322: (x,y) = (-17.344, -6.94324) +323: (x,y) = (-15.4034, -7.42708) +324: (x,y) = (-13.7261, -8.51636) +325: (x,y) = (-13.4478, -6.53583) +326: (x,y) = (-12.3006, -8.17413) +327: (x,y) = (-13.4762, -9.79216) +328: (x,y) = (-11.9219, -11.0508) +329: (x,y) = (-10.6363, -12.5829) +330: (x,y) = (-10.0516, -10.6703) +331: (x,y) = (-11.0212, -12.4195) +332: (x,y) = (-12.5533, -13.7051) +333: (x,y) = (-11.164, -15.1438) +334: (x,y) = (-10.4799, -17.0232) +335: (x,y) = (-11.3567, -18.8208) +336: (x,y) = (-9.40036, -19.2366) +337: (x,y) = (-9.40036, -21.2366) +338: (x,y) = (-7.40523, -21.0971) +339: (x,y) = (-9.11957, -20.067) +340: (x,y) = (-8.30609, -18.2399) +341: (x,y) = (-6.3655, -18.7237) +342: (x,y) = (-8.02358, -19.8421) +343: (x,y) = (-7.95378, -21.8409) +344: (x,y) = (-6.39949, -20.5823) +345: (x,y) = (-4.40071, -20.5125) +346: (x,y) = (-6.39583, -20.652) +347: (x,y) = (-7.04697, -22.543) +348: (x,y) = (-8.64424, -23.7466) +349: (x,y) = (-6.83163, -24.5919) +350: (x,y) = (-4.92951, -23.9738) +351: (x,y) = (-6.10508, -25.5919) +352: (x,y) = (-7.44334, -24.1056) +353: (x,y) = (-5.93392, -25.4177) +354: (x,y) = (-7.74654, -24.5725) +355: (x,y) = (-9.73558, -24.7815) +356: (x,y) = (-11.5332, -23.9048) +357: (x,y) = (-13.1715, -25.0519) +358: (x,y) = (-13.2413, -27.0507) +359: (x,y) = (-14.3597, -28.7088) +360: (x,y) = (-14.4643, -26.7115) +361: (x,y) = (-14.9142, -28.6603) +362: (x,y) = (-15.8532, -26.8944) +363: (x,y) = (-15.3693, -28.835) +364: (x,y) = (-13.9307, -27.4457) +365: (x,y) = (-14.6474, -29.3128) +366: (x,y) = (-16.6106, -28.9312) +367: (x,y) = (-18, -30.3699) +368: (x,y) = (-19.6961, -31.4297) +369: (x,y) = (-19.7659, -29.4309) +370: (x,y) = (-20.9695, -27.8337) +371: (x,y) = (-18.989, -28.112) +372: (x,y) = (-20.9377, -28.5619) +373: (x,y) = (-19.2994, -27.4148) +374: (x,y) = (-20.5307, -25.8387) +375: (x,y) = (-20.2524, -27.8193) +376: (x,y) = (-19.7011, -29.7418) +377: (x,y) = (-18.2624, -31.1311) +378: (x,y) = (-20.2548, -30.9568) +379: (x,y) = (-21.9321, -29.8675) +380: (x,y) = (-20.9932, -31.6334) +381: (x,y) = (-19.1956, -30.7567) +382: (x,y) = (-18.7118, -28.8161) +383: (x,y) = (-20.5244, -29.6613) +384: (x,y) = (-22.337, -28.8161) +385: (x,y) = (-21.5235, -30.6432) +386: (x,y) = (-20.7743, -28.7888) +387: (x,y) = (-22.6869, -28.2041) +388: (x,y) = (-22.1022, -30.1167) +389: (x,y) = (-23.4915, -28.678) +390: (x,y) = (-25.2235, -27.678) +391: (x,y) = (-26.9894, -26.7391) +392: (x,y) = (-26.9196, -24.7403) +393: (x,y) = (-25.716, -23.143) +394: (x,y) = (-26.1659, -21.1943) +395: (x,y) = (-27.3415, -22.8123) +396: (x,y) = (-29.1074, -23.7512) +397: (x,y) = (-27.8218, -22.2192) +398: (x,y) = (-25.9808, -23.0006) +399: (x,y) = (-24.3628, -21.825) +400: (x,y) = (-26.1603, -22.7018) +401: (x,y) = (-27.6466, -24.04) +402: (x,y) = (-28.8503, -22.4428) +403: (x,y) = (-28.7456, -24.44) +404: (x,y) = (-29.5271, -26.281) +405: (x,y) = (-29.4573, -28.2798) +406: (x,y) = (-27.8392, -29.4554) +407: (x,y) = (-28.9285, -27.7781) +408: (x,y) = (-27.0159, -27.1933) +409: (x,y) = (-28.8285, -26.3481) +410: (x,y) = (-30.3828, -25.0894) +411: (x,y) = (-32.3679, -25.3332) +412: (x,y) = (-34.0452, -24.2439) +413: (x,y) = (-36.0258, -24.5222) +414: (x,y) = (-37.9483, -25.0735) +415: (x,y) = (-36.234, -26.1036) +416: (x,y) = (-37.2036, -27.8528) +417: (x,y) = (-35.2084, -27.9923) +418: (x,y) = (-33.2388, -28.3396) +419: (x,y) = (-35.0798, -27.5582) +420: (x,y) = (-35.3236, -29.5433) +421: (x,y) = (-35.6709, -27.5737) +422: (x,y) = (-37.538, -26.8569) +423: (x,y) = (-35.5627, -27.1698) +424: (x,y) = (-37.3898, -26.3563) +425: (x,y) = (-37.1114, -24.3758) +426: (x,y) = (-38.2007, -26.0531) +427: (x,y) = (-39.755, -24.7945) +428: (x,y) = (-41.0136, -23.2402) +429: (x,y) = (-40.4623, -25.1627) +430: (x,y) = (-39.4025, -23.4666) +431: (x,y) = (-37.4393, -23.085) +432: (x,y) = (-35.5266, -22.5003) +433: (x,y) = (-34.2411, -20.9682) +434: (x,y) = (-32.9555, -22.5003) +435: (x,y) = (-30.975, -22.2219) +436: (x,y) = (-32.8975, -21.6706) +437: (x,y) = (-31.6119, -20.1385) +438: (x,y) = (-32.7303, -18.4805) +439: (x,y) = (-31.244, -19.8187) +440: (x,y) = (-32.2136, -18.0695) +441: (x,y) = (-30.2331, -18.3478) +442: (x,y) = (-28.342, -17.6967) +443: (x,y) = (-28.6204, -15.7162) +444: (x,y) = (-30.1964, -14.4848) +445: (x,y) = (-28.9928, -16.0821) +446: (x,y) = (-27.0174, -15.7692) +447: (x,y) = (-28.3814, -14.3065) +448: (x,y) = (-29.2581, -16.1041) +449: (x,y) = (-30.8964, -14.957) +450: (x,y) = (-32.2086, -13.4476) +451: (x,y) = (-34.0062, -12.5708) +452: (x,y) = (-33.4549, -10.6483) +453: (x,y) = (-31.4916, -10.2667) +454: (x,y) = (-33.3588, -9.54993) +455: (x,y) = (-31.8494, -8.23781) +456: (x,y) = (-31.4335, -6.28152) +457: (x,y) = (-33.4287, -6.14201) +458: (x,y) = (-35.3983, -6.4893) +459: (x,y) = (-36.2435, -4.67669) +460: (x,y) = (-35.5595, -2.7973) +461: (x,y) = (-35.6293, -0.79852) +462: (x,y) = (-35.4202, 1.19052) +463: (x,y) = (-33.4448, 0.877654) +464: (x,y) = (-31.4558, 1.08671) +465: (x,y) = (-32.8451, -0.351968) +466: (x,y) = (-32.8451, 1.64803) +467: (x,y) = (-33.7531, 3.43004) +468: (x,y) = (-31.8125, 3.91389) +469: (x,y) = (-33.7688, 4.32971) +470: (x,y) = (-32.0915, 3.24043) +471: (x,y) = (-34.0402, 2.79053) +472: (x,y) = (-32.0597, 2.51219) +473: (x,y) = (-32.338, 4.49272) +474: (x,y) = (-30.762, 3.2614) +475: (x,y) = (-29.2526, 4.57352) +476: (x,y) = (-28.1342, 6.23159) +477: (x,y) = (-29.7102, 5.00027) +478: (x,y) = (-29.5707, 3.00514) +479: (x,y) = (-31.2288, 4.12353) +480: (x,y) = (-29.7661, 2.75953) +481: (x,y) = (-31.4241, 1.64114) +482: (x,y) = (-33.1734, 0.671525) +483: (x,y) = (-35.1658, 0.497213) +484: (x,y) = (-36.8041, -0.649939) +485: (x,y) = (-36.8041, 1.35006) +486: (x,y) = (-35.8961, 3.13207) +487: (x,y) = (-36.835, 4.89797) +488: (x,y) = (-35.6879, 3.25966) +489: (x,y) = (-33.8608, 2.44619) +490: (x,y) = (-35.0079, 0.807887) +491: (x,y) = (-33.0592, 1.25779) +492: (x,y) = (-31.9408, 2.91586) +493: (x,y) = (-29.9484, 3.09018) +494: (x,y) = (-30.1575, 5.07922) +495: (x,y) = (-29.8102, 7.04884) +496: (x,y) = (-30.4613, 8.93987) +497: (x,y) = (-31.4003, 10.7058) +498: (x,y) = (-33.3129, 10.121) +499: (x,y) = (-34.5165, 11.7183) +500: (x,y) = (-32.536, 11.4399) +501: (x,y) = (-31.3604, 9.82192) +502: (x,y) = (-30.1291, 8.24589) +503: (x,y) = (-29.3156, 10.073) +504: (x,y) = (-28.346, 11.8222) +505: (x,y) = (-30.2004, 11.073) +506: (x,y) = (-28.3733, 10.2595) +507: (x,y) = (-28.8571, 8.31895) +508: (x,y) = (-30.8376, 8.59729) +509: (x,y) = (-31.5217, 10.4767) +510: (x,y) = (-29.5898, 9.95904) +511: (x,y) = (-28.9718, 11.8612) +512: (x,y) = (-30.9472, 12.174) +513: (x,y) = (-32.9362, 11.965) +514: (x,y) = (-34.5943, 13.0834) +515: (x,y) = (-32.7817, 13.9286) +516: (x,y) = (-34.268, 12.5903) +517: (x,y) = (-35.6822, 11.1761) +518: (x,y) = (-37.6819, 11.1412) +519: (x,y) = (-36.6518, 9.42687) +520: (x,y) = (-38.3099, 10.5453) +521: (x,y) = (-36.4973, 11.3905) +522: (x,y) = (-37.6444, 13.0288) +523: (x,y) = (-38.2292, 14.9414) +524: (x,y) = (-39.2592, 13.2271) +525: (x,y) = (-41.0412, 12.3191) +526: (x,y) = (-43.0412, 12.3191) +527: (x,y) = (-42.2598, 10.4781) +528: (x,y) = (-44.0724, 9.63285) +529: (x,y) = (-42.3065, 8.6939) +530: (x,y) = (-43.2454, 10.4598) +531: (x,y) = (-41.6912, 11.7184) +532: (x,y) = (-40.5728, 13.3765) +533: (x,y) = (-42.2111, 14.5237) +534: (x,y) = (-43.8884, 13.4344) +535: (x,y) = (-45.3747, 14.7727) +536: (x,y) = (-43.7166, 13.6543) +537: (x,y) = (-45.6187, 13.0362) +538: (x,y) = (-44.5295, 11.3589) +539: (x,y) = (-42.7168, 10.5137) +540: (x,y) = (-44.4661, 11.4833) +541: (x,y) = (-46.3571, 12.1344) +542: (x,y) = (-44.7188, 10.9873) +543: (x,y) = (-46.3571, 9.8401) +544: (x,y) = (-47.8198, 8.47611) +545: (x,y) = (-48.6651, 6.66349) +546: (x,y) = (-49.0467, 8.62675) +547: (x,y) = (-50.4107, 7.16404) +After 547 steps, the subject has the following location: +(x,y) = (-50.4107, 7.16404) + or +(m,a) = (50.9172, 171.912) +Average outward distance per step = 0.0930844 +1: (x,y) = (-0.781462, 1.84101) +2: (x,y) = (-0.955774, -0.15138) +3: (x,y) = (-2.01561, 1.54472) +4: (x,y) = (-3.63365, 0.369146) +5: (x,y) = (-2.63365, -1.3629) +6: (x,y) = (-2.18374, -3.31164) +7: (x,y) = (-4.12434, -3.79549) +8: (x,y) = (-2.52706, -2.59186) +9: (x,y) = (-4.42918, -1.97382) +10: (x,y) = (-6.3517, -1.42255) +11: (x,y) = (-7.13316, 0.41846) +12: (x,y) = (-9.12829, 0.278947) +13: (x,y) = (-10.5176, 1.71763) +14: (x,y) = (-11.5774, 0.0215302) +15: (x,y) = (-10.796, -1.81948) +16: (x,y) = (-10.5522, -3.80457) +17: (x,y) = (-10.2739, -5.78511) +18: (x,y) = (-10.3437, -3.78633) +19: (x,y) = (-11.941, -4.98996) +20: (x,y) = (-13.7069, -4.05101) +21: (x,y) = (-11.8048, -3.43298) +22: (x,y) = (-13.6841, -2.74894) +23: (x,y) = (-13.4404, -4.73403) +24: (x,y) = (-11.6428, -5.61077) +25: (x,y) = (-13.3389, -4.55094) +26: (x,y) = (-15.3085, -4.20364) +27: (x,y) = (-13.3389, -4.55094) +28: (x,y) = (-13.2342, -2.55368) +29: (x,y) = (-12.8869, -0.58406) +30: (x,y) = (-10.9644, -1.13534) +31: (x,y) = (-9.67884, 0.396754) +32: (x,y) = (-7.69375, 0.640492) +33: (x,y) = (-5.9617, 1.64049) +34: (x,y) = (-4.87242, 3.31783) +35: (x,y) = (-4.83751, 1.31814) +36: (x,y) = (-4.94219, 3.3154) +37: (x,y) = (-3.16017, 2.40742) +38: (x,y) = (-5.05121, 1.75628) +39: (x,y) = (-5.12101, -0.242502) +40: (x,y) = (-6.26816, -1.88081) +41: (x,y) = (-7.2071, -3.6467) +42: (x,y) = (-5.32772, -2.96266) +43: (x,y) = (-3.63162, -1.90282) +44: (x,y) = (-3.87536, -3.88791) +45: (x,y) = (-1.96275, -3.30317) +46: (x,y) = (-0.704111, -1.74888) +47: (x,y) = (-0.288288, -3.70517) +48: (x,y) = (-1.00502, -5.57234) +49: (x,y) = (-2.68237, -4.48306) +50: (x,y) = (-4.59497, -3.89831) +51: (x,y) = (-6.5901, -3.7588) +52: (x,y) = (-7.76567, -2.14077) +53: (x,y) = (-8.31695, -0.218243) +54: (x,y) = (-7.00483, -1.72766) +55: (x,y) = (-8.83192, -2.54114) +56: (x,y) = (-6.83679, -2.68065) +57: (x,y) = (-6.80189, -0.680953) +58: (x,y) = (-6.11785, -2.56034) +59: (x,y) = (-7.23623, -4.21841) +60: (x,y) = (-9.11562, -3.53437) +61: (x,y) = (-7.40128, -2.5043) +62: (x,y) = (-7.5408, -4.49943) +63: (x,y) = (-9.13807, -5.70306) +64: (x,y) = (-8.65422, -3.76246) +65: (x,y) = (-9.96634, -5.27188) +66: (x,y) = (-11.7484, -4.3639) +67: (x,y) = (-10.8094, -6.1298) +68: (x,y) = (-10.0927, -4.26264) +69: (x,y) = (-10.4743, -2.29938) +70: (x,y) = (-9.99045, -0.358791) +71: (x,y) = (-8.08834, 0.259243) +72: (x,y) = (-9.78443, 1.31908) +73: (x,y) = (-10.0628, -0.661454) +74: (x,y) = (-9.54514, -2.59331) +75: (x,y) = (-10.9594, -1.17909) +76: (x,y) = (-11.6105, -3.07013) +77: (x,y) = (-10.797, -4.89722) +78: (x,y) = (-12.7776, -5.17557) +79: (x,y) = (-14.4549, -6.26484) +80: (x,y) = (-16.4439, -6.4739) +81: (x,y) = (-14.4686, -6.78677) +82: (x,y) = (-12.4698, -6.85657) +83: (x,y) = (-11.0805, -8.29525) +84: (x,y) = (-9.69115, -9.73393) +85: (x,y) = (-8.97441, -7.86677) +86: (x,y) = (-7.20852, -8.80571) +87: (x,y) = (-8.76281, -10.0644) +88: (x,y) = (-9.67079, -11.8464) +89: (x,y) = (-7.7302, -11.3625) +90: (x,y) = (-6.61181, -13.0206) +91: (x,y) = (-8.60907, -13.1253) +92: (x,y) = (-8.02433, -11.2127) +93: (x,y) = (-6.8207, -12.8099) +94: (x,y) = (-5.22343, -14.0136) +95: (x,y) = (-4.53939, -15.8929) +96: (x,y) = (-6.46191, -15.3417) +97: (x,y) = (-4.6209, -14.5602) +98: (x,y) = (-2.71879, -13.9422) +99: (x,y) = (-2.20115, -15.874) +100: (x,y) = (-4.19628, -15.7345) +101: (x,y) = (-5.56027, -14.2718) +102: (x,y) = (-4.2747, -12.7397) +103: (x,y) = (-3.2747, -11.0077) +104: (x,y) = (-1.29932, -10.6948) +105: (x,y) = (-3.04856, -9.72518) +106: (x,y) = (-1.13595, -9.14043) +107: (x,y) = (-0.788655, -11.11) +108: (x,y) = (-1.3734, -9.19744) +109: (x,y) = (-1.4432, -11.1962) +110: (x,y) = (-2.67452, -9.6202) +111: (x,y) = (-2.53501, -7.62507) +112: (x,y) = (-0.876933, -6.50669) +113: (x,y) = (-1.32683, -8.45543) +114: (x,y) = (0.159455, -9.79369) +115: (x,y) = (-1.62256, -10.7017) +116: (x,y) = (-3.56315, -10.2178) +117: (x,y) = (-2.12447, -8.82851) +118: (x,y) = (-1.70865, -6.87221) +119: (x,y) = (0.0056879, -7.90229) +120: (x,y) = (-0.168624, -9.89468) +121: (x,y) = (-0.273295, -7.89742) +122: (x,y) = (1.683, -8.31324) +123: (x,y) = (2.33414, -6.42221) +124: (x,y) = (1.24486, -4.74486) +125: (x,y) = (3.20811, -5.12648) +126: (x,y) = (3.38242, -7.11887) +127: (x,y) = (1.56981, -7.96411) +128: (x,y) = (2.53943, -6.21487) +129: (x,y) = (3.50905, -7.96411) +130: (x,y) = (1.52395, -8.20785) +131: (x,y) = (3.49933, -8.52072) +132: (x,y) = (5.46259, -8.90233) +133: (x,y) = (3.48721, -9.2152) +134: (x,y) = (4.99663, -7.90308) +135: (x,y) = (3.53392, -6.53909) +136: (x,y) = (2.24835, -5.007) +137: (x,y) = (3.86638, -6.18257) +138: (x,y) = (4.98477, -4.52449) +139: (x,y) = (6.98446, -4.48959) +140: (x,y) = (8.29658, -2.98017) +141: (x,y) = (7.67854, -4.88228) +142: (x,y) = (7.71345, -6.88198) +143: (x,y) = (7.60878, -4.88472) +144: (x,y) = (5.74162, -4.16798) +145: (x,y) = (6.01996, -2.18745) +146: (x,y) = (7.50625, -0.849187) +147: (x,y) = (5.90898, 0.354443) +148: (x,y) = (5.69992, 2.34349) +149: (x,y) = (4.76098, 4.10938) +150: (x,y) = (5.27862, 2.17753) +151: (x,y) = (7.10571, 2.991) +152: (x,y) = (8.25286, 4.62931) +153: (x,y) = (7.34488, 2.84729) +154: (x,y) = (5.35584, 3.05635) +155: (x,y) = (3.35584, 3.05635) +156: (x,y) = (2.94002, 5.01265) +157: (x,y) = (2.90511, 3.01295) +158: (x,y) = (4.36782, 4.37695) +159: (x,y) = (4.64616, 6.35748) +160: (x,y) = (6.6267, 6.63583) +161: (x,y) = (5.23738, 5.19715) +162: (x,y) = (4.89009, 7.16677) +163: (x,y) = (4.92499, 5.16707) +164: (x,y) = (6.10056, 6.78511) +165: (x,y) = (7.33189, 5.20908) +166: (x,y) = (5.36227, 5.55638) +167: (x,y) = (3.52126, 4.77492) +168: (x,y) = (1.52887, 4.94923) +169: (x,y) = (0.243295, 3.41714) +170: (x,y) = (-1.63609, 4.10118) +171: (x,y) = (-0.19741, 2.71186) +172: (x,y) = (-2.12926, 2.19423) +173: (x,y) = (-3.97027, 2.97569) +174: (x,y) = (-3.6574, 4.95106) +175: (x,y) = (-2.71846, 3.18517) +176: (x,y) = (-1.54289, 1.56714) +177: (x,y) = (-3.43393, 2.21827) +178: (x,y) = (-5.14826, 1.1882) +179: (x,y) = (-6.23754, 2.86554) +180: (x,y) = (-5.89024, 4.83515) +181: (x,y) = (-4.45156, 3.44584) +182: (x,y) = (-3.63809, 5.27293) +183: (x,y) = (-3.8124, 7.26532) +184: (x,y) = (-2.60877, 8.86259) +185: (x,y) = (-4.60847, 8.89749) +186: (x,y) = (-5.38993, 7.05648) +187: (x,y) = (-5.25042, 9.05161) +188: (x,y) = (-5.25042, 11.0516) +189: (x,y) = (-6.73671, 12.3899) +190: (x,y) = (-6.73671, 14.3899) +191: (x,y) = (-6.91102, 12.3975) +192: (x,y) = (-5.27271, 11.2503) +193: (x,y) = (-6.61097, 9.76404) +194: (x,y) = (-6.61097, 7.76404) +195: (x,y) = (-7.64105, 6.0497) +196: (x,y) = (-8.42251, 7.89071) +197: (x,y) = (-10.0999, 8.97999) +198: (x,y) = (-8.22047, 8.29595) +199: (x,y) = (-8.18556, 10.2956) +200: (x,y) = (-8.11576, 8.29687) +201: (x,y) = (-10.0476, 8.8145) +202: (x,y) = (-9.52998, 10.7464) +203: (x,y) = (-10.0138, 12.6869) +204: (x,y) = (-11.5681, 11.4283) +205: (x,y) = (-13.5244, 11.0125) +206: (x,y) = (-13.4895, 9.01279) +207: (x,y) = (-13.8024, 7.03741) +208: (x,y) = (-13.3525, 5.08867) +209: (x,y) = (-14.3825, 3.37434) +210: (x,y) = (-13.7314, 5.26537) +211: (x,y) = (-15.5134, 6.17335) +212: (x,y) = (-13.9813, 4.88778) +213: (x,y) = (-14.5326, 2.96526) +214: (x,y) = (-15.8709, 4.45155) +215: (x,y) = (-15.7314, 6.44667) +216: (x,y) = (-14.2451, 7.78493) +217: (x,y) = (-13.1852, 9.48103) +218: (x,y) = (-11.8997, 7.94894) +219: (x,y) = (-13.289, 9.38762) +220: (x,y) = (-12.1418, 11.0259) +221: (x,y) = (-10.6791, 9.66193) +222: (x,y) = (-9.34085, 8.17564) +223: (x,y) = (-10.5164, 6.55761) +224: (x,y) = (-8.75053, 5.61866) +225: (x,y) = (-9.23437, 7.55925) +226: (x,y) = (-9.98358, 9.41362) +227: (x,y) = (-10.3994, 11.3699) +228: (x,y) = (-11.9967, 12.5735) +229: (x,y) = (-9.99698, 12.6085) +230: (x,y) = (-9.64968, 10.6388) +231: (x,y) = (-11.5623, 11.2236) +232: (x,y) = (-12.6807, 9.5655) +233: (x,y) = (-14.6758, 9.42599) +234: (x,y) = (-15.6758, 7.69394) +235: (x,y) = (-15.2259, 9.64268) +236: (x,y) = (-13.5116, 10.6728) +237: (x,y) = (-15.3526, 11.4542) +238: (x,y) = (-14.4758, 9.65663) +239: (x,y) = (-14.6154, 11.6518) +240: (x,y) = (-12.6263, 11.4427) +241: (x,y) = (-14.6263, 11.4427) +242: (x,y) = (-13.5079, 9.78463) +243: (x,y) = (-13.0921, 7.82833) +244: (x,y) = (-14.5548, 6.46434) +245: (x,y) = (-16.3958, 5.68287) +246: (x,y) = (-15.6791, 3.81571) +247: (x,y) = (-17.3934, 4.84579) +248: (x,y) = (-17.9111, 2.91394) +249: (x,y) = (-19.8429, 2.3963) +250: (x,y) = (-19.5992, 4.38139) +251: (x,y) = (-17.7448, 3.63218) +252: (x,y) = (-19.0831, 2.14589) +253: (x,y) = (-17.2159, 2.86262) +254: (x,y) = (-16.5319, 4.74201) +255: (x,y) = (-14.9558, 5.97333) +256: (x,y) = (-16.103, 7.61164) +257: (x,y) = (-17.3066, 9.20891) +258: (x,y) = (-18.1201, 11.036) +259: (x,y) = (-18.4674, 13.0056) +260: (x,y) = (-16.9353, 14.2912) +261: (x,y) = (-17.9049, 16.0404) +262: (x,y) = (-19.217, 14.531) +263: (x,y) = (-17.853, 13.0683) +264: (x,y) = (-15.962, 12.4172) +265: (x,y) = (-16.7112, 14.2715) +266: (x,y) = (-15.0151, 15.3314) +267: (x,y) = (-14.8408, 13.339) +268: (x,y) = (-16.7895, 13.7889) +269: (x,y) = (-18.299, 15.101) +270: (x,y) = (-19.6372, 16.5873) +271: (x,y) = (-21.2133, 17.8186) +272: (x,y) = (-22.6026, 19.2573) +273: (x,y) = (-20.9252, 18.168) +274: (x,y) = (-22.3145, 19.6067) +275: (x,y) = (-23.096, 17.7657) +276: (x,y) = (-25.0765, 18.044) +277: (x,y) = (-23.1202, 18.4599) +278: (x,y) = (-24.9874, 19.1766) +279: (x,y) = (-25.6054, 17.2745) +280: (x,y) = (-25.3617, 15.2894) +281: (x,y) = (-24.8779, 13.3488) +282: (x,y) = (-22.946, 13.8664) +283: (x,y) = (-21.055, 14.5176) +284: (x,y) = (-19.0854, 14.8649) +285: (x,y) = (-20.4494, 13.4022) +286: (x,y) = (-19.0351, 11.9879) +287: (x,y) = (-17.8315, 10.3907) +288: (x,y) = (-17.5186, 8.4153) +289: (x,y) = (-15.5381, 8.69364) +290: (x,y) = (-13.9201, 9.86921) +291: (x,y) = (-15.8111, 10.5204) +292: (x,y) = (-14.8111, 8.7883) +293: (x,y) = (-13.0291, 7.88032) +294: (x,y) = (-13.6802, 5.98928) +295: (x,y) = (-13.5059, 3.99689) +296: (x,y) = (-15.1032, 2.79326) +297: (x,y) = (-15.4505, 0.823646) +298: (x,y) = (-17.0265, -0.407677) +299: (x,y) = (-15.3684, 0.710709) +300: (x,y) = (-13.4774, 0.0595728) +301: (x,y) = (-15.4664, -0.149484) +302: (x,y) = (-14.9826, -2.09008) +303: (x,y) = (-16.1297, -3.72838) +304: (x,y) = (-14.3171, -2.88314) +305: (x,y) = (-14.2822, -0.883448) +306: (x,y) = (-16.2455, -1.26507) +307: (x,y) = (-17.9775, -0.265066) +308: (x,y) = (-17.3595, 1.63705) +309: (x,y) = (-18.7982, 0.247731) +310: (x,y) = (-20.0018, -1.34954) +311: (x,y) = (-20.3491, -3.31916) +312: (x,y) = (-21.8354, -1.98089) +313: (x,y) = (-23.7672, -1.46326) +314: (x,y) = (-25.4055, -0.316104) +315: (x,y) = (-23.4165, -0.525161) +316: (x,y) = (-25.1985, 0.38282) +317: (x,y) = (-23.8092, 1.8215) +318: (x,y) = (-21.9821, 2.63497) +319: (x,y) = (-21.4645, 4.56682) +320: (x,y) = (-19.8672, 3.36319) +321: (x,y) = (-20.2145, 1.39358) +322: (x,y) = (-18.4019, 0.548343) +323: (x,y) = (-19.2471, -1.26427) +324: (x,y) = (-19.3866, -3.2594) +325: (x,y) = (-17.9003, -1.92114) +326: (x,y) = (-19.6324, -2.92114) +327: (x,y) = (-17.6433, -3.1302) +328: (x,y) = (-16.9922, -5.02123) +329: (x,y) = (-15.2102, -5.92921) +330: (x,y) = (-17.0646, -5.18) +331: (x,y) = (-19.0633, -5.1102) +332: (x,y) = (-21.0585, -5.24972) +333: (x,y) = (-20.6086, -7.19846) +334: (x,y) = (-18.696, -7.7832) +335: (x,y) = (-17.788, -6.00119) +336: (x,y) = (-19.679, -5.35005) +337: (x,y) = (-18.1696, -4.03793) +338: (x,y) = (-17.2, -2.28869) +339: (x,y) = (-19.091, -1.63756) +340: (x,y) = (-19.4039, 0.337821) +341: (x,y) = (-21.1698, -0.601122) +342: (x,y) = (-21.919, 1.25325) +343: (x,y) = (-23.76, 0.471783) +344: (x,y) = (-22.7002, -1.22431) +345: (x,y) = (-24.4494, -0.254694) +346: (x,y) = (-26.4418, -0.429005) +347: (x,y) = (-24.4528, -0.219948) +348: (x,y) = (-26.202, -1.18957) +349: (x,y) = (-24.3894, -2.0348) +350: (x,y) = (-25.7015, -0.525385) +351: (x,y) = (-24.2628, 0.863932) +352: (x,y) = (-24.1581, -1.13333) +353: (x,y) = (-25.2474, 0.544014) +354: (x,y) = (-23.5893, 1.6624) +355: (x,y) = (-21.7623, 0.848926) +356: (x,y) = (-23.3165, -0.409715) +357: (x,y) = (-22.6325, 1.46967) +358: (x,y) = (-24.3098, 2.55895) +359: (x,y) = (-22.3536, 2.14313) +360: (x,y) = (-20.3973, 1.7273) +361: (x,y) = (-22.396, 1.7971) +362: (x,y) = (-23.5144, 0.139026) +363: (x,y) = (-24.3597, 1.95164) +364: (x,y) = (-24.6034, -0.0334509) +365: (x,y) = (-22.6046, -0.10325) +366: (x,y) = (-22.1547, 1.84549) +367: (x,y) = (-23.1547, 0.113439) +368: (x,y) = (-21.6004, 1.37208) +369: (x,y) = (-23.3824, 0.464099) +370: (x,y) = (-21.4019, 0.185753) +371: (x,y) = (-21.2624, 2.18088) +372: (x,y) = (-19.4804, 1.2729) +373: (x,y) = (-17.6984, 2.18088) +374: (x,y) = (-17.4893, 0.191837) +375: (x,y) = (-15.4905, 0.261636) +376: (x,y) = (-16.6377, -1.37667) +377: (x,y) = (-15.2484, -2.81535) +378: (x,y) = (-17.2047, -2.39952) +379: (x,y) = (-19.0022, -3.27627) +380: (x,y) = (-17.1001, -2.65823) +381: (x,y) = (-17.2396, -0.663104) +382: (x,y) = (-15.9541, -2.19519) +383: (x,y) = (-14.422, -0.909618) +384: (x,y) = (-16.4192, -0.804946) +385: (x,y) = (-14.4629, -0.389123) +386: (x,y) = (-13.9117, -2.31165) +387: (x,y) = (-13.9117, -0.311646) +388: (x,y) = (-12.0707, 0.469816) +389: (x,y) = (-10.7851, 2.00191) +390: (x,y) = (-10.82, 0.00220983) +391: (x,y) = (-10.6805, -1.99292) +392: (x,y) = (-11.5572, -3.79051) +393: (x,y) = (-11.9045, -1.82089) +394: (x,y) = (-13.6189, -0.790815) +395: (x,y) = (-11.7517, -0.0740788) +396: (x,y) = (-9.78843, 0.307539) +397: (x,y) = (-9.37261, -1.64876) +398: (x,y) = (-10.9699, -0.445126) +399: (x,y) = (-12.8493, 0.238914) +400: (x,y) = (-11.9103, -1.52698) +401: (x,y) = (-10.1283, -2.43496) +402: (x,y) = (-10.9418, -4.26205) +403: (x,y) = (-12.8089, -3.54532) +404: (x,y) = (-10.9418, -2.82858) +405: (x,y) = (-9.03967, -2.21055) +406: (x,y) = (-8.4884, -4.13307) +407: (x,y) = (-10.1267, -2.98592) +408: (x,y) = (-12.083, -3.40174) +409: (x,y) = (-13.447, -1.93903) +410: (x,y) = (-14.355, -0.15702) +411: (x,y) = (-13.355, 1.57503) +412: (x,y) = (-11.3917, 1.95665) +413: (x,y) = (-10.8404, 3.87917) +414: (x,y) = (-9.1631, 4.96845) +415: (x,y) = (-9.26778, 6.96571) +416: (x,y) = (-11.2529, 6.72197) +417: (x,y) = (-11.9696, 8.58913) +418: (x,y) = (-12.248, 10.5697) +419: (x,y) = (-11.2783, 8.82043) +420: (x,y) = (-12.6676, 10.2591) +421: (x,y) = (-10.8701, 9.38237) +422: (x,y) = (-12.3087, 7.99305) +423: (x,y) = (-10.36, 8.44295) +424: (x,y) = (-9.77526, 6.53034) +425: (x,y) = (-11.7643, 6.32128) +426: (x,y) = (-12.2481, 4.38069) +427: (x,y) = (-11.9008, 6.35031) +428: (x,y) = (-13.9008, 6.35031) +429: (x,y) = (-14.9008, 4.61826) +430: (x,y) = (-14.6918, 2.62921) +431: (x,y) = (-16.6236, 3.14685) +432: (x,y) = (-17.742, 1.48878) +433: (x,y) = (-16.1877, 0.230136) +434: (x,y) = (-14.188, 0.26504) +435: (x,y) = (-14.2927, -1.73222) +436: (x,y) = (-15.1695, 0.0653695) +437: (x,y) = (-16.5077, 1.55166) +438: (x,y) = (-17.0925, -0.36095) +439: (x,y) = (-18.2961, -1.95822) +440: (x,y) = (-20.2766, -1.67988) +441: (x,y) = (-19.6255, -3.57091) +442: (x,y) = (-18.5071, -1.91284) +443: (x,y) = (-19.9213, -0.498624) +444: (x,y) = (-21.9104, -0.289567) +445: (x,y) = (-23.0575, -1.92787) +446: (x,y) = (-21.2599, -1.05113) +447: (x,y) = (-21.6415, 0.912126) +448: (x,y) = (-23.6403, 0.842327) +449: (x,y) = (-21.6513, 1.05138) +450: (x,y) = (-22.9369, -0.480705) +451: (x,y) = (-21.5226, -1.89492) +452: (x,y) = (-23.5178, -1.75541) +453: (x,y) = (-23.7615, 0.229687) +454: (x,y) = (-25.6741, -0.355057) +455: (x,y) = (-23.6817, -0.529368) +456: (x,y) = (-25.2578, 0.701955) +457: (x,y) = (-24.7401, -1.2299) +458: (x,y) = (-26.0257, -2.76199) +459: (x,y) = (-28.0062, -2.48364) +460: (x,y) = (-26.2919, -3.51372) +461: (x,y) = (-24.4648, -4.32719) +462: (x,y) = (-22.5854, -3.64315) +463: (x,y) = (-21.4961, -1.96581) +464: (x,y) = (-20.7794, -3.83297) +465: (x,y) = (-22.7548, -3.5201) +466: (x,y) = (-24.7111, -3.93592) +467: (x,y) = (-22.8701, -4.71739) +468: (x,y) = (-21.088, -3.8094) +469: (x,y) = (-22.027, -5.5753) +470: (x,y) = (-21.1818, -3.76268) +471: (x,y) = (-21.931, -1.90832) +472: (x,y) = (-23.3696, -3.29763) +473: (x,y) = (-25.2107, -2.51617) +474: (x,y) = (-23.2216, -2.72523) +475: (x,y) = (-21.424, -3.60197) +476: (x,y) = (-19.5114, -3.01723) +477: (x,y) = (-20.797, -1.48514) +478: (x,y) = (-21.3817, 0.427472) +479: (x,y) = (-23.379, 0.3228) +480: (x,y) = (-23.4488, 2.32158) +481: (x,y) = (-25.0248, 3.5529) +482: (x,y) = (-23.1227, 4.17094) +483: (x,y) = (-23.2274, 2.17368) +484: (x,y) = (-22.5106, 4.04084) +485: (x,y) = (-22.5804, 2.04206) +486: (x,y) = (-24.5801, 2.07696) +487: (x,y) = (-26.4345, 2.82618) +488: (x,y) = (-26.6088, 0.833787) +489: (x,y) = (-24.6164, 1.0081) +490: (x,y) = (-23.6468, 2.75734) +491: (x,y) = (-25.3789, 1.75734) +492: (x,y) = (-24.6296, -0.0970295) +493: (x,y) = (-23.9785, -1.98807) +494: (x,y) = (-25.9736, -1.84855) +495: (x,y) = (-26.8816, -3.63057) +496: (x,y) = (-26.8118, -5.62935) +497: (x,y) = (-25.0459, -4.69041) +498: (x,y) = (-23.1665, -5.37445) +499: (x,y) = (-21.2994, -6.09118) +500: (x,y) = (-22.9174, -4.91561) +501: (x,y) = (-24.9174, -4.91561) +502: (x,y) = (-26.9171, -4.88071) +503: (x,y) = (-28.8734, -4.46488) +504: (x,y) = (-29.9918, -2.80681) +505: (x,y) = (-28.6025, -4.24549) +506: (x,y) = (-28.1866, -6.20178) +507: (x,y) = (-29.901, -7.23186) +508: (x,y) = (-28.4868, -5.81764) +509: (x,y) = (-26.5742, -6.40239) +510: (x,y) = (-27.2253, -8.29343) +511: (x,y) = (-26.5413, -10.1728) +512: (x,y) = (-25.3376, -11.7701) +513: (x,y) = (-23.4058, -12.2877) +514: (x,y) = (-24.6644, -13.842) +515: (x,y) = (-23.1101, -15.1007) +516: (x,y) = (-21.4921, -16.2762) +517: (x,y) = (-20.6468, -18.0888) +518: (x,y) = (-19.0708, -19.3202) +519: (x,y) = (-18.3216, -21.1745) +520: (x,y) = (-19.3216, -19.4425) +521: (x,y) = (-21.1036, -18.5345) +522: (x,y) = (-21.5875, -16.5939) +523: (x,y) = (-22.8188, -15.0179) +524: (x,y) = (-24.4961, -13.9286) +525: (x,y) = (-24.809, -11.9532) +526: (x,y) = (-24.4961, -13.9286) +527: (x,y) = (-25.1473, -15.8196) +528: (x,y) = (-23.8886, -14.2654) +529: (x,y) = (-25.4207, -12.9798) +530: (x,y) = (-25.2117, -14.9688) +531: (x,y) = (-25.9609, -16.8232) +532: (x,y) = (-24.1789, -15.9152) +533: (x,y) = (-23.5941, -14.0026) +534: (x,y) = (-24.1454, -12.0801) +535: (x,y) = (-22.636, -13.3922) +536: (x,y) = (-23.0859, -11.4435) +537: (x,y) = (-21.0862, -11.4784) +538: (x,y) = (-23.0813, -11.6179) +539: (x,y) = (-23.186, -9.62061) +540: (x,y) = (-22.278, -11.4026) +541: (x,y) = (-21.1024, -13.0207) +542: (x,y) = (-21.484, -14.9839) +543: (x,y) = (-22.484, -16.716) +544: (x,y) = (-24.1801, -17.7758) +545: (x,y) = (-25.6429, -19.1398) +546: (x,y) = (-27.5654, -18.5885) +547: (x,y) = (-26.5055, -20.2846) +548: (x,y) = (-26.2272, -22.2652) +549: (x,y) = (-26.1225, -24.2624) +550: (x,y) = (-27.0305, -26.0444) +551: (x,y) = (-25.6665, -24.5817) +552: (x,y) = (-24.2523, -25.9959) +553: (x,y) = (-25.4279, -27.614) +554: (x,y) = (-23.5485, -28.298) +555: (x,y) = (-23.7922, -30.2831) +556: (x,y) = (-24.3098, -32.215) +557: (x,y) = (-23.9282, -30.2517) +558: (x,y) = (-22.1156, -29.4065) +559: (x,y) = (-24.1129, -29.3018) +560: (x,y) = (-22.347, -30.2407) +561: (x,y) = (-24.336, -30.4498) +562: (x,y) = (-25.7747, -31.8391) +563: (x,y) = (-26.2585, -29.8985) +564: (x,y) = (-27.3184, -31.5946) +565: (x,y) = (-25.3293, -31.8037) +566: (x,y) = (-25.6077, -33.7842) +567: (x,y) = (-24.7625, -35.5968) +568: (x,y) = (-24.7974, -33.5971) +569: (x,y) = (-23.2001, -32.3935) +570: (x,y) = (-21.5821, -31.2179) +571: (x,y) = (-19.964, -32.3935) +572: (x,y) = (-17.9886, -32.7064) +573: (x,y) = (-19.0187, -30.992) +574: (x,y) = (-18.7404, -29.0115) +575: (x,y) = (-17.8636, -27.2139) +576: (x,y) = (-15.894, -27.5612) +577: (x,y) = (-17.512, -28.7368) +578: (x,y) = (-19.5044, -28.9111) +579: (x,y) = (-18.9868, -26.9792) +580: (x,y) = (-20.134, -28.6175) +581: (x,y) = (-21.0729, -30.3834) +582: (x,y) = (-20.8986, -28.391) +583: (x,y) = (-18.9013, -28.4957) +584: (x,y) = (-19.6828, -26.6547) +585: (x,y) = (-21.1455, -28.0187) +586: (x,y) = (-19.1482, -27.914) +587: (x,y) = (-19.6321, -29.8546) +588: (x,y) = (-21.0708, -28.4653) +589: (x,y) = (-22.2179, -26.827) +590: (x,y) = (-20.3158, -27.445) +591: (x,y) = (-18.4364, -28.1291) +592: (x,y) = (-17.1778, -26.5748) +593: (x,y) = (-16.1179, -28.2709) +594: (x,y) = (-14.1179, -28.2709) +595: (x,y) = (-12.3687, -29.2405) +596: (x,y) = (-13.3383, -27.4913) +597: (x,y) = (-12.0527, -29.0233) +598: (x,y) = (-13.8186, -28.0844) +599: (x,y) = (-13.437, -26.1211) +600: (x,y) = (-13.5765, -24.126) +601: (x,y) = (-12.5765, -25.8581) +602: (x,y) = (-14.4437, -25.1413) +603: (x,y) = (-16.0617, -26.3169) +604: (x,y) = (-14.3125, -25.3473) +605: (x,y) = (-16.2035, -25.9984) +606: (x,y) = (-17.8216, -27.174) +607: (x,y) = (-15.8228, -27.1042) +608: (x,y) = (-16.2044, -29.0674) +609: (x,y) = (-18.2041, -29.0325) +610: (x,y) = (-16.6947, -30.3447) +611: (x,y) = (-17.2459, -32.2672) +612: (x,y) = (-16.4645, -30.4262) +613: (x,y) = (-18.3055, -31.2076) +614: (x,y) = (-19.9235, -30.0321) +615: (x,y) = (-21.6894, -30.971) +616: (x,y) = (-20.9727, -32.8382) +617: (x,y) = (-22.1763, -34.4354) +618: (x,y) = (-23.7084, -33.1499) +619: (x,y) = (-25.6105, -32.5318) +620: (x,y) = (-24.797, -34.3589) +621: (x,y) = (-24.3132, -32.4183) +622: (x,y) = (-26.2042, -33.0695) +623: (x,y) = (-28.1675, -33.4511) +624: (x,y) = (-27.5164, -31.56) +625: (x,y) = (-25.8583, -30.4417) +626: (x,y) = (-27.4126, -29.183) +627: (x,y) = (-26.5046, -30.965) +628: (x,y) = (-24.8085, -29.9052) +629: (x,y) = (-24.8085, -31.9052) +630: (x,y) = (-26.7572, -31.4553) +631: (x,y) = (-28.7205, -31.8369) +632: (x,y) = (-30.1347, -33.2511) +633: (x,y) = (-28.672, -31.8871) +634: (x,y) = (-30.29, -30.7116) +635: (x,y) = (-32.2824, -30.8859) +636: (x,y) = (-34.1095, -30.0724) +637: (x,y) = (-36.0791, -29.7251) +638: (x,y) = (-37.1684, -31.4024) +639: (x,y) = (-39.0228, -30.6532) +640: (x,y) = (-38.9181, -32.6505) +After 640 steps, the subject has the following location: +(x,y) = (-38.9181, -32.6505) + or +(m,a) = (50.8003, -140.005) +Average outward distance per step = 0.0793755 diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/vector.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/vector.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..f2686d190d0672fbf1329b1abdfa98741ab8fa71 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/vector.cpp" @@ -0,0 +1,180 @@ +// vect.cpp -- methods for the Vector class +#include +#include "vector.h" // includes +using std::sqrt; +using std::sin; +using std::cos; +using std::atan; +using std::atan2; +using std::cout; + +namespace VECTOR +{ + // compute degrees in one radian + const double Rad_to_deg = 45.0 / atan(1.0); // should be about 57.2957795130823 + + // private methods + // calculates magnitude from x and y + //void Vector::set_mag() + //{ + // mag = sqrt(x * x + y * y); + //} + + //void Vector::set_ang() + //{ + // if (x == 0.0 && y == 0.0) + // ang = 0.0; + // else + // ang = atan2(y, x); + //} + + // set x from polar coordinate + void Vector::set_x() + { + x = magval() * cos(angval()); + } + + // set y from polar coordinate + void Vector::set_y() + { + y = magval() * sin(angval()); + } + + // public methods + Vector::Vector() // default constructor + { + x = y = 0.0; + mode = RECT; + } + + // construct vector from rectangular coordinates if form is RECT (the default) + // or else from polar coordinates if form is POL + Vector::Vector(double n1, double n2, Mode form) + { + mode = form; + if (form == RECT) + { + x = n1; + y = n2; + //set_mag(); + //set_ang(); + } + else if (form == POL) + { + double mag = n1; + double ang = n2 / Rad_to_deg; + x = mag * cos(ang); + y = mag * sin(ang); + } + else + { + cout << "Incorrect 3rd argument to Vector() -- "; + cout << "vector set to 0\n"; + x = y = 0.0; + mode = RECT; + } + } + + // reset vector from rectangular coordinates if form is RECT (the default) + // or else from polar coordinates if form is POL + void Vector::reset(double n1, double n2, Mode form) + { + mode = form; + if (form == RECT) + { + x = n1; + y = n2; + //set_mag(); + //set_ang(); + } + else if (form == POL) + { + double mag = n1; + double ang = n2 / Rad_to_deg; + x = mag * cos(ang); + y = mag * sin(ang); + } + else + { + cout << "Incorrect 3rd argument to Vector() -- "; + cout << "vector set to 0\n"; + x = y = 0.0; + mode = RECT; + } + } + + Vector::~Vector() // destructor + { + } + + void Vector::polar_mode() // set to polar mode + { + mode = POL; + } + + void Vector::rect_mode() // set to rectangular mode + { + mode = RECT; + } + + double Vector::magval() const // calculate magnitude + { + return sqrt(x * x + y * y); + } + + double Vector::angval() const // calculate angle + { + if (x == 0.0 && y == 0.0) + return 0.0; + else + return atan2(y, x) * Rad_to_deg; + } + + // operator overloading + // add two Vectors + Vector Vector::operator+(const Vector& b) const + { + return Vector(x + b.x, y + b.y); + } + + // subtract Vector b from a + Vector Vector::operator-(const Vector& b) const + { + return Vector(x - b.x, y - b.y); + } + + // reverse sign of Vector + Vector Vector::operator-() const + { + return Vector(-x, -y); + } + + // multiply vector by n + Vector Vector::operator*(double n) const + { + return Vector(n * x, n * y); + } + + // friend methods + // multiply n by Vector a + Vector operator*(double n, const Vector& a) + { + return a * n; + } + + // display rectangular coordinates if mode is RECT, + // else display polar coordinates if mode is POL + std::ostream& operator<<(std::ostream& os, const Vector& v) + { + if (v.mode == Vector::RECT) + os << "(x,y) = (" << v.x << ", " << v.y << ")"; + else if (v.mode == Vector::POL) + { + os << "(m,a) = (" << v.magval() << ", " << v.angval() << ")"; + } + else + os << "Vector object mode is invalid"; + return os; + } + +} // end namespace VECTOR diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/vector.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/vector.h" new file mode 100644 index 0000000000000000000000000000000000000000..79d834f40843df850604da1ea90b29f1f9e3ae09 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_2/vector.h" @@ -0,0 +1,47 @@ +// vect.h -- Vector class with <<, mode-state +#ifndef VECTOR_H_ +#define VECTOR_H_ +#include +namespace VECTOR +{ + class Vector + { + public: + enum Mode { RECT, POL }; // RECT for rectangular, POL for Polar modes + private: + double x; // horizontal value + double y; // vertical value + //double mag; // length of vector + //double ang; // direction of vector in degrees + Mode mode; // RECT or POL + + // private methods for setting values + //void set_mag(); + //void set_ang(); + void set_x(); + void set_y(); + public: + Vector(); + Vector(double n1, double n2, Mode form = RECT); + void reset(double n1, double n2, Mode form = RECT); + ~Vector(); + double xval() const { return x; } // report x value + double yval() const { return y; } // report y value + double magval() const; // report magnitude + double angval() const; // report angle + void polar_mode(); // set mode to POL + void rect_mode(); // set mode to RECT + + // operator overloading + Vector operator+(const Vector& b) const; + Vector operator-(const Vector& b) const; + Vector operator-() const; + Vector operator*(double n) const; + + // friends + friend Vector operator*(double n, const Vector& a); + friend std::ostream& operator<<(std::ostream& os, const Vector& v); + }; +} // end namespace VECTOR + +#endif diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/randwalk.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/randwalk.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..60e9ed454b1d1f49ce969affe41c35b80f890143 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/randwalk.cpp" @@ -0,0 +1,69 @@ +// randwalk.cpp -- using the Vector class +// compile with the vect.cpp file +#include +#include // rand(), srand() prototypes +#include // time() prototype +#include "vector.h" + + +int main() +{ + using namespace std; + using VECTOR::Vector; + srand(time(0)); // seed random-number generator + double direction; + Vector step; + Vector result(0.0, 0.0); + unsigned long steps = 0; + unsigned long maxsteps = 0; + unsigned long minsteps = 4294967295; + unsigned long totalsteps = 0; + double averagesteps = 0.0; + double target; + + int n, cnt; + cout << "请输入测试的次数:"; + cin >> n; + cnt = n; + double dstep; + cout << "Enter target distance: "; + cin >> target; + cout << "Enter step length: "; + cin >> dstep; + + while (n--) + { + while (result.magval() < target) + { + direction = rand() % 360; + step.reset(dstep, direction, Vector::POL); + result = result + step; + steps++; + } + + /*cout << "After " << steps << " steps, the subject " + << "has the following location:\n"; + cout << result << endl; + + result.polar_mode(); + cout << " or\n" << result << endl; + cout << "Average outward distance per step = " + << result.magval() / steps << endl;*/ + + if (steps > maxsteps) { + maxsteps = steps; + } + if (steps < minsteps) { + minsteps = steps; + } + totalsteps += steps; + + steps = 0; + result.reset(0.0, 0.0); + } + averagesteps = totalsteps / cnt; + cout << "最高步数:" << maxsteps << endl; + cout << "最低步数:" << minsteps << endl; + cout << "平均步数:" << averagesteps << endl; + return 0; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/vector.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/vector.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..bd8493dd21a99cd067475fd757a82568ed49c8e3 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/vector.cpp" @@ -0,0 +1,167 @@ +// vect.cpp -- methods for the Vector class +#include +#include "vector.h" // includes +using std::sqrt; +using std::sin; +using std::cos; +using std::atan; +using std::atan2; +using std::cout; + +namespace VECTOR +{ + // compute degrees in one radian + const double Rad_to_deg = 45.0 / atan(1.0); // should be about 57.2957795130823 + + // private methods + // calculates magnitude from x and y + void Vector::set_mag() + { + mag = sqrt(x * x + y * y); + } + + void Vector::set_ang() + { + if (x == 0.0 && y == 0.0) + ang = 0.0; + else + ang = atan2(y, x); + } + + // set x from polar coordinate + void Vector::set_x() + { + x = mag * cos(ang); + } + + // set y from polar coordinate + void Vector::set_y() + { + y = mag * sin(ang); + } + + // public methods + Vector::Vector() // default constructor + { + x = y = mag = ang = 0.0; + mode = RECT; + } + + // construct vector from rectangular coordinates if form is RECT (the default) + // or else from polar coordinates if form is POL + Vector::Vector(double n1, double n2, Mode form) + { + mode = form; + if (form == RECT) + { + x = n1; + y = n2; + set_mag(); + set_ang(); + } + else if (form == POL) + { + mag = n1; + ang = n2 / Rad_to_deg; + set_x(); + set_y(); + } + else + { + cout << "Incorrect 3rd argument to Vector() -- "; + cout << "vector set to 0\n"; + x = y = mag = ang = 0.0; + mode = RECT; + } + } + + // reset vector from rectangular coordinates if form is RECT (the default) + // or else from polar coordinates if form is POL + void Vector::reset(double n1, double n2, Mode form) + { + mode = form; + if (form == RECT) + { + x = n1; + y = n2; + set_mag(); + set_ang(); + } + else if (form == POL) + { + mag = n1; + ang = n2 / Rad_to_deg; + set_x(); + set_y(); + } + else + { + cout << "Incorrect 3rd argument to Vector() -- "; + cout << "vector set to 0\n"; + x = y = mag = ang = 0.0; + mode = RECT; + } + } + + Vector::~Vector() // destructor + { + } + + void Vector::polar_mode() // set to polar mode + { + mode = POL; + } + + void Vector::rect_mode() // set to rectangular mode + { + mode = RECT; + } + + // operator overloading + // add two Vectors + Vector Vector::operator+(const Vector& b) const + { + return Vector(x + b.x, y + b.y); + } + + // subtract Vector b from a + Vector Vector::operator-(const Vector& b) const + { + return Vector(x - b.x, y - b.y); + } + + // reverse sign of Vector + Vector Vector::operator-() const + { + return Vector(-x, -y); + } + + // multiply vector by n + Vector Vector::operator*(double n) const + { + return Vector(n * x, n * y); + } + + // friend methods + // multiply n by Vector a + Vector operator*(double n, const Vector& a) + { + return a * n; + } + + // display rectangular coordinates if mode is RECT, + // else display polar coordinates if mode is POL + std::ostream& operator<<(std::ostream& os, const Vector& v) + { + if (v.mode == Vector::RECT) + os << "(x,y) = (" << v.x << ", " << v.y << ")"; + else if (v.mode == Vector::POL) + { + os << "(m,a) = (" << v.mag << ", " << v.ang * Rad_to_deg << ")"; + } + else + os << "Vector object mode is invalid"; + return os; + } + +} // end namespace VECTOR diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/vector.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/vector.h" new file mode 100644 index 0000000000000000000000000000000000000000..4e9c645812d5611026c04c514562631144be4c62 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_3/vector.h" @@ -0,0 +1,47 @@ +// vect.h -- Vector class with <<, mode-state +#ifndef VECTOR_H_ +#define VECTOR_H_ +#include +namespace VECTOR +{ + class Vector + { + public: + enum Mode { RECT, POL }; // RECT for rectangular, POL for Polar modes + private: + double x; // horizontal value + double y; // vertical value + double mag; // length of vector + double ang; // direction of vector in degrees + Mode mode; // RECT or POL + + // private methods for setting values + void set_mag(); + void set_ang(); + void set_x(); + void set_y(); + public: + Vector(); + Vector(double n1, double n2, Mode form = RECT); + void reset(double n1, double n2, Mode form = RECT); + ~Vector(); + double xval() const { return x; } // report x value + double yval() const { return y; } // report y value + double magval() const { return mag; } // report magnitude + double angval() const { return ang; } // report angle + void polar_mode(); // set mode to POL + void rect_mode(); // set mode to RECT + + // operator overloading + Vector operator+(const Vector& b) const; + Vector operator-(const Vector& b) const; + Vector operator-() const; + Vector operator*(double n) const; + + // friends + friend Vector operator*(double n, const Vector& a); + friend std::ostream& operator<<(std::ostream& os, const Vector& v); + }; +} // end namespace VECTOR + +#endif diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/mytime.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/mytime.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..2332b4f2ad40002307e4e410c2f16b4e30e8c598 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/mytime.cpp" @@ -0,0 +1,85 @@ +#include "mytime.h" + +Time::Time() +{ + hours = minutes = 0; +} + +Time::Time(int h, int m) +{ + hours = h; + minutes = m; +} + +void Time::AddMin(int m) +{ + minutes += m; + hours += minutes / 60; + minutes %= 60; +} + +void Time::AddHr(int h) +{ + hours += h; +} + +void Time::Reset(int h, int m) +{ + hours = h; + minutes = m; +} + +//Time Time::operator+(const Time& t) const +//{ +// Time sum; +// sum.minutes = minutes + t.minutes; +// sum.hours = hours + t.hours + sum.minutes / 60; +// sum.minutes %= 60; +// return sum; +//} +// +//Time Time::operator-(const Time& t) const +//{ +// Time diff; +// int tot1, tot2; +// tot1 = t.minutes + 60 * t.hours; +// tot2 = minutes + 60 * hours; +// diff.minutes = (tot2 - tot1) % 60; +// diff.hours = (tot2 - tot1) / 60; +// return diff; +//} + +Time Time::operator*(double mult) const +{ + Time result; + long totalminutes = hours * mult * 60 + minutes * mult; + result.hours = totalminutes / 60; + result.minutes = totalminutes % 60; + return result; +} + +Time operator+(const Time& t1, const Time& t2) +{ + Time result; + result.minutes = t1.minutes + t2.minutes; + result.hours = t1.hours + t2.hours + result.minutes / 60; + result.minutes %= 60; + return result; +} + +Time operator-(const Time& t1, const Time& t2) +{ + Time result; + int tot1, tot2; + tot1 = t1.hours * 60 + t1.minutes; + tot2 = t2.hours * 60 + t2.minutes; + result.hours = (tot1 - tot2) / 60; + result.minutes = (tot1 - tot2) % 60; + return result; +} + +std::ostream& operator<<(std::ostream& os, const Time& t) +{ + os << t.hours << " hours, " << t.minutes << " minutes"; + return os; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/mytime.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/mytime.h" new file mode 100644 index 0000000000000000000000000000000000000000..a5096696a9bce6eaec118207de526123bb63dcac --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/mytime.h" @@ -0,0 +1,29 @@ +#ifndef MYTIME3_H_ +#define MYTIME3_H_ +#include + +class Time +{ +private: + int hours; + int minutes; +public: + Time(); + Time(int h, int m = 0); + void AddMin(int m); + void AddHr(int h); + void Reset(int h = 0, int m = 0); + //Time operator+(const Time& t) const; + //Time operator-(const Time& t) const; + friend Time operator+(const Time& t1, const Time& t2); + friend Time operator-(const Time& t1, const Time& t2); + + Time operator*(double n) const; + friend Time operator*(double m, const Time& t) + { + return t * m; + } // inline definition + friend std::ostream& operator<<(std::ostream& os, const Time& t); +}; + +#endif diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/usetime.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/usetime.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..02ab6ad2fe5639c55ea05b02ee72304bf98d9d4b --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_4/usetime.cpp" @@ -0,0 +1,23 @@ +#include +#include "mytime.h" + +int main() +{ + using std::cout; + using std::endl; + Time aida(3, 35); + Time tosca(2, 48); + Time temp; + + cout << "Aida and Tosca:\n"; + cout << aida << "; " << tosca << endl; + temp = aida + tosca; // operator+() + cout << "Aida + Tosca: " << temp << endl; + temp = aida - tosca; // operator-() + cout << "Aida - Tosca: " << temp << endl; + temp = aida * 1.17; // member operator*() + cout << "Aida * 1.17: " << temp << endl; + cout << "10.0 * Tosca: " << 10.0 * tosca << endl; + + return 0; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stone.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stone.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..306815bdbac0a734765235a2ead8c615709a3c0a --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stone.cpp" @@ -0,0 +1,58 @@ +#include +#include "stonewt.h" + +void display(const Stonewt& st, int n); + +int main() +{ + using namespace std; + + Stonewt incognito = 275; // uses constructor to initialize + Stonewt wolfe(285.7); // same as Stonewt wolfe = 285.7; + Stonewt taft(21, 8); + + incognito.setMode(Stonewt::INT_POUNDS); + wolfe.setMode(Stonewt::FLOAT_POUNDS); + taft.setMode(Stonewt::STONE); + + Stonewt test1 = taft * 10; + Stonewt test2 = incognito + wolfe; + Stonewt test3 = taft - incognito; + + test1.setMode(Stonewt::STONE); + test2.setMode(Stonewt::FLOAT_POUNDS); + test3.setMode(Stonewt::INT_POUNDS); + + cout << "The celebrity weighed "; + cout << incognito << endl; + cout << "The detective weighed "; + cout << wolfe << endl; + cout << "The President weighed "; + cout << taft << endl; + + cout << "test1: taft * 10 = " << test1 << endl; + cout << "test2: incognito + wolfe = " << test2 << endl; + cout << "test3: taft - incognito = " << test3 << endl; + + incognito = 276.8; // uses constructor for conversion + taft = 325; // same as taft = Stonewt(325); + cout << "After dinner, the celebrity weighed "; + cout << incognito << endl; + cout << "After dinner, the President weighed "; + cout << taft << endl; + display(taft, 2); + cout << "The wrestler weighed even more.\n"; + display(422, 2); + cout << "No stone left unearned\n"; + return 0; +} + +void display(const Stonewt& st, int n) +{ + using namespace std; + for (int i = 0; i < n; i++) + { + cout << "Wow! "; + cout << st << endl; + } +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stonewt.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stonewt.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..d7fe7a225124f2f46f1e03148852e0a9a036bf3d --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stonewt.cpp" @@ -0,0 +1,91 @@ +// stonewt.cpp -- Stonewt methods +#include +using std::cout; +#include "stonewt.h" + +// construct Stonewt object from double value +Stonewt::Stonewt(double lbs, Mode form) +{ + stone = int(lbs) / Lbs_per_stn; // integer division + pds_left = int(lbs) % Lbs_per_stn + lbs - int(lbs); + pounds = lbs; + mode = form; +} + +// construct Stonewt object from stone, double values +Stonewt::Stonewt(int stn, double lbs, Mode form) +{ + stone = stn; + pds_left = lbs; + pounds = stn * Lbs_per_stn + lbs; + mode = form; +} + +Stonewt::Stonewt() // default constructor, wt = 0 +{ + stone = pounds = pds_left = 0; + mode = FLOAT_POUNDS; +} + +Stonewt::~Stonewt() // destructor +{ +} + +//// show weight in stones +//void Stonewt::show_stn() const +//{ +// cout << stone << " stone, " << pds_left << " pounds\n"; +//} +// +//// show weight in pounds +//void Stonewt::show_lbs() const +//{ +// cout << pounds << " pounds\n"; +//} + +void Stonewt::setMode(Mode form) +{ + mode = form; +} + +Stonewt operator+(const Stonewt& s1, const Stonewt& s2) +{ + Stonewt result; + result.pounds = s1.pounds + s2.pounds; + result.stone = int(result.pounds) / Lbs_per_stn; + result.pds_left = int(result.pounds) % Lbs_per_stn + result.pounds - int(result.pounds); + + return result; +} + +Stonewt operator-(const Stonewt& s1, const Stonewt& s2) +{ + Stonewt result; + result.pounds = s1.pounds - s2.pounds; + result.stone = int(result.pounds) / Lbs_per_stn; + result.pds_left = int(result.pounds) % Lbs_per_stn + result.pounds - int(result.pounds); + return result; +} + +Stonewt operator*(const Stonewt& s1, int m) +{ + Stonewt result; + result.pounds = s1.pounds * m; + result.stone = int(result.pounds) / Lbs_per_stn; + result.pds_left = int(result.pounds) % Lbs_per_stn + result.pounds - int(result.pounds); + return result; +} + +std::ostream& operator<<(std::ostream& os, const Stonewt& s) +{ + if (s.mode == Stonewt::STONE) { + os << s.stone << " stone, " << s.pds_left << " pounds\n"; + } + else if (s.mode == Stonewt::INT_POUNDS) { + os << int(s.pounds) << " pounds\n"; + } + else { + os << s.pounds << " pounds\n"; + } + return os; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stonewt.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stonewt.h" new file mode 100644 index 0000000000000000000000000000000000000000..2ad1677e1a21a3e2a6d41c986a19d6bcd4804fed --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter11/11_5/stonewt.h" @@ -0,0 +1,34 @@ +// stonewt.h -- definition for the Stonewt class +#ifndef STONEWT_H +#define STONEWT_H + +const int Lbs_per_stn = 14; + +class Stonewt +{ +public: + enum Mode { STONE, INT_POUNDS, FLOAT_POUNDS }; + +private: + //enum { Lbs_per_stn = 14 }; // pounds per stone + int stone; // whole stones + double pds_left; // fractional pounds + double pounds; // entire weight in pounds + Mode mode; + +public: + Stonewt(double lbs, Mode form = FLOAT_POUNDS); // constructor for double pounds + Stonewt(int stn, double lbs, Mode form = STONE); // constructor for stone, lbs + Stonewt(); // default constructor + ~Stonewt(); + void show_lbs() const; // show weight in pounds format + void show_stn() const; // show weight in stone format + void setMode(Mode form); + friend Stonewt operator+(const Stonewt& s1, const Stonewt& s2); + friend Stonewt operator-(const Stonewt& s1, const Stonewt& s2); + friend Stonewt operator*(const Stonewt& s1, int m); + friend std::ostream& operator<<(std::ostream& os, const Stonewt& s); + +}; + +#endif diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/CD.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/CD.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..cb557519bce723aadc34e1a38c769b77153f5eb6 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/CD.cpp" @@ -0,0 +1,109 @@ +#include "CD.h" +#include +#include + +Cd::Cd(const char* s1, const char* s2, int n, double x) +{ + int len1 = strlen(s1); + int len2 = strlen(s2); + + performers = new char[len1 + 1]; + label = new char[len2 + 1]; + strcpy_s(performers, len1 + 1, s1); + strcpy_s(label, len2 + 1, s2); + performers[len1] = '\0'; + label[len2] = '\0'; + + selections = n; + playtime = x; +} + +Cd::Cd(const Cd& d) +{ + int len1 = strlen(d.performers); + int len2 = strlen(d.label); + + performers = new char[len1 + 1]; + label = new char[len2 + 1]; + strcpy_s(performers, len1 + 1, d.performers); + strcpy_s(label, len2 + 1, d.label); + performers[len1] = '\0'; + label[len2] = '\0'; + + selections = d.selections; + playtime = d.playtime; +} + +Cd::~Cd() +{ + delete[] performers; + delete[] label; +} + + +void Cd::Report() const +{ + using namespace std; + cout << "performers: " << performers << endl; + cout << "label: " << label << endl; + cout << "selections: " << selections << endl; + cout << "playtime: " << playtime << endl; +} + +Cd& Cd::operator=(const Cd& d) +{ + if (this == &d) { + return *this; + } + delete[] performers; + delete[] label; + + int len1 = strlen(d.performers); + int len2 = strlen(d.label); + + performers = new char[len1 + 1]; + label = new char[len2 + 1]; + strcpy_s(performers, len1 + 1, d.performers); + strcpy_s(label, len2 + 1, d.label); + performers[len1] = '\0'; + label[len2] = '\0'; + + selections = d.selections; + playtime = d.playtime; + return *this; +} + +Classic::Classic(const char* s, const char* s1, const char* s2, int n, double x) :Cd(s1, s2, n, x) +{ + int len = strlen(s); + song = new char[len + 1]; + strcpy_s(song, len + 1, s); + song[len] = '\0'; +} + +Classic::~Classic() +{ + delete[] song; +} + +void Classic::Report() const +{ + using namespace std; + Cd::Report(); + cout << "song: " << song << endl; +} + +Classic& Classic::operator=(const Classic& c) +{ + if (this == &c) { + return *this; + } + Cd::operator=(c); + delete[] song; + int len = strlen(c.song); + song = new char[len + 1]; + strcpy_s(song, len + 1, c.song); + song[len] = '\0'; + + return *this; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/CD.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/CD.h" new file mode 100644 index 0000000000000000000000000000000000000000..8a38d28cb314fdc912b6ea58eda1db6e784395e0 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/CD.h" @@ -0,0 +1,25 @@ +class Cd +{ +private: + char* performers; + char* label; + int selections; + double playtime; +public: + Cd(const char* s1 = "no performers", const char* s2 = "no label", int n = 0, double x = 0.0); + Cd(const Cd& d); + virtual ~Cd(); + virtual void Report() const; + Cd& operator=(const Cd& d); +}; + +class Classic : public Cd +{ +private: + char* song; +public: + Classic(const char* s = "no song", const char* s1 = "no performers", const char* s2 = "no label", int n = 0, double x = 0.0); + ~Classic(); + virtual void Report() const; + Classic& operator=(const Classic& c); +}; \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..441ff2550ef6bfcc227e36f2863d915f13edc414 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter13/13_2/main.cpp" @@ -0,0 +1,41 @@ +#include +using namespace std; +#include "CD.h" +void Bravo(const Cd& disk); +int main() +{ + Cd c1("Beatles", "Capitol", 14, 35.5); + Classic c2 = Classic("Piano Sonata in B-flat, Fantasia in C", + "Alfred Brendel", "Philips", 2, 57.17); + Cd* pcd = &c1; + + cout << "Using object directly:\n"; + c1.Report();// use Cd method + cout << endl; + c2.Report(); // use Classic method + cout << endl; + + cout << "Using type cd * pointer to objects:\n"; + pcd->Report(); // use Cd method for cd object + cout << endl; + pcd = &c2; + pcd->Report(); // use Classic method for classic object + cout << endl; + + cout << "Calling a function with a Cd reference argument:\n"; + Bravo(c1); + Bravo(c2); + + cout << "Testing assignment: "; + Classic copy; + copy = c2; + copy.Report(); + + return 0; +} + +void Bravo(const Cd& disk) +{ + disk.Report(); + cout << endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_1.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_1.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..1b1c9ab96edd835fa33a297ebef39f8ecf8ccd30 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_1.cpp" @@ -0,0 +1,16 @@ +#include + +void printString(const char* str, int n = 0); //第二个参数是默认参数 + +int main() { + const char* mystring = "Hello World"; + printString(mystring); + printString(mystring, 3); + + return 0; +} + +//默认参数的值只能在声明中指定 +void printString(const char* str, int n) { + std::cout << str << std::endl; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_2.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_2.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..59591a99e1bac6806c5b665baceb4d76f0a074e6 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_2.cpp" @@ -0,0 +1,31 @@ +#include + +struct CandyBar { + char _name[40]; + double _weight; + int _heat; +}; + +void setCandy(CandyBar& c, const char name[] = "Millennium Munch", double weight = 2.85, int heat = 350); +void showCandy(const CandyBar& c); + +int main() { + CandyBar candy1, candy2; + setCandy(candy1); + setCandy(candy2, "Chocolate", 3.85, 800); + showCandy(candy1); + showCandy(candy2); + return 0; +} + +void setCandy(CandyBar& c, const char name[], double weight, int heat) { + strcpy_s(c._name, name); + c._heat = heat; + c._weight = weight; +} + +void showCandy(const CandyBar& c) { + std::cout << "Candy name: " << c._name << "\n"; + std::cout << "Candy weight: " << c._weight << "\n"; + std::cout << "Candy heat: " << c._heat << "\n"; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_3.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_3.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..4c8e565485df9b16ff58ab95aaad6e77678fd5cc --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_3.cpp" @@ -0,0 +1,29 @@ +#include +#include +#include + +void transformString(std::string& s); + + +int main() { + using namespace std; + string str; + while (1) { + cout << "Enter a string (q to quit): "; + getline(cin, str); + if (str == "q") { + break; + } + transformString(str); + cout << str << endl; + } + + return 0; +} + +void transformString(std::string& s) { + int len = s.length(); + for (int i = 0; i < len; i++) { + s[i] = toupper(s[i]); + } +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_4.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_4.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..eb7aef17112a395745ec7f41d20e368f72d4ddc1 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_4.cpp" @@ -0,0 +1,50 @@ +#include +#include // for strlen(), strcpy() + +struct stringy { + char* _str; // points to a string + int _ct; // length of string (not counting '\0') +}; + +// prototypes for set(), show(), and show() go here +void set(stringy& b, const char* t); +void show(const stringy& b, int n = 1); +void show(const char t[], int n = 1); + +int main() { + stringy beany; + char testing[] = "Reality isn't what it used to be."; + + set(beany, testing); // first argument is a reference, + // allocates space to hold copy of testing, + // sets str member of beany to point to the + // new block, copies testing to new block, + // and sets ct member of beany + show(beany); // prints member string once + show(beany, 2); // prints member string twice + testing[0] = 'D'; + testing[1] = 'u'; + show(testing); // prints testing string once + show(testing, 3); // prints testing string thrice + show("Done!"); + return 0; +} + +void set(stringy& b, const char* test) { + b._ct = strlen(test); + b._str = new char[b._ct + 1]; + strcpy_s(b._str, b._ct + 1, test); +} + +void show(const stringy& b, int n) { + for (int i = 0; i < n; i++) { + std::cout << b._str << std::endl; + } +} + +void show(const char t[], int n) { + for (int i = 0; i < n; i++) { + std::cout << t << std::endl; + } +} + diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_5.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_5.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..36a5876487548595e44b60b5c528d419ab61e136 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_5.cpp" @@ -0,0 +1,23 @@ +#include + +//模板函数 +template T getMaxnumber(T a[]); + +int main() { + int arr1[5] = { 1,2,3,4,5 }; + double arr2[5] = { 1.2,4.2,0.3,5.6,2.3 }; + std::cout << "第一个数组中最大的数为:" << getMaxnumber(arr1) << "\n"; + std::cout << "第二个数组中最大的数为:" << getMaxnumber(arr2) << "\n"; + + return 0; +} + +template T getMaxnumber(T a[]) { + T maxNumber = a[0]; + for (int i = 1; i < 5; i++) { + if (a[i] > maxNumber) { + maxNumber = a[i]; + } + } + return maxNumber; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_6.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_6.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..1ac1ee5de006cdd32af5e56392f0ce16a3770788 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_6.cpp" @@ -0,0 +1,41 @@ +#include +#include + +//模板函数,返回数组中最大的数 +template +T maxn(T a[], int n) { + T maxNum = a[0]; + for (int i = 0; i < n; i++) { + if (a[i] > maxNum) { + maxNum = a[i]; + } + } + return maxNum; +} + +//模板具体化函数,返回最长字符串的地址 +template<> +const char* maxn(const char* a[], int n) { + const char* longest = a[0]; + for (int i = 1; i < n; i++) { + if (strlen(longest) < strlen(a[i])) { + longest = a[i]; + } + } + return longest; +} + + +int main() +{ + int arr1[4] = { 3, 10, 4, 9 }; + double arr2[6] = { 0.1,0.2,0.3,0.4,0.5,0.6 }; + const char* arr3[] = { "Hello","World","C++","Programming" }; + std::cout << "第一个数组最大的数是:" << maxn(arr1, 4) << "\n"; + std::cout << "第二个数组最大的数是:" << maxn(arr2, 6) << "\n"; + std::cout << "最长的字符串是:" << maxn(arr3, 4) << "\n"; + return 0; +} + + + diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_7.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_7.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..e468f0f102ce8c4036daa47155766571ca5c853c --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter8/8_7.cpp" @@ -0,0 +1,80 @@ +#include + +template // template A +void ShowArray(T arr[], int n); + +template // template B +void ShowArray(T* arr[], int n); + +template +int SumArray(T arr[], int n); + +template +double SumArray(T* arr[], int n); + +struct debts { + char name[50]; + double amount; +}; + +int main() { + using namespace std; + int things[6] = { 13, 31, 103, 301, 310, 130 }; + struct debts mr_E[3] = { + {"Ima Wolfe", 2400.0}, + {"Ura Foxe", 1300.0}, + {"Iby Stout", 1800.0} + }; + double* pd[3]; + + for (int i = 0; i < 3; i++) + pd[i] = &mr_E[i].amount; + + cout << "Listing Mr. E's counts of things:\n"; + ShowArray(things, 6); // uses template A + cout << "Listing Mr. E's total of things: " << SumArray(things, 6) << endl; + + cout << "Listing Mr. E's debts:\n"; + ShowArray(pd, 3); // uses template B (more specialized) + cout << "Listing Mr. E's total of debts: " << SumArray(pd, 3) << endl; + + return 0; +} + +template +void ShowArray(T arr[], int n) { + using namespace std; + cout << "template A\n"; + for (int i = 0; i < n; i++) + cout << arr[i] << ' '; + cout << endl; +} + +template +void ShowArray(T* arr[], int n) { + using namespace std; + cout << "template B\n"; + for (int i = 0; i < n; i++) + cout << *arr[i] << ' '; + cout << endl; +} + +template +int SumArray(T arr[], int n) { + using namespace std; + int total = 0; + for (int i = 0; i < n; i++) { + total += arr[i]; + } + return total; +} + +template +double SumArray(T* arr[], int n) { + using namespace std; + double total = 0.0; + for (int i = 0; i < n; i++) { + total += *arr[i]; + } + return total; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/golf.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/golf.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..4ae96c36415dea23ab647448b75c636e939ea6a3 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/golf.cpp" @@ -0,0 +1,38 @@ +#include "golf.h" +#include + +void setGolf(Golf& g, const char* name, int hc) +{ + strcpy_s(g._fullname, Len, name); + g._handicap = hc; +} + +int setGolf(Golf& g) +{ + using namespace std; + char fullname[Len]; + int handicap; + cout << "请输入用户的姓名:"; + cin.getline(fullname, Len); + if (fullname[0] == '\0') { + return 0; + } + + strcpy_s(g._fullname, Len, fullname); + cout << "请输入用户的等级:"; + cin >> handicap; + g._handicap = handicap; + cin.get(); + return 1; +} + +void handicap(Golf& g, int hc) +{ + g._handicap = hc; +} + +void showGolf(const Golf& g) +{ + using namespace std; + cout << "用户的姓名为:" << g._fullname << ",等级为:" << g._handicap << endl; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/golf.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/golf.h" new file mode 100644 index 0000000000000000000000000000000000000000..01c32c332dcf2d826212b7a74997edc56197a766 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/golf.h" @@ -0,0 +1,26 @@ +#pragma once +#include + + +const int Len = 40; +struct Golf { + char _fullname[Len]; + int _handicap; +}; + +// non-interactive version: +// function sets golf structure to provided name, handicap +// using values passed as arguments to the function +void setGolf(Golf& g, const char* name, int hc); + +// interactive version: +// function solicits name and handicap from user +// and sets the members of g to the values entered +// returns 1 if name is entered, 0 if name is empty string +int setGolf(Golf& g); + +// function resets handicap to new value +void handicap(Golf& g, int hc); + +// function displays contents of golf structure +void showGolf(const Golf& g); diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..d844858394588bd442a8a90fe5ed71f6d9590a51 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_1/main.cpp" @@ -0,0 +1,32 @@ +#include +#include"golf.h" + +int main() { + using namespace std; + Golf ann; + setGolf(ann, "Ann Birdfree", 24); + Golf arr[3]; + int k; + for (k = 0; k < 3; k++) { + if (setGolf(arr[k]) == 0) { + break; + } + } + cout << "以下是全部用户信息" << endl; + for (int i = 0; i < k; i++) { + showGolf(arr[i]); + } + + cout << "请选择要重设等级的用户:"; + int j, hc; + cin >> j; + cout << "请输入新等级:"; + cin >> hc; + handicap(arr[j - 1], hc); + + cout << "以下是全部用户信息" << endl; + for (int i = 0; i < k; i++) { + showGolf(arr[i]); + } + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_2.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_2.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..4783e2b0ddf0c4a9644063c8ed2ac080d1651329 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_2.cpp" @@ -0,0 +1,44 @@ +// static.cpp -- 使用静态局部变量 +#include +#include + +// 常量 +const int ArSize = 10; + +// 函数原型 +void strcount(const std::string str); + +int main() { + using namespace std; + //char input[ArSize]; + string input; + char next; + + cout << "输入一行文本:\n"; + //cin.get(input, ArSize); + getline(cin, input); + while (input != "") { + //cin.get(next); + //while (next != '\n') // 字符串不符合! + //cin.get(next); // 处理剩余部分 + strcount(input); + cout << "输入下一行(空行退出):\n"; + getline(cin, input); + } + cout << "再见\n"; + return 0; +} + +void strcount(const std::string str) { + using namespace std; + static int total = 0; // 静态局部变量 + int count = 0; // 自动局部变量 + + cout << "\"" << str << "\" 包含 "; + //while (*str++) // 移动到字符串的末尾 + //count++; + count = str.length(); + total += count; + cout << count << " 个字符\n"; + cout << "总共 " << total << " 个字符\n"; +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_3.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_3.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..aba141e1370e9527294a216f51d45164efd2f245 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_3.cpp" @@ -0,0 +1,36 @@ +#include +#include + +const int BUF = 512; +char buffer[BUF]; + +struct chaff { + char dross[20]; + int slag; +}; + + +int main() { + using namespace std; + chaff* pd1, * pd2; + pd1 = new chaff[2]; + pd2 = new (buffer) chaff[2]; + strcpy_s(pd1[0].dross, 20, "chaff1_1"); + strcpy_s(pd1[1].dross, 20, "chaff1_2"); + strcpy_s(pd2[0].dross, 20, "chaff2_1"); + strcpy_s(pd2[1].dross, 20, "chaff2_2"); + pd1[0].slag = pd2[0].slag = 10; + pd1[1].slag = pd2[1].slag = 20; + + cout << "Memory addresses:\n" << " heap: " << pd1 << " static: " << (void*)buffer << endl; + cout << "Memory contents:\n"; + for (int i = 0; i < 2; i++) { + cout << pd1[i].dross << " at " << &pd1[i].dross << "; "; + cout << pd2[i].dross << " at " << &pd2[i].dross << endl; + cout << pd1[i].slag << " at " << &pd1[i].slag << "; "; + cout << pd2[i].slag << " at " << &pd2[i].slag << endl; + + } + + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/9_4.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/9_4.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..1d145783d836a7d082f7736cf99cecb9e144f907 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/9_4.cpp" @@ -0,0 +1,63 @@ +#include +#include"9_4.h" +namespace SALES { + void setSales(Sales& s, const double ar[], int n) + { + int i = 0; + double max = 0, min = ar[0], avg = 0, total = 0; + for (i = 0; i < n; i++) { + s.sales[i] = ar[i]; + if (ar[i] > max) { + max = ar[i]; + } + if (ar[i] < min) { + min = ar[i]; + } + total += ar[i]; + } + s.average = total / n; + s.max = max; + s.min = min; + if (i < 4) { + for (int j = i; j < 4; j++) { + s.sales[j] = 0; + } + } + } + + void setSales(Sales& s) { + using namespace std; + double max, min, total; + cout << "请分别输入四个季度的销售额:"; + for (int i = 0; i < 4; i++) { + cin >> s.sales[i]; + } + max = min = total = s.sales[0]; + for (int i = 1; i < 4; i++) { + if (s.sales[i] > max) { + max = s.sales[i]; + } + if (s.sales[i] < min) { + min = s.sales[i]; + } + total += s.sales[i]; + } + s.average = total / 4; + s.max = max; + s.min = min; + } + + void showSales(const Sales& s) { + using namespace std; + cout << "四个季度的销售额分别为:"; + for (int i = 0; i < 4; i++) { + cout << s.sales[i] << " "; + } + cout << endl; + cout << "最大值:" << s.max << endl; + cout << "最小值:" << s.min << endl; + cout << "平均值:" << s.average << endl; + } + +} + diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/9_4.h" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/9_4.h" new file mode 100644 index 0000000000000000000000000000000000000000..f756064d134b808190de55d773041c589b18dc49 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/9_4.h" @@ -0,0 +1,22 @@ +#pragma once +namespace SALES { + const int QUARTERS = 4; + struct Sales { + double sales[QUARTERS]; + double average; + double max; + double min; + }; + + // 复制 ar 数组中的 4 个或 n 个元素到 s 的 sales 成员, + // 并计算和存储输入项的平均值、最大值和最小值; + // 剩余的 sales 元素(如果有的话)设为 0 + void setSales(Sales& s, const double ar[], int n); + + // 交互式获取 4 个季度的销售额,存储到 s 的 sales 成员中, + // 并计算和存储平均值、最大值和最小值 + void setSales(Sales& s); + + // 显示结构 s 中的所有信息 + void showSales(const Sales& s); +} diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/main.cpp" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/main.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..7d704e0c03fd821d5bdb4361f3bd4d9f8eebe2b2 --- /dev/null +++ "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/C++PrimerPlus/Chapter9/9_4/main.cpp" @@ -0,0 +1,13 @@ +#include +#include"9_4.h" +using namespace SALES; + +int main() { + Sales s1, s2; + const double arr[3] = { 100.0,200.0,300.0 }; + setSales(s1, arr, 3); + setSales(s2); + showSales(s1); + showSales(s2); + return 0; +} \ No newline at end of file diff --git "a/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/test.txt" "b/C++/codes/2024-07/\350\213\217\345\235\232\350\215\243/test.txt" deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000