From 0df13cfa930c2b05934660213c024cd808b07d24 Mon Sep 17 00:00:00 2001 From: Nuevo009 <73752701+Nuevo009@users.noreply.github.com> Date: Tue, 28 Sep 2021 19:16:48 +0800 Subject: [PATCH 1/3] Update 7_9.cpp --- ch07/7_9.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ch07/7_9.cpp b/ch07/7_9.cpp index fe7f275..ce1da48 100644 --- a/ch07/7_9.cpp +++ b/ch07/7_9.cpp @@ -52,7 +52,7 @@ int getinfo(student * pstu, int n) cout << "fullname: "; // detect blank line cin.getline(pt->fullname, Slen); - if(!pt->fullname) + if(!*pt->fullname) break; cout << "hobby: "; cin.getline(pt->hobby, Slen); From c2cb165729364072236c7ce1a4367064bdd7dd09 Mon Sep 17 00:00:00 2001 From: Nuevo009 <73752701+Nuevo009@users.noreply.github.com> Date: Sat, 9 Oct 2021 16:56:42 +0800 Subject: [PATCH 2/3] Update randwalk.cpp --- ch11/11_1/randwalk.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ch11/11_1/randwalk.cpp b/ch11/11_1/randwalk.cpp index 2e84edd..70b324b 100644 --- a/ch11/11_1/randwalk.cpp +++ b/ch11/11_1/randwalk.cpp @@ -20,7 +20,11 @@ int main() // write to file ofstream fout; fout.open("walk.txt"); - + if (!fout.is_open()) { + cout << "Could not write to file \n"; + cout << "Program terminating.\n"; + exit(EXIT_FAILURE); + } cout << "Enter target distance (q to quit): "; while (cin >> target) { @@ -29,29 +33,37 @@ int main() break; // write to file - fout << "Target Distance: " << target << ", "; - fout << "Step Size: " << dstep << endl; + fout << "Target Distance: " << target << ", Step Size: " << dstep << endl + << steps << ": " << result << endl; while (result.magval() < target) { direction = rand() % 360; step.reset(dstep, direction, Vector::POL); result = result + step; - fout << steps << ": " << result << endl; steps++; + fout << steps << ": " << result << endl; } 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" << result << endl; result.polar_mode(); cout << " or\n" << result << endl; cout << "Average outward distance per step = " - << result.magval()/steps << endl; + << result.magval()/steps << endl; + fout << " or\n" + << result << endl + << "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"; + fout.close(); return 0; } From 1c4ba250dd53bf92540a67a7e678918e764c0d8a Mon Sep 17 00:00:00 2001 From: Nuevo009 <73752701+Nuevo009@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:29:57 +0800 Subject: [PATCH 3/3] Update README.md I guess you lost a blankspace. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9e08a2..3951300 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ C++ Primer Plus 6th answers (by **PytLab**) C++ Primer Plus(第六版) 编程练习答案(全部本人所写,仅供参考) -###Table of Content +### Table of Content - [第三章 处理数据](https://github.com/PytLab/Cpp-Primer-Plus/tree/master/ch03) - [第四章 复合类型](https://github.com/PytLab/Cpp-Primer-Plus/tree/master/ch04)