본문 바로가기

C++8

[Notes] Ch.21 Applying Computing to Engineering Problems (Runestone) I. Warm-up: Binary Search 1. Binary search repeatedly divides the search space (the values you are searching through) in half. 2. In the best case scenario, the first value that you look at is the optimal braking coefficient. II. Introduction: Algorithms and Data Structures 1. Algorithms & Data Structures (1) Algorithm: a set of steps to solve a computational problem We need to choose the correc.. 2022. 12. 6.
[Notes] Ch.20 More Data Structures (Runestone) EXERCISE) Printing a Vector of int Write a function that prints out the contents of a vector of int. II. Vectors of Vectors 1. Review: declaring the element type of a vector (1) Declare a vector like this: => In addition to the base type of vector, provide the type of elements it will hold. (2) A vector can store elements of any type, as long as they match the type with which it is declared. 2. .. 2022. 12. 6.
[Notes] Ch.19 Structs (Runestone) I. Introduction 1. Modeling Real-World Objects in Code (1) Let’s model the autonomous rovers used to explore the dark side of Proxima b. => This proliferation of variables will quickly become unmanageable. (2) Using vectors: Vectors can store sequences of objects => We no longer need an arbitrary large number of variables. The vectors just grow to accommodate new rovers. => However, each attribu.. 2022. 12. 6.
[Notes] Ch.18 Program Design in C++ (Runestone) I. Introduction 1. Bottom-up design: starts by identifying specific features that we’ll need in our program, and then writing functions that accomplish these specific features. 2. Top-down design: starts by looking at the big picture of what the end result will be, and then breaks it down into smaller steps after that. II. Bottom-up Design We need to first think of some small pieces of functiona.. 2022. 12. 5.
[Notes] Ch.16 Strings, Streams, and I/O (Runestone) I. The Standard Library and # Include 1. C++ standard library (1) To use part of the standard library, use the #include directive. Ex) if you would like to use cout and cin in the code, you’ll need to include library at the top of your .cpp file #include using namespace std; (3) The using namespace std; directive is generally used with included libraries, we can use shorthand names like cout and.. 2022. 11. 18.
[Notes] Ch.14 Iteration (Runestone) I. While Loop 1. While loop (1) While loops execute a block of code as long as some condition is true. (2) If we start x at 0, and count while x < N, we iterate N times (with x as 0,1,..., N-1) 2. Hint on Creating While Loops Some of the trickier parts of writing a correct while loop are: (1) Where does it start? ex) “what gets initialized before the loop starts? And to what value?” (2) When doe.. 2022. 11. 18.
[Notes] Ch.13 More C++ Basics and Branching (Runestone) I. Implicit Type Conversions 1. int to double 1. Widening conversion: a double can always hold any integer value. (1) A double is a wider data type than an int. (2) There is no info loss in this conversion, so this conversion and other widening conversions are generally considered safe. 2. double to int (1) The double value is truncated and only the integer part of the number is retained. (2) Fr.. 2022. 11. 18.
[Notes] Ch.12 Introduction to C++ (Runestone) I. C++, Machine Code, Compilers 1. Interpreted Languages (1) MATLAB: interpreted language. * The code doesn’t run on your computer. * MATLAB (the program) runs on the computer and processes the code line-by-line, telling the computer what to do. 2. Machine Languages (1) Computers can only directly run programs written in “machine code”. (2) Different kinds of computers also have different machin.. 2022. 11. 18.