In-class Examples List
CS 111 - Computer Science Foundations 1
Section 10 - CRN 41046 - TuTh 9:00am-10:20am
Fall 2024
Last modified: Sunday, December 15, 2024
Important Notes:
- This is merely a selection of files and examples, most of which were
mentioned or used in the class (lectures and labs). It is not a
comprehensive
list, nor are all lectures and labs included. Formatting is generally
minimal.
- EXTRA example: the promised example adding a variation of
function
get_waffle_order named
get_waffle_order_2, that expects an array of
available waffle toppings and its size instead of
"hard-coding" the available waffle toppings
- Week 15 - Labs, 2024-12-13 - review clicker questions
followed by a lab exercise
- Week 15 - Lecture 2, 2024-12-12 - review for Final Exam
- Week 15 - Lecture 1, 2024-12-10 -
intro to several C++ "shorthand" operators,
+= -= *= /=
and ++ --; intro to the classic C++ for
loop
- Week 14 - Labs, 2024-12-06 - review clicker questions
followed by a lab exercise
- Week 14 - Lecture 2, 2024-12-05 - finished the function
get_smallest, and introduced the basics of
C++ stream-based file input/output
-
111lect14-2-projected.txt -
In-class projections
- 111lect14-2.cpp -
completed version of our function from Week 14 - Lecture 2,
tested in the
main function at the end; the main
alwo includes demos of writing to and reading from a file
-
get_smallest - a function that has an array
parameter (amongst its two parameters)
- NOTE: you can do
file input/output within a
non-
main function, also! We just
happened to demo it from
a main function!
- Additional discussion and examples of file input and output,
although they do things a bit differently in places
(in particular, do NOT use
break
like they do
here...! You will lose points if you do.)
Week 14 - Lecture 1, 2024-12-03 - continued intro to
arrays, including designing our first function with an array
parameter
-
111lect14-1-projected.txt -
In-class projections
- 111lect14-1.cpp -
our function from Week 14 - Lecture 1, tested in the
main function at the end
(and started design recipe for another function we'll
finish in class on Thursday):
-
sum_array - a function that has an array
parameter (amongst its two parameters)
- from Runestone's "C++ for Python Programmers",
https://runestone.academy/ns/books/published/cpp4python/index.html
- NOTE: this text's examples do
not always follow the required CS 111 style/coding
standards!
- Section 5.2 - Arrays
Week 13 - Labs, 2024-11-22 - review clicker questions
followed by a lab exercise
Week 13 - Lecture 2, 2024-11-21 - a few words about
pseudocode;
"walking" through a string
using a while statement; started intro to
arrays
-
111lect13-2-projected.txt -
In-class projections
- 111lect13-2.cpp -
our function from Week 13 - Lecture 2, tested in the
main function at the end;
main function also includes some interactive
input, calling a function with side-effects in a couple
of different ways, and playing a bit with arrays
-
vertical - uses a
while loop to loop through
characters in a string, printing them each on their
own line as its side-effect, and returns the
given string's length
- from Runestone's "C++ for Python Programmers",
https://runestone.academy/ns/books/published/cpp4python/index.html
- NOTE: this text's examples do
not always follow the required CS 111 style/coding
standards!
- Section 5.2 - Arrays
Week 13 - Lecture 1, 2024-11-19 - intro to
our first C++ iterative repetition statement,
the while statement/loop
-
111lect13-1-projected.txt - In-class projections
- while loop
flow chart - (as a PDF image);
includes
while loop syntax, along with
a flow-chart showing while loop semantics
- 111lect13-1.cpp -
our functions from Week 13 - Lecture 1, which are tested
in the
main function at the end:
-
cheer - a function with side-effects,
printing a cheer to the screen, that
uses a while loop
-
sum_ints - a regular function that
uses a while loop to compute the sum of
the positive integers from 1 to a specified value
- from Runestone's "How to Think Like a Computer Scientist - C++
Edition" - NOTE that some of the terms are a little different,
and the examples don't all follow CS 111 course style standards,
BUT I think the discussion and interactive exercises could still
be useful:
Week 12 - Labs, 2024-11-15 - review clicker questions
followed by a lab exercise
Week 12 - Lecture 2, 2024-11-14 - Exam 2
Week 12 - Lecture 1, 2024-11-12 -
continued intro to local variables, assignment statements, and
mutation; discussed more about
interactive input using cin;
worked through a waffle-order example featuring
local variables, interactive input, and a sequence of
if statements (for a 0-or-more choices situation!)
-
111lect12-1-projected.txt - In-class projections
- 111lect12-1.cpp -
our function from Week 12 - Lecture 1, tested in the
main function at the end:
-
get_waffle_order - which uses local variables,
interactive input, and a sequence of if statements
to handle a 0-or-more-choices situation
- from Runestone's "How to Think Like a Computer Scientist - C++
Edition" - NOTE that some of the terms are a little different,
and the examples don't all follow CS 111 course style standards,
BUT I think the discussion and interactive exercises could still
be useful:
Week 11 - Labs, 2024-11-08 - review clicker questions
followed by a lab exercise
Week 11 - Lecture 2, 2024-11-07 - review for Exam 2;
continued intro to local variables, assignment
statements, and mutation
-
111lect11-2-projected.txt - In-class projections
- Exam 2 Review
Suggestions (in tagged PDF)
- from Runestone's "How to Think Like a Computer Scientist - C++
Edition" - NOTE that some of the terms are a little different,
and the examples don't all follow CS 111 course style standards,
BUT I think the discussion and interactive exercises could still
be useful:
Week 11 - Lecture 1, 2024-11-05 -
intro to the C++ switch statement;
started intro to local variables, assignment
statements, mutation, and a little interactive input using
the cin object
-
111lect11-1-projected.txt - In-class projections
- 111lect11-1.cpp -
our function from Week 11 - Lecture 1, tested in the
main function at the end; the main function
also includes an example using the cin object
for interactive input along with a local variable:
-
describe_grade - which uses a switch
statement
- from Runestone's "How to Think Like a Computer Scientist - C++
Edition" - NOTE that some of the terms are a little different,
and the examples don't all follow CS 111 course style standards,
BUT I think the discussion and interactive exercises could still
be useful:
-
https://stackoverflow.com/questions/97987/advantage-of-switch-over-if-else-statement - interesting Stack Overflow answer discussing
thoughts on when to use
switch and when to use
if-else-if pattern - with thanks to Casey Cooper!
Week 10 - Labs, 2024-11-01 - quick intro to string
class method substr, review clicker questions,
and a lab exercise
Week 10 - Lecture 2, 2024-10-31 -
branching in C++, continued; several functions using
if statements, including using the
if-else-if pattern; reminder of the
string class at method
-
111lect10-2-projected.txt - In-class projections
- 111lect10-2.cpp -
our functions from
Week 10 - Lecture 2, with the
new functions tested in the
main function at the end:
-
next_sound - C++ version of Week 4 - Lecture 2
Racket function next-sound, and involves
enumeration-style data
-
porridge_state - which happens to involve
interval-style data
-
name_length - copied from Week 10 Lecture 1,
so can use it in pretty_name_2 below
-
pretty_name_2 - which uses an if
statement and the string class at
method
Week 10 - Lecture 1, 2024-10-29 -
another kind of C++ compound
expression: calling a method of a class;
concept of a C++ block;
intro to the C++ if statement
-
111lect10-1-projected.txt - In-class projections
-
111lect10-1.cpp -
our functions from Week 10 - Lecture 1, tested in the
main function at the end, and also a
little additional "playing around" in the main function:
-
name_length -
which calls a string
method, length
-
abs_value - which uses an
if-else
statement, and involves interval-style data
-
https://cplusplus.com/reference/string/string/ -
cplusplus.com's reference page for the C++
string class
Week 9 - Labs, 2024-10-25 - review clicker questions
followed by a lab exercise
Week 9 - Lecture 2, 2024-10-24 -
more examples of C++ (non-main) functions,
designed using the design recipe and run and tested using CS50
IDE
-
111lect09-2-projected.txt - In-class projections
-
111lect09-2.cpp -
our non-
main functions from Week 9 - Lecture 2, tested in the
main function at the end:
-
circ_area - which returns a double
value
-
grade_in_range - which returns a
bool value
-
pretty_name -
which uses + to append
string instances (also works with
char* and char
as long as at least one
of its operands is type string!)
- (the function
main also demos using
cout to print to the screen the values of
desired expressions besides test expressions; do NOT
confuse that with a function RETURNING
a value!)
- 111template.cpp -
PASTE this first
.cpp file template INTO a
.cpp file
in the CS50 IDE at
https://cs50.dev
-
C++ "graphic design recipe helper" - as a color PDF -
a C++ version of a more-graphical depiction of the
Design Recipe
Week 9 - Lecture 1, 2024-10-22 - continuing intro to C++;
review of C++ identifier syntax;
syntax to define a C++ named constant;
review of kinds of C++ compound expressions;
STARTED walk-through of C++ (non-main) function
syntax in DESIGN RECIPE order (and will finish this
in class on Thursday)
Week 8 - Labs, 2024-10-18 - review clicker questions,
quick discussion of C++ compound expression syntax for
parentheses, followed by a lab exercise
Week 8 - Lecture 2, 2024-10-17 - starting intro to C++;
definition of a C++ program;
intro to the
idea of a compiler (as compared to an interpreter);
intro to C++ simple expressions and basic data types;
intro to some of C++'s kinds of compound expressions;
and syntax of a C++ identifier
Week 8 - Lecture 1, 2024-10-15 - Exam 1
RECORDED Week 7 Lecture 2, recorded for October 10, 2024 -
a few more list-related functions
- See Canvas Modules, Class Recordings, for Zoom recording
walking through
creating the functions below
-
111lect07-2.rkt -
DrRacket Definitions
window from recorded example; includes the functions:
-
string-list-smush
-
make-greet-list
-
say-hi
-
draw-strings-randomly
-
return-current
-
add-string
-
change-string-list
- 111-names.txt -
used in
111lect07-2.rkt
above
- greetings.txt -
used in
111lect07-2.rkt
above
Additional list function example: string-list-smush
- See Canvas Modules, Class Recordings, for Zoom recording
walking through
creating the function
string-list-smush
below
-
111lect06-2-string-list-smush.rkt -
DrRacket Definitions
window from recorded example; includes the functions:
-
string-list-smush
-
make-greet-list
-
say-hi
- 111-names.txt -
used in
111lect06-2-string-list-smush.rkt
above
Week 7 - Lecture 1, 2024-10-08 - review for Exam 1
Week 6 - Labs, 2024-10-04 - review
clicker questions followed by a lab exercise
Week 6 - Lecture 2, 2024-10-03 -
writing to a file using BSL Racket's 2htdp/batch-io
module, and more examples of functions that "walk through" a list
-
111lect06-2-projected.txt -
In-class projected notes
- IMPORTANT: after writing your tests
for a function that "walks through" a list, actually
PASTE IN the template for a function that "walks
through" a list into your function body, then
EDIT that template!
-
111lect06-2.rkt -
DrRacket Definitions
window from class; includes trying out some
file input/output, as well as recursive functions:
-
make-greet-list (which uses function
say-hi)
-
grab-strings
- 111-names.txt -
used in 111lect06-2.rkt above
Week 6 - Lecture 1, 2024-10-01 -
intro to lists, continued;
intro to template for a function that needs to
"walk through" a list;
examples of functions that use this to "walk through" a list;
quick intro to 2htdp/batch-io
file input/output module's read-lines function
Week 5 - Labs, 2024-09-27 - changing the ticker's
speed for a big-bang expression; review
clicker questions followed by a lab exercise
Week 5 - Lecture 2, 2023-09-21 -
concept of a data
structure;
started discussion of our first data structure, the BSL
Racket list
type, and introduced several built-in functions
that work with lists
Week 5 - Lecture 1, 2024-09-24 -
intro to big-bang's on-key clause;
intro to itemization data, and describing such
data using data definition
comments; also an after-class example of throwing an error
and writing a test for that
-
111lect05-1-projected.txt -
In-class projected notes
- The penguin images used in today's examples:
(originally from
http://wallofgame.com/free-online-games/arcade/231/Parachute_Penguin_Shootout.html):
-
111lect05-1.rkt
- DrRacket Definitions
window from lecture; includes functions:
- (from Week 4 Lecture 2)
draw-penguin-scene
-
change-elevation
-
double-it
-
111-error-throwing-and-testing-demo.rkt
- AFTER-CLASS example of how to throw an error
in BSL Racket, and write a test using
check-error to test it without halting
your program prematurely
Week 4 - Labs, 2024-09-20 - review
clicker questions followed by a lab exercise
Week 4 - Lecture 2, 2024-09-19 -
example of refactoring;
"falling" penguin example using
cond; discussion of interval-style data and
enumeration-style
data; walked through an example using enumeration-style data
-
111lect04-2-projectede.txt -
In-class projected notes
- The penguin images used in today's examples:
(originally from
http://wallofgame.com/free-online-games/arcade/231/Parachute_Penguin_Shootout.html):
-
111lect04-2.rkt
- DrRacket Definitions
window from lecture; includes functions:
- (from earlier classes)
teal-star,
teal-star-scene
-
bad-star-size?
-
draw-penguin-scene
-
next-sound
Week 4 - Lecture 1, 2024-09-17 -
what is refactoring; intro to cond
(conditional/branching) expression; demo of big-bang
function's stop-when clause
-
111lect04-1-projected.txt -
In-class projected notes
-
111lect04-1.rkt
- DrRacket Definitions
window from lecture; includes functions:
-
teal-star - from Week 2 Lecture 2
-
teal-star-scene - refactored
from Week 3 Lecture 2 version
-
banana-report
Week 3 - Labs, 2024-09-13 - quick intro to check-within,
review clicker questions, and a lab exercise
Week 3 - Lecture 2, 2024-09-12 -
continued intro to type scene;
example using the design recipe to write a function
that returns a scene instance;
intro to the big-bang function from the module
2htdp/universe
Week 3 - Lecture 1, 2024-09-10 - two more examples of designing
functions using the design recipe: humboldt-logo
and doubt-it; started intro to Racket's
scene type
Week 2 - Labs, 2024-09-06 - review clicker questions and a
lab exercise
Week 2 - Lecture 2, 2024-09-05 -
more intro to identifiers; more intro to named constants;
intro to
check-expect; intro to writing your own
functions and to the DESIGN RECIPE
-
111lect2-02-projected.txt -
In-class projected notes
- DISPLAY-ONLY HTML version of
111lect02-2_rkt.html from class;
save and execute this version below
("Save Link As..." to get a
copy on your computer, should then be able to double-click
on that or open it from DrRacket to run it):
111lect02-2.rkt
includes our first Racket functions written using
the design recipe:
Week 2 - Lecture 1, 2024-09-03 - more examples of
built-in Racket functions
that can be used in compound expressions;
intro to function signature and
purpose statement comments;
and started introducing identifiers, and
defining a name to have a value (a named constant)
Week 1 - Labs, 2024-08-30 - practice
clicker questions, intro to pair programming, and a lab exercise
Week 1 - Lecture 2, 2024-08-29 - continuing intro to DrRacket
programming environment; four basic BSL (Beginning Student Level)
Racket data types, and syntax
for literal simple expressions of those types; intro to
BSL Racket compound expressions
Week 1 - Lecture 1, 2024-08-28 - intro to course; just started intro
to DrRacket programming environment; definitions of syntax and
semantics
Back to Course Home Page