Week 2 - Boolean Expressions and Conditionals

Learning Objectives

Upon finishing this learning module, you should be able to:

  • Use relational operators to construct simple boolean statements
  • Write a program using conditional expressions

Day 1

Day 2

Day 3

Day 4

  • Finish Conditionals - complete through Ch 3.16
  • Do BooleanPractice WS
  • Do assignment

Multiple File Sample Projects

If you look at the sample code for week 2 (from the cs161Code.zip file in the Files area of Canvas), you will notice that some project folders have extra text files with the extension ".bak" after the filename.

A  project folder with .cpp.bak files

The .bak files have alternative samples. Rather than make 3 different projects to show off 3 closely related samples, there is just one project with the different samples stored in those "backup" files.

The .bak files will not be compiled. To switch which sample you are building and running, simply copy all the code from one of the .bak files and paste it into the main.cpp file, replacing the code that was there.

Data Conversions and Other Operators

  • Read the last parts of chapter 2 (2.7, 2.11-13, and 2.16). These videos cover two of the topics, Casts and Constants:

  • Do the MentalCodeOpsCasts worksheet (see Classroom files link). Like last week, try doing in your head, then check it using the debugger.

    One of your takeaways should be that the operators like ++ and += are pretty simple if you use them on a line by themselves. But, if you mix them into more complex expressions, they quickly get very tricky:

    z += y /= --x + 6;  //valid but insane c++
    

CPPLab

We will be using a website called CPP Lab to be getting programming practice.

Follow this guide to get logged into CPPLab and learn about it.

Some of the problems are easy, some are hard. Your goal should be to attempt all the problems in each problem set and, hopefully, complete all of them. But if you get stuck, don't spin your wheels for hours trying to solve a particular problem. Move on to something else and get help with that one.

Conditionals

  • Read Ch 3.1-3.4. This video introduces some of the key concepts:

  • Watch this video on the concept of Scope:

  • Do Conditionals 1 CPP Lab

  • Read Ch 3.5-3.8. This video introduces some of the ideas:

  • Do Conditionals 2 CPP Lab .

  • This video demonstrates using the debugger to trace your way through the computer tax example:

  • Read Ch 3.10-11 and 3.13-16.
    Note: you do not need these parts of Chapter 3 to do the assignment or CPPLabs. Next week involves less material, if necessary you can worry about mastering these section next week.
    These videos cover the basics of those sections:

  • Do the Boolean Practice worksheet (Remeber that the Files link in Elearn/Canvas is where you can access this and future worksheets).

  • Do the assignment.