Copied to Clipboard
@@ -32,7 +33,7 @@ export default function Terminal(props: TerminalProps): JSX.Element {
<>>
)}
-
+
{
diff --git a/src/pages/Conclusion.tsx b/src/pages/Conclusion.tsx
index 47510d88..025b9f74 100644
--- a/src/pages/Conclusion.tsx
+++ b/src/pages/Conclusion.tsx
@@ -37,7 +37,7 @@ const Conclusion: FC = () => {
-
+
>
);
};
diff --git a/src/pages/Exercise2.tsx b/src/pages/Exercise2.tsx
index 2fc8bfc3..24ac729c 100644
--- a/src/pages/Exercise2.tsx
+++ b/src/pages/Exercise2.tsx
@@ -134,7 +134,7 @@ const Exercise2: FC = () => {
@@ -147,7 +147,7 @@ const Exercise2: FC = () => {
diff --git a/src/pages/Exercise5.tsx b/src/pages/Exercise5.tsx
new file mode 100644
index 00000000..5023dca5
--- /dev/null
+++ b/src/pages/Exercise5.tsx
@@ -0,0 +1,277 @@
+import { FC } from 'react';
+import '../styles/Exercise5.scss';
+import AppWrapper from '../components/AppWrapper';
+import NavButtons from '../components/NavButtons';
+import RunCode from '../components/RunCode';
+import SlideShow from '../components/SlideShow';
+import Terminal from '../components/Terminal';
+import { HeaderSections } from '../types/globalTypes';
+
+const code1 = `void dream1(int a){
+ a+=1;
+}`;
+const code2 = `void dream2(int &a){
+ a+=2;
+}`;
+const code3 = `void dream3(int *a){
+ *a+=3;
+}`;
+const code4 = `void dream4(int *a){
+ int b = 5;
+ a = &b;
+ *a+=4;
+}`;
+
+const questions1 = [
+ {
+ question: 'The input is passed by?',
+ options: ['value', 'reference', 'pointer'],
+ answer: 'value',
+ answerText: new Map([
+ [
+ 'value',
+ 'Correct! Nothing special is happening, so it is pass by value.',
+ ],
+ ['reference', 'Not quite! There is no & sign before the variable a.'],
+ ['pointer', 'There is no * sign before the variable a.'],
+ ]),
+ },
+ {
+ question:
+ 'When we call the function dream1 with variable num, will num be changed?',
+ options: ['No', 'Yes'],
+ answer: 'No',
+ answerText: new Map([
+ ['Yes', 'Correct! The function will only change the copy of num.'],
+ [
+ 'No',
+ 'Not quite! When a variable is passed by value, the function does not affect the variable.',
+ ],
+ ]),
+ },
+];
+const questions2 = [
+ {
+ question: 'The input is passed by?',
+ options: ['value', 'reference', 'pointer'],
+ answer: 'reference',
+ answerText: new Map([
+ [
+ 'value',
+ 'Correct! The & in the function parameter signals pass by reference.',
+ ],
+ ['reference', 'Not quite! There is an & sign before the variable a.'],
+ ['pointer', 'Not quite! There is an & sign before the variable a.'],
+ ]),
+ },
+ {
+ question:
+ 'When we call the function dream2 with variable num, will num be changed?',
+ options: ['No', 'Yes'],
+ answer: 'Yes',
+ answerText: new Map([
+ [
+ 'Yes',
+ 'Correct! The change made to "a" inside the function is reflected in the variable num.',
+ ],
+ [
+ 'No',
+ 'Not quite! The variable is passed by reference, so the function can modify it.',
+ ],
+ ]),
+ },
+];
+const questions3 = [
+ {
+ question: 'The input is passed by?',
+ options: ['value', 'reference', 'pointer'],
+ answer: 'pointer',
+ answerText: new Map([
+ ['value', 'Not quite! There is * in the function parameter.'],
+ ['reference', 'Not quite! There is * in the function parameter.'],
+ [
+ 'pointer',
+ 'Correct! The * in the function parameter signals pass by pointer.',
+ ],
+ ]),
+ },
+ {
+ question:
+ 'When we call the function dream1 with variable num, will num be changed?',
+ options: ['No', 'Yes'],
+ answer: 'Yes',
+ answerText: new Map([
+ [
+ 'No',
+ 'Not quite! What pointer “a” points to, which is num, is being changed.',
+ ],
+ [
+ 'Yes',
+ 'Correct! What pointer “a” points to, which is num, is being changed.',
+ ],
+ ]),
+ },
+];
+const questions4 = [
+ {
+ question: 'The input is passed by?',
+ options: ['value', 'reference', 'pointer'],
+ answer: 'pointer',
+ answerText: new Map([
+ ['value', 'Not quite! There is * in the function parameter.'],
+ ['reference', 'Not quite! There is * in the function parameter.'],
+ [
+ 'pointer',
+ 'Correct! The * in the function parameter signals pass by pointer.',
+ ],
+ ]),
+ },
+ {
+ question:
+ 'When we call the function dream4 with variable num, will num be changed?',
+ options: ['No', 'Yes'],
+ answer: 'No',
+ answerText: new Map([
+ [
+ 'No',
+ 'Correct! When “a” is dereferenced, it points to b instead of “num”, so the change of value has nothing to do with num.',
+ ],
+ [
+ 'Yes',
+ 'Not quite! Although “a” is dereferenced, it does not point to “num” anymore.',
+ ],
+ ]),
+ },
+];
+const questions5 = [
+ {
+ question: 'After Pipi runs the main function, what is the value of a?',
+ options: ['20', '80'],
+ answer: '80',
+ answerText: new Map([
+ [
+ '80',
+ `Correct! The "&" before the "num" variable in the "quadruple" function
+ definition shows that the argument is passed by reference.
+ The change made to num inside the function is reflected in the variable a.`,
+ ],
+ [
+ '20',
+ `Not quite! The "&" before the "num" variable in the "quadruple"
+ function definition shows that the argument is passed by reference.`,
+ ],
+ ]),
+ },
+ {
+ question: 'After Pipi runs the main function, what is the value of b?',
+ options: ['20', '40'],
+ answer: '20',
+ answerText: new Map([
+ [
+ '20',
+ `Correct! The function double takes its parameter by value,
+ meaning it operates on a copy of b. Changes within the double
+ function do not affect the original value of b.`,
+ ],
+ [
+ '40',
+ `Not quite! Note that this is not pass by reference or pass by pointer.
+ We are passing b normally, the function makes a copy of b, and the copy
+ is being modified.`,
+ ],
+ ]),
+ },
+ {
+ question: 'After Pipi runs the main function, what is the value of b?',
+ options: ['20', '60'],
+ answer: '60',
+ answerText: new Map([
+ [
+ '60',
+ `Correct! We pass a pointer to the triple function.
+ The function makes a copy of that pointer, dereferences it,
+ and modifies the value it points to.`,
+ ],
+ [
+ '20',
+ `Not Quite! The function takes a pointer and modifies the value the
+ pointer points to by dereferencing it.`,
+ ],
+ ]),
+ },
+];
+
+const codeblock = `
+#include
+
+void quadruple (int &num){
+ num *= 4;
+}
+
+void double(int x) {
+ x *= 2;
+}
+
+void triple (int* money){
+ *money *= 3;
+}
+
+
+int main() {
+ int a = 20;
+ int b = 20;
+ int c = 20
+ quadruple(a);
+ double (b);
+ triple(&c);
+}
+`;
+
+const Exercise5: FC = () => {
+ const passingCode = [];
+ passingCode.push(
+
+ );
+ passingCode.push(
+
+ );
+ passingCode.push(
+
+ );
+ passingCode.push(
+
+ );
+
+ return (
+ <>
+
+
+
Exercise 5: Passing Confusion
+
+ For this exercise, you will be passing parameters by value,
+ reference, and pointer and examining the difference between these.
+ Pipi is looking at a bunch of code and doesn't understand what
+ is going on! Help Pipi find the correct solution.
+
+
+ Pipi now wants to replace the basketball with a soccer ball. What is
+ the corresponding code to do this?
+
+
+
+
+
+
+
+
+
+ >
+ );
+};
+
+export default Exercise5;
diff --git a/src/pages/Exercise6.tsx b/src/pages/Exercise6.tsx
index 59b47a15..e017d624 100644
--- a/src/pages/Exercise6.tsx
+++ b/src/pages/Exercise6.tsx
@@ -204,7 +204,7 @@ const Exercise6: FC = () => {
>
);
};
diff --git a/src/pages/Lesson10.tsx b/src/pages/Lesson10.tsx
index 26bb4d83..db68bbcd 100644
--- a/src/pages/Lesson10.tsx
+++ b/src/pages/Lesson10.tsx
@@ -41,7 +41,7 @@ const Lesson10: FC = () => {
Let’s take a look at another common application of pointers: dynamic
- memory allocation
+ memory allocation.
Allocating memory is just saying to the computer that you want to
diff --git a/src/styles/Exercise5.scss b/src/styles/Exercise5.scss
new file mode 100644
index 00000000..f05fd9e7
--- /dev/null
+++ b/src/styles/Exercise5.scss
@@ -0,0 +1,11 @@
+.exercise5-div {
+ align-items: center;
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ width: 100%;
+
+ @media screen and (max-width: 850px) {
+ flex-direction: column;
+ }
+}
diff --git a/src/styles/RunCode.scss b/src/styles/RunCode.scss
index f4e89e30..7bd53bb8 100644
--- a/src/styles/RunCode.scss
+++ b/src/styles/RunCode.scss
@@ -13,6 +13,12 @@
}
}
+.code-select-container {
+ display: flex;
+ flex-direction: column;
+ gap: 1.5em;
+}
+
.code-select {
align-items: center;
display: flex;
@@ -54,3 +60,9 @@
position: static; // Make button static for small screens
}
}
+
+// fix size of svg to be min of 20 px
+.lightbulb-icon {
+ height: auto;
+ min-width: 20px;
+}
diff --git a/src/styles/SelectCode.scss b/src/styles/SelectCode.scss
index fe7b6e61..a67ef484 100644
--- a/src/styles/SelectCode.scss
+++ b/src/styles/SelectCode.scss
@@ -1,6 +1,9 @@
+@import './global';
+
.select-box {
border: 1px;
border-color: #cfcfcf;
+ font-family: $niramit;
font-size: 1.6vw;
height: fit-content;
width: fit-content;
diff --git a/src/styles/SlideShow.scss b/src/styles/SlideShow.scss
index ca4497a3..26098b3b 100644
--- a/src/styles/SlideShow.scss
+++ b/src/styles/SlideShow.scss
@@ -1,8 +1,8 @@
@import './global';
// Variables
//=======================================
-$side-margins: 0%;
-$bottom-margin: 35%;
+$side-margins: -10%;
+$bottom-margin: 45%;
$top-padding: 7vh;
$bottom-padding: 10vh;
$img-height: 400px;
@@ -22,24 +22,26 @@ $img-height: 400px;
}
}
-.left {
+.slideshow-left {
background: none;
border: 0;
bottom: $bottom-margin;
left: $side-margins;
position: absolute;
+ z-index: 1;
&:hover {
cursor: pointer;
}
}
-.right {
+.slideshow-right {
background: none;
border: 0;
bottom: $bottom-margin;
position: absolute;
right: $side-margins;
+ z-index: 1;
&:hover {
cursor: pointer;
diff --git a/src/styles/Terminal/Terminal.scss b/src/styles/Terminal/Terminal.scss
index 47612a27..cc45797b 100644
--- a/src/styles/Terminal/Terminal.scss
+++ b/src/styles/Terminal/Terminal.scss
@@ -5,6 +5,10 @@
width: 80%;
}
+.terminal-container {
+ width: 100%;
+}
+
.copybutton {
position: absolute;
right: 14px;
diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts
index dcdeb88d..3082776b 100644
--- a/src/types/globalTypes.ts
+++ b/src/types/globalTypes.ts
@@ -13,7 +13,10 @@ export enum HeaderSections {
LESSON_2 = 'Lesson 2',
LESSON_3 = 'Lesson 3',
EXERCISE_1 = 'Exercise 1',
+ EXERCISE_2 = 'Exercise 2',
EXERCISE_3 = 'Exercise 3',
+ EXERCISE_4 = 'Exercise 4',
+ EXERCISE_5 = 'Exercise 5',
EXERCISE_6 = 'Exercise 6',
LESSON_4 = 'Lesson 4',
LESSON_5 = 'Lesson 5',
@@ -22,8 +25,6 @@ export enum HeaderSections {
LESSON_8 = 'Lesson 8',
LESSON_9 = 'Lesson 9',
LESSON_10 = 'Lesson 10',
- EXERCISE_2 = 'Exercise 2',
- EXERCISE_4 = 'Exercise 4',
CONCLUSION = 'Conclusion',
}
@@ -46,6 +47,7 @@ export enum PageURLs {
EXERCISE_2 = '/exercise-2',
EXERCISE_3 = '/exercise-3',
EXERCISE_4 = '/exercise-4',
+ EXERCISE_5 = '/exercise-5',
EXERCISE_6 = '/exercise-6',
CONCLUSION = '/conclusion',
}
@@ -70,6 +72,7 @@ export enum PageOrder {
'/exercise-2',
'/exercise-3',
'/exercise-4',
+ '/exercise-5',
'/exercise-6',
'/conclusion',
}