From 8420fa2a5184b1f9fb9cf6dbb1dc1f7cdb3bac9d Mon Sep 17 00:00:00 2001 From: lshprung Date: Wed, 27 Jan 2021 17:56:11 -0800 Subject: Fixed various small errors --- 01-07.md | 2 +- 01-14.md | 6 +++--- 01-19.md | 2 +- 01-21.md | 14 +++++++------- 01-26.md | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/01-07.md b/01-07.md index cfe82ee..6e11fbb 100644 --- a/01-07.md +++ b/01-07.md @@ -28,7 +28,7 @@ int square(int A){ int B = square(2); //B will equal 4 ``` -### Specifiying Pre and Post conditions +### Specifying Pre and Post conditions - Preconditions - What must be true before calling your program/method - Postconditions - What must be true/what will happen after your program returns diff --git a/01-14.md b/01-14.md index 0fc5245..f58ce01 100644 --- a/01-14.md +++ b/01-14.md @@ -245,7 +245,7 @@ x coordinate is 4 y coordinate is 6 ``` - A **reference parameter** is declared by writing the type name followed by the character `&` and the parameter name -- With a reference parameter, any use of the parameter within the body of the functino will access the argument from the calling program +- With a reference parameter, any use of the parameter within the body of the function will access the argument from the calling program - Changes made to the formal parameter in the body of the function **will alter the argument** ### Pitfall @@ -285,7 +285,7 @@ cout << d; - The function has two point parameters, and **neither parameter is changed by the function** - `double distance(const point& p1, const point& p2);` -## When the Type of a Function's Return Valeu is a Class +## When the Type of a Function's Return Value is a Class - The type of a function's return value may be a class @@ -470,7 +470,7 @@ istream& operator >>(istream& ins, point& target){ - In the input function, the input is sent to the private member variables! However, only member functions can access private member variables - Two solutions: - To write new member functions to set a point's coordinates and use these member functions within the input function's implementation - - You can grant special permission for the input functino to access the private members of the point class - Called a **Friend Function** + - You can grant special permission for the input function to access the private members of the point class - Called a **Friend Function** --- diff --git a/01-19.md b/01-19.md index a7340f7..efd4e13 100644 --- a/01-19.md +++ b/01-19.md @@ -188,7 +188,7 @@ My University Zip: 95053 1. A bag can be put in its **initial state**, which is an empty bag 2. Numbers can be **inserted** into the bag -3. You may check how many **occurences** of a certain number are in the bag +3. You may check how many **occurrences** of a certain number are in the bag 4. Numbers can be **removed** from the bag 5. You can check **how many** numbers are in the bag diff --git a/01-21.md b/01-21.md index 2f1c4e2..4edd277 100644 --- a/01-21.md +++ b/01-21.md @@ -43,7 +43,7 @@ class bag{ - Our documentation indicates that **assignments and the copy constructor may be used with a bag** - Our plan is to use the **automatic assignment operator** and the **automatic copy constructor**, each of which simply copies the member variables from one bag to another - This is fine because **the copying process will copy both the data array and the member variable** `used` -- Ecample: If a programmer has two bags `x` and `y`, then the statement `y=x` will invoke the automatic assignment operator to copy all of `x.data` to `y.data`, and to copy `x.used` to `y.used` +- Example: If a programmer has two bags `x` and `y`, then the statement `y=x` will invoke the automatic assignment operator to copy all of `x.data` to `y.data`, and to copy `x.used` to `y.used` - Our only "work" for the value semantics is confirming that the automatic operations are correct ### Header File for the Bag Class @@ -115,7 +115,7 @@ bag::size_type bag::count(const value_type& target) const; ``` - We have used the completely specified type `bag::size_type` rather than just `size_type` - - Because many compiler do not recognize that you are implementing a bag member functino until after seeing `bag::count` + - Because many compiler do not recognize that you are implementing a bag member function until after seeing `bag::count` - In the implementation, after `bag::count`, we may use simpler names such as `size_type` and `value_type` - However, before `bag::count`, we should use the full type name `bag::size_type` @@ -183,7 +183,7 @@ void bag::operator +=(const bag& addend){ } ``` -- To avoid an explicit loop **we can used the copy functino from the Standard Library** +- To avoid an explicit loop **we can used the copy function from the Standard Library** ### An Object can be an Argument to its Own Member Function @@ -197,8 +197,8 @@ b.insert(2); b += b; ``` -- In the `+=` statement, the bag `b` is activating the `+=` operator, but this smae bag `b` is the actual argument to the operator -- This is a situatino that must be carefully tested +- In the `+=` statement, the bag `b` is activating the `+=` operator, but this same bag `b` is the actual argument to the operator +- This is a situation that must be carefully tested - **Example of the danger:** Consider the **incorrect** implementation of += ``` @@ -227,7 +227,7 @@ copy(, , ); ``` - It continues beyond the beginning location, copying more and more items to the next spot of the destination, until we are about to copy the ending location - **The ending location is not copied** -- This implementation uses the `copy` functino from the `` Standard Library +- This implementation uses the `copy` function from the `` Standard Library ``` void bag::operator +=(const bag& addend){ @@ -307,7 +307,7 @@ for(i = 0; i < used; ++i){ |Operation |Time Analysis | |-------------------|------------------------------------------------| -|Default constructor|O(1) (consant time) | +|Default constructor|O(1) (constant time) | |count |O(n) (n is the size of the bag) | |erase_one |O(n) (linear time) | |erase |O(n) (linear time) | diff --git a/01-26.md b/01-26.md index da4652c..f7919d1 100644 --- a/01-26.md +++ b/01-26.md @@ -7,7 +7,7 @@ ### Introduction - The container classes' capacity is declared as a **constant** in the class definition (`bag::CAPACITY`) -- If we need bigger bages, then we can increase the constant and recompile the code +- If we need bigger bags, then we can increase the constant and recompile the code - What if a program needs one large bag and many small bags? - All the bags will be of the same size! @@ -123,7 +123,7 @@ d_ptr = new double[10]; ### Address Space Segmentation -![diagram](01-26_2.md) +![diagram](01-26_2.png) ### Stack Memory @@ -172,7 +172,7 @@ delete [] example_ptr; **Stack overflow** is the result of: - Allocating too many variables on the stack -- Making too many nested function valls +- Making too many nested function calls - Example: Where function A calls function B calls function C calls function D... - Stack overflow generally causes a program to crash @@ -191,7 +191,7 @@ int main(){ - The `new` operator usually indicates failure by throwing an exception called the `bad_alloc` exception - Normally, an exception causes an error message to be printed and the program to halt - Alternatively, a programmer can "catch" an exception and try to fix the problem - - **Exceptions** provide a way to reacto to exceptional circumstances (like runtime errors) in programs + - **Exceptions** provide a way to react to to exceptional circumstances (like runtime errors) in programs - When an exception is thrown, control is transferred to its **handler** ### Example 1 -- cgit