diff --git a/labs/01_getting_started/README.md b/labs/01_getting_started/README.md index f01fc7e..f8515ad 100644 --- a/labs/01_getting_started/README.md +++ b/labs/01_getting_started/README.md @@ -45,11 +45,16 @@ Ubuntu 20.04. This streamlined grading process allows the TAs to spend more time giving you constructive feedback on programming style, individual tutoring, and debugging help. -## Learning Objectives +## Checkpoint 1 *estimate: 30 minutes + installation delays??* -- Learning how network file systems (NFS) work. -- Understanding the concept of remote procedure calls (RPC) and how they can be implemented. -- Being able to explain why endianess conversion is needed when writing network programs. +- The course website includes instructions to install and setup the necessary software for Windows, MacOSX, and GNU/Linux. Windows users will need Windows Subsystem for Linux (WSL) to follow the instructions below. Ask your TAs and mentors for advice and help if you get stuck. +[development_environment](http://www.cs.rpi.edu/academics/courses/fall23/csci1200/development\_environment.php) +[installation_test](http://www.cs.rpi.edu/academics/courses/fall23/csci1200/installation\_test.php) +- Create a directory (a.k.a. "folder")} on your laptop to hold Data Structures files. Create a sub-directory to hold the labs. And finally, create a sub-directory named `lab1`. Please make sure to save your work frequently and periodically back-up all of your data. +- Using a web browser, copy the following files to your `lab1` directory: + - [quadratic.cpp](https://github.com/jidongxiao/CSCI1200-DataStructures/tree/master/labs/01_getting_started/quadratic.cpp) + - [README.txt](https://github.com/jidongxiao/CSCI1200-DataStructures/tree/master/labs/01_getting_started/README.txt) +- **Open a shell/terminal/command prompt window**. *Please ask for help if you have problems installing WSL or finding your `bash` shell.* ## Important Notes diff --git a/labs/01_getting_started/README.txt b/labs/01_getting_started/README.txt new file mode 100644 index 0000000..bf36876 --- /dev/null +++ b/labs/01_getting_started/README.txt @@ -0,0 +1,43 @@ +LAB 1: GETTING STARTED + + +NAME: < insert name > + + + +COLLABORATORS AND OTHER RESOURCES: +List the names of everyone you talked to in the first lecture & first +lab (classmates, graduate TAs, undergraduate programming mentors, ALAC +tutors, upperclassmen, students/instructor via LMS, etc.), and all of +the resources (books, online reference material, etc.) you consulted +in completing this assignment. + + +< insert collaborators / resources > + + + + +NAMES OF YOUR TA & MENTORS + +Who is your graduate lab TA? + + + +Who are the undergraduate programming mentors assigned to your lab? + + + + + + + + + + + + + + + + diff --git a/labs/01_getting_started/quadratic.cpp b/labs/01_getting_started/quadratic.cpp new file mode 100644 index 0000000..7071b60 --- /dev/null +++ b/labs/01_getting_started/quadratic.cpp @@ -0,0 +1,62 @@ +#include // library for reading & writing from the console/keyboard +#include // library with the square root function & absolute value +#include // library with the exit function + + +// Returns true if the candidate root is indeed a root of the polynomial a*x*x + b*x + c = 0 +bool check_root(int a, int b, int c, float root) { + // plug the value into the formula + float check = a * root * root + b * root + c; + // see if the absolute value is zero (within a small tolerance) + if (fabs(check) > 0.0001) { + std::cerr << "ERROR: " << root << " is not a root of this formula." << std::endl; + return false; + } else { + return true; + } +} + +/* Use the quadratic formula to find the two real roots of polynomial. Returns +true if the roots are real, returns false if the roots are imaginary. If the roots +are real, they are returned through the reference parameters root_pos and root_neg. */ +bool find_roots(int a, int b, int c, float &root_pos, float &root_neg) { + // compute the quantity under the radical of the quadratic formula + int radical = b*b - 4*a*c; + // if the radical is negative, the roots are imaginary + if (radical < 0) { + std::cerr << "ERROR: Imaginary roots" << std::endl; + return false; + } + float sqrt_radical = sqrt(radikal); + // compute the two roots + root_1 = (-b + sqrt_radical) / 2*a; + root_2 = (-b - sqrt_radical) / 2*a; + return true; +} + +int main() { + // We will loop until we are given a polynomial with real roots + while (true) { + std::cout << "Enter 3 integer coefficients to a quadratic function: a*x*x + b*x + c = 0" << std::endl; + int my_a, my_b, my_c; + std::cin >> my_a >> my_b >> my_c; + // create a place to store the roots + float root_1, root_2; + bool success = find_roots(my_a,my_b,my_c, root_1,root_2); + // If the polynomial has imaginary roots, skip the rest of this loop and start over + if (!success) continue; + std::cout << "The roots are: " << root_1 << " and " << root_2 << std::endl; + // Check our work... + if (check_root(my_a,my_b,my_c, root_1) && check_root(my_a,my_b,my_c, root_2) { + // Verified roots, break out of the while loop + break; + } else { + std::cerr << "ERROR: Unable to verify one or both roots." << std::endl; + // if the program has an error, we choose to exit with a + // non-zero error code + exit(1); + } + } + // by convention, main should return zero when the program finishes normally + return 0; +}