=====
CS 111 - Week 12 Lecture 1 - 2024-11-12
=====
=====
TODAY WE WILL:
=====
* announcements
* continue with local variables & interactve input
* prep for next class
* important upcoming schedule notes!
* TODAY - TUESDAY, November 12
* graded Exam 1s were returned during class
(so you can look over them before taking Exam 2!)
* continue discussing LOCAL VARIABLES and related topics
* ALSO: have your final versions of
Homeworks 7-9 submitted
by 11:59 pm on TUESDAY, November 12,
* WEDNESDAY, November 13
* ...so example solutions can be posted
for Exam 2 study purposes by
12:01 am on WEDNESDAY, November 13
* Raul, CS 111's Learning Assistant,
will give an EXAM 2 REVIEW SESSION on WEDNESDAY, November 13,
in BSS 302 from 3:00 - 5:00 pm
* THURSDAY, November 14 -
* Exam 2 study guide *bonus* is due by 9:00 am on Canvas
* Exam 2 given in class (in GH 218) from 9:00 - 10:20 am
* Friday, November 15 - there WILL be a lab exercise!
* and Homework 10 will come out after this
====
STYLE POINT:
====
* now that we are trying out changing the values
in local variables...
* it is considered POOR STYLE to change the value
of a function's parameter within the function body
(except for SPECIAL cases we will discuss,
and will NOTE in the purpose statements of such functions)
=====
* quick reminder:
* the C++ iostream library creates both the objects
cout and cin
* cout is an output stream object! connected by default
to standard output! (typically a console, or in the CS50 IDE
a Terminal)
* cin is an input stream object! connected by default
to standard input! (typically keyboard input)
* stream? thinking of input or output as a STREAM,
as a sequence, of characters;
* we can have the side-effect of writing to standard output
by using cout and the << operator, and the expression whose
value we wish to print:
cout << desired_expr;
* the value of desired_expr will be written to standard
output, using cout's default formatting for a value of
that data type
* we can have the side-effect of reading from standard input
by using cin and the >> operator, and the local variable
or thing-you-can-assign-to you wish to be filled with the result:
string sound;
cout << "enter an animal sound: ";
cin >> sound;
* BUT: when using cin with >>,
HOW MUCH it reads (from the standard input stream, from
the keyboard) can be effected by the TYPE of the
local variable being read into!
* cin with >> and a string variable
STOPS at a blank, tab, or newline character;
if for the above you typed
la la la
...sound would contain JUST "la"!
* what if you WANT to read a blank? (really, what if you
want to read everything typed until typing enter/return?
until typing essentially a newline?)
* iostream provides a function named getline
that expects an input stream object and a string variable
and has the side effect of reading everything from that
input stream up until the next newline character,
and converts it to a string object and assigns it to
the given string variable
string longer_sound;
cout << "enter an animal sound: ";
getline(cin, longer_sound);
// NOW if the user enters
la la la
// ... longer_sound WILL contain "la la la"!
=====
BLOBBING into combinations of waffle toppings,
and here's the combos we ended up with:
=====
* NO toppings!
* chocolate chips
* maple syrup
* fruit and honey
* fruit
* chocolate chips, butter, maple syrup, and whipped cream
* peanut butter and bananas
WHAT IF ... we wanted a function that would
ASK a user about desired toppings,
and return a string containing their resulting
waffle order? With ZERO or ALL or SOME of the
above toppings?
* see function get_waffle_order in 111lect12-1.cpp
to see our FIRST version of this,
* using a SEQUENCE of if statements
(because 0 or more of these choices may be
made)
* using local variables
(to "build" a waffle order and to hold the
user's answers)
* and using interactive input to get the user's
answers;
(also our first example of how testing gets...
even *more* INTERESTING when side-effects are involved!)