Year #3, Week #13 đ» đ
New stuff we learned this week: đ€
Pointer Arithmetic in C
- The magic formula:
array[i] == p + i
(wherep
is a pointer toa[0]
) - All arguments are passed by VALUE in C, including arrays, because they DECAY INTO POINTERS.
- There are 3 forms of pointer math allowed in C:
- Adding an
int
to a pointer, which produces another pointer - Subtracting an
int
from a pointer, which produces another pointer - Subtracing two pointers, which produces an
int
representing the number of items between the two pointers
- Adding an
- When you add and subtract integers to/from pointers, the pointers are
automagically scaled according to the
sizeof
the type pointed to. This is the same as what happens with integers used for array access, you probably just never thought of it before. - If you have any questions, simply refer to this diagram:
Homework Plan (2 weeks)
- 1 day Monkey Assignment #20 đ
- 1 day Monkey Assignment #21 đ
- 2 day review all flashcards in your (new Netlify) app.
- 2 day touch typing practice
- 1 day read King-C ch. 12 đ
- 1 day King-C ch. 12 projects đ
- 1 day Flashcards Webapp assignment (Login/Signup)
- 1 day watch CS50
CS50 Lecture #3 segment,
from
1:01:56
to end. - 6 days Execute Program homework
King C Chapter 12 Exercizes/Projects đ
First, make sure youâve slowly and carefully read all of chapter 12 of King C. assignment.
Merge your
king-c
repo branch from last week, and CREATE A NEW BRANCH.Then, do the following programming projects:
Project #1a
, andProject #1b
, each in a SEPARATE file.Project #2a
, andProject #2b
, each in a SEPARATE file.Project #7
NOTE: Do this one BEFORE Project #6, itâs easier and good practice for #6.- here is the starting code
- hint: do the same trick of initializing an array without requiring user
input while youâre working on this one, then remove it and uncomment the
part that uses
scanf
.
Interlude
(not in the book): modify theanagrams
assignment from chapter 8 (project#16
) to use pointers instead of array indexing with integers.Project #6
- here is the starting code
- hint: the type of the
part_element
variable should NOT be changed. - hint: your function prototypes should be:
void quicksort(int a[], int* low, int* high); int* split(int a[], int* low, int* high);
- hint: comment out the first 3 lines of
main
and replace them with the following, so you donât have to keep entering numbers to test, then remove when youâve got it working.
int i = 0; int a[N] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
before you slack me the URL, review your own diffs, clean up anything you notice, then slack me the URL.
Monkey #20 đ
- Address all feedback from prior MRâs, and merge.
- Create a new branch.
- Double-check that you did the first two steps.
- Start where you left of last time, after the Completing the REPL section, which is labeled Boolean Literals.
- Complete the next 3 short section:
- Boolean Literals
- Null
- Prefix Expressions
- Commit your work.
- As always, make sure to try to do as much as you can without the videos, but always also watch the videos and update your code to (mostly) match.
- Video link
- Submit a MR, Review your diffs and fixup!!, then slack the MR url
Monkey #21 đ
- Address all feedback from prior MRâs, and merge.
- Create a new branch.
- Double-check that you did the first two steps.
- Start where you left of last time, after the Prefix Expressions section, which is labeled Infix Expressions. Complete the section.
- Commit your work.
- As always, make sure to try to do as much as you can without the videos, but always also watch the videos and update your code to (mostly) match.
- Video link
- Submit a MR, Review your diffs and fixup!!, then slack the MR url
Flashcards WebApp Assignment
- First, make sure youâve addressed any feedback from your last MR, then merge.
- Make a new branch
- As I went over and briefly sketched out in class, your task is to make 2 new
components: 1) a Login component, and 2) a Signup component, following these
hints/requirements:
- Work purely in Storylite, donât integrate these components anywhere in the actual live app yet
- both forms must look good down to
385px
- you must build them first at
385px
, then modify them to look different at larger screen sizes - because these two components will be very similar, you should reduce duplication by composing them both out of re-usable smaller components, and minimize duplication as much as possible to keep things DRY.
- you must, at the very least, extract a
<Button />
component (if you donât have a usable one already), and a<TextInput />
component. - since youâre only working in storybook, there should be no state involved with this, these are just dumb components that receive props. Later, when we integrate them, weâll wrap them in containers and supply them with their props that way. In Storylite, youâll be manually setting any props
- make sure you have stories written for your sub-components (Button, TextInput, and any others you want)
- the Button component must take a
disabled
boolean prop, which when set totrue
causes the button to change its visual appearance so it is looks disabled. It should also change the cursor when hovered to the ânot allowedâ symbol (hint: see tailwind) - you must have a storylite story showing the button in itâs
disabled
state - your TextInput component should receive an optional
invalid
boolean prop. When passedtrue
the TextInput should render in a state showing the user that the input is invalid (imagine if they typedlol
for their email and tried to submit, youâd want to indicate that the input is wrong/invalid). Make sure you have a story to cover the invalid state as well. - the âLoginâ component should have a checkbox with a label that says something like âremember me for 2 weeksâ.
- both main components should take props setting the values for both input fields, which you should use in your stories. Make sure you have at least one story when there is no input, and one story where the fields are filled out (which will allow you to style the font of the text entered into the input)
- spend a little time reading
MDN about :focus styling,
as well as
the tailwind docs about the same.
Also, checkout and familiarize yourself with the css
outline-*
properties, by looking at the tailwind docs for them (look at all fouroutline-*
props) â these are really useful for hover/active/focus styline - make sure your TextInput has a focus/active state alternate styling.
- make sure your Button has a focus/active state alternate styling.
- The âLoginâ component should have an email + password text input, plus a button to submit, plus the âremember me for two weeksâ checkbox.
- The âSignupâ component should have an email, password, and button to Submit.
- When youâve got it all looking good, submit a MR, review your diffs and clean up anything you notice. Then build it to a draft url on Netlify. You should be able to see your storylite stories on netlify. Slack me the MR url and the Netlify Draft URL.