=====
CS 111 - Week 10 Lecture 2 - 2025-10-30
=====
=====
TODAY WE WILL:
=====
* announcements
* several examples using if statements
* intro to C++ string class' substr methods
* prep for next class
=====
* should be working on Homework 8!
* at-least-first-attempts due by 11:59 pm on Friday, October 31!
* MEET WITH YOUR ADVISOR(S)!
* RE-CREATE your DARS plan!
* get ready to REGISTER for SPRING 2026 between November 10-21!
* CS and SE majors:
* in Spring 2026, you should take:
CS 112 - CS Foundations 2
Math 253 - Discrete Math
* You CAN take Math 101T - Trigonometry and Math 253 CONCURRENTLY
* You CAN ask to switch to another ENGL 103 section if it conflicts
with a major requirement such as CS 112 or Math 253 that you need to
stay on-track in your major!
=====
* reviewed C++ if-statement syntax,
using postings simplest-if.pdf, else-if.pdf, and
if-else-if-pattern.pdf
=====
* if you have a choose-exactly-one-of-3-or-more situation,
after you finish writing your tests
you COULD write a template as follows:
if ()
{
}
else if ()
{
}
else if ()
{
}
...
else
{
}
=====
another useful string class method:
substr
=====
* 2-argument version:
expects a (0-based) position to start and that number of
characters to grab starting at that position,
and returns a string containing those characters from
the calling string
* 1-argument version:
expects a (0-based) position to start
and returns a string containing the characters from
that position to the end of the calling string
=====
QUESTION: what is the difference between:
const string DB_INTRO = "CS 325";
DB_INTRO.at(4) == '2' // returns the char '2'
DB_INTRO.substr(4, 1) == "2" // returns a string with contents equiv to "2"
* we'll see that sometimes we would prefer a char!
(for example, for use with another C++ branching statement we will
be discussing soon)
* and sometimes we prefer a string!
(for example, to be able to use + to concatenate the result to another
literal char or char*)