본문 바로가기

umich engr 101 c++4

[Notes] Ch.17 Vectors in C++ (Runestone) I. Introduction Indexing in C++ also uses random access to read and write data, but the indices start a 0 (just like with strings in C++). II. Declaring and Initializing Vectors in C++ 1. Vectors in C++ (1) In C++, a vector is used to store a sequence of elements. -> The elements must be homogenous (all of the same type) (2) This is conceptually similar to a vector in MATLAB, but the details are.. 2022. 11. 18.
[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.15 Functions in C++ (Runestone) I. Function Basics 1. Basic structure of a function in C++ int square(int n){ Return n * n; } The function square takes one int parameter (a variable you can use in your function code), and returns an int value. Ex) calling the function: int x = 3; int y = square(x); cout 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.