diff --git a/.vscode/launch.json b/.vscode/launch.json index de9bd5a..356814a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,7 @@ "name": "nyplaylists", "type": "cppdbg", "request": "launch", - "program": "${fileDirname}/${fileBasenameNoExtension}", // 指向你的可执行文件 + "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [ "playlist_tiny2.txt", "actions2.txt", @@ -17,6 +17,41 @@ "MIMode": "gdb", "miDebuggerPath": "/usr/bin/gdb", "preLaunchTask": "C/C++: g++ build active file" + }, + { + "name": "nyride", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}/${fileBasenameNoExtension}", + "args": [ + "drivers.txt", + "riders.txt", + "output0.txt", + "output1.txt", + "output2.txt", + "516-951-1561", + "request", + "debug" + ], + "cwd": "${fileDirname}", + "environment": [], + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb", + "preLaunchTask": "C/C++: g++ build active file" + }, + { + "name": "lab02-roads", + "type": "cppdbg", + "request": "launch", + "program": "${fileDirname}/${fileBasenameNoExtension}", + "args": [ + "input_a.txt" + ], + "cwd": "${fileDirname}", + "environment": [], + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb", + "preLaunchTask": "C/C++: g++ build active file" } ] } diff --git a/labs/debugging/line.cpp b/labs/debugging/line.cpp index 5a6a867..6f73589 100644 --- a/labs/debugging/line.cpp +++ b/labs/debugging/line.cpp @@ -22,7 +22,7 @@ double gradient(const Line &ln) { float gradient = 100.0 * fabs(slope); // take the absolute value if (gradient < 0) { - gradient * -1; + gradient *= -1; } return gradient; } @@ -37,6 +37,5 @@ bool steeper_gradient(const Line &m, const Line &n) { return true; if (gradient_n > gradient_m) return false; + return false; } - - diff --git a/labs/debugging/line.h b/labs/debugging/line.h index 8c35b5f..08dc1e4 100644 --- a/labs/debugging/line.h +++ b/labs/debugging/line.h @@ -1,3 +1,5 @@ +#ifndef LINE_H +#define LINE_H #include "point.h" // A simple line class. In this simple world, we'll follow the @@ -26,4 +28,4 @@ double gradient(const Line &ln); // (That can be used to sort a collection of roads.) bool steeper_gradient(const Line &m, const Line &n); - +#endif \ No newline at end of file diff --git a/labs/debugging/main b/labs/debugging/main deleted file mode 100755 index 76b814c..0000000 Binary files a/labs/debugging/main and /dev/null differ diff --git a/labs/debugging/main.cpp b/labs/debugging/main.cpp.back similarity index 100% rename from labs/debugging/main.cpp rename to labs/debugging/main.cpp.back diff --git a/labs/debugging/point.cpp b/labs/debugging/point.cpp index 552ac82..891b612 100644 --- a/labs/debugging/point.cpp +++ b/labs/debugging/point.cpp @@ -20,6 +20,6 @@ double compute_slope(const Point &a, const Point &b) { double run_x = b.get_x() - a.get_x(); double run_z = b.get_z() - a.get_z(); double run = sqrt(run_x*run_x + run_z*run_z); - double answer = rise / run; + //double answer = rise / run; return rise / run; } diff --git a/labs/debugging/point.h b/labs/debugging/point.h index a70eae6..1d1cab0 100644 --- a/labs/debugging/point.h +++ b/labs/debugging/point.h @@ -1,6 +1,7 @@ +#ifndef _POINT_H_ +#define _POINT_H_ #include - // A simple 3D point class. In this simple world, we'll follow the // convention often used in Computer Graphics. y is the vertical // axes, "pointing" up. The x and z axes define the ground plane. @@ -26,3 +27,5 @@ std::ostream& operator<< (std::ostream &ostr, const Point &p); // A helper function to compute the slope between two Points. double compute_slope(const Point &a, const Point &b); + +#endif \ No newline at end of file diff --git a/labs/debugging/roads.cpp b/labs/debugging/roads.cpp index a80274a..a7d4d45 100644 --- a/labs/debugging/roads.cpp +++ b/labs/debugging/roads.cpp @@ -2,13 +2,13 @@ #include #include #include +#include #include "line.h" - - +#include "point.h" // A helper function to parse a collection of files from an input file. -std::vector& load(std::ifstream &istr) { +std::vector load(std::ifstream &istr) { std::vector roads; float x1,y1,z1,x2,y2,z2; while (istr >> x1 >> y1 >> z1 >> x2 >> y2 >> z2) { @@ -28,13 +28,14 @@ void organize(std::vector &roads) { void print(const std::vector &roads) { // print each road in the current, sorted order (steepest first) - for (int i = 0; i < roads.size(); i++) { + //for (int i = 0; i < roads.size(); i++) { + for (size_t i = 0; i < roads.size(); i++) { std::cout << roads[i] << std::endl; } // count the number of roads with gradient less than 10% int count; - for (unsigned int i = roads.size() - 1; + for (int i = roads.size() - 1; i >= 0 && gradient(roads[i]) < 10.0; i--) { count++;