Last active
December 16, 2015 14:19
-
-
Save nathanhleung/e7bb2819bfff39c55d0f to your computer and use it in GitHub Desktop.
Revisions
-
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,26 +14,26 @@ 4. Define a function called `squareArea` that computes the area of a square of a given `sideLength`. ```cpp double squareArea(double sideLength) { return pow(sideLength, 2.0); } ``` 5. Consider this function: ```cpp int mystery( int x, int y) { double result = (x + y ) / ( y - x); return result; } ``` What is the result of `mystery(2,3)` and `mystery(3,5)`. 1. `5` and `4`. 6. Implement a function that returns the minimum of three values. ```cpp // Prototype int findTheSmallest(int, int, int); // Implementation @@ -51,7 +51,7 @@ ``` ## Attached Code ```cpp #include <iostream> #include <cmath> -
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ 1. `cubeByVolume(8)` = `512`. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ```cpp double cubeByVolume(double sideLength) { return pow(sideLength, 3.0); } -
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ # Returning Values ## Questions 1. What is the value of `cubeByVolume(9)`? 1. `729`. 2. What is the value of `cubeByVolume(cubeByVolume(2))`? 1. `cubeByVolume(8)` = `512`. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ``` @@ -30,7 +30,7 @@ ``` What is the result of `mystery(2,3)` and `mystery(3,5)`. 1. `5` and `4`. 6. Implement a function that returns the minimum of three values. ``` -
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,27 +5,34 @@ 2. What is the value of `cubeByVolume(cubeByVolume(2))`? 1. `cubeByVolume(8)` = 512. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ``` double cubeByVolume(double sideLength) { return pow(sideLength, 3.0); } ``` 4. Define a function called `squareArea` that computes the area of a square of a given `sideLength`. ``` double squareArea(double sideLength) { return pow(sideLength, 2.0); } ``` 5. Consider this function: ``` int mystery( int x, int y) { double result = (x + y ) / ( y - x); return result; } ``` What is the result of `mystery(2,3)` and `mystery(3,5)`. 1. 5 and 4. 6. Implement a function that returns the minimum of three values. ``` // Prototype int findTheSmallest(int, int, int); -
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ 1. What is the value of `cubeByVolume(9)`? 1. 9^3 = 729. 2. What is the value of `cubeByVolume(cubeByVolume(2))`? 1. `cubeByVolume(8)` = 512. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ``` double cubeByVolume(double sideLength) { @@ -24,7 +24,7 @@ a. `cubeByVolume(8)` = 512. } ``` What is the result of `mystery(2,3)` and `mystery(3,5)`. 1. 5 and 4. 6. Implement a function that returns the minimum of three values. ``` // Prototype -
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Returning Values ## Questions 1. What is the value of `cubeByVolume(9)`? 1. 9^3 = 729. 2. What is the value of `cubeByVolume(cubeByVolume(2))`? a. `cubeByVolume(8)` = 512. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. -
nathanhleung revised this gist
Dec 16, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ # Returning Values ## Questions 1. What is the value of `cubeByVolume(9)`? a. 9^3 = 729. 2. What is the value of `cubeByVolume(cubeByVolume(2))`? a. `cubeByVolume(8)` = 512. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ``` double cubeByVolume(double sideLength) { -
nathanhleung created this gist
Dec 16, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,96 @@ # Returning Values ## Questions 1. What is the value of `cubeByVolume(9)`? a. 9^3 = 729. 2. What is the value of `cubeByVolume(cubeByVolume(2))`? a. `cubeByVolume(8)` = 512. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ``` double cubeByVolume(double sideLength) { return pow(sideLength, 3.0); } ``` 4. Define a function called `squareArea` that computes the area of a square of a given `sideLength`. ``` double squareArea(double sideLength) { return pow(sideLength, 2.0); } ``` 5. Consider this function: ``` int mystery( int x, int y) { double result = (x + y ) / ( y - x); return result; } ``` What is the result of `mystery(2,3)` and `mystery(3,5)`. a. 5 and 4. 6. Implement a function that returns the minimum of three values. ``` // Prototype int findTheSmallest(int, int, int); // Implementation int findTheSmallest(int x, int y, int z) { if (x < y && x < z) { return x; } else if (y < x && y < z) { return y; } return z; } // Function call findTheSmallest(1,2,3); // => 1 ``` ## Attached Code ``` #include <iostream> #include <cmath> using namespace std; double steinbergPow( double, double); int main() { double result1; double result2; result1 = pow( 2.0, 4.0 ); result2 = steinbergPow( 2.0, 4.0 ); cout << "pow: " << result1 << endl; cout << "steinbergPow: " << result2 << endl; cout << endl; system("pause"); return EXIT_SUCCESS; } /** Raises base to the power @param base is the base @param power is the exponent */ double steinbergPow( double base, double power ) { double sum = 1; for( int i = 0; i < power ; i++ ) { sum = sum * base; } return sum; } /* Computes the volume of a cube. @param sideLength the side length of a cube @return the volume */ double cubeByVolume( double sideLength ) { double volume = sideLength * sideLength * sideLength; return volume; } ```