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

  • Holiday - finish up anything leftover from last week

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 CS161 git repository, 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.

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:

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

  • Check out the assignment - you should know enough to do it at this point. The rest of this week's material has tricks you might choose to use, but do not need.

  • Read Ch 3.10-11 about the Logical Operators || and &&. These are important ideas and although you don't need them to do the assignment or CPPLabs, they may help you write cleaner code. This video covers the basics of those sections:

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

  • Do Conditionals 2 CPP Lab .

  • Read Ch 3.13-16. These sections cover some ideas that you should know about, but almost certainly won't need to use this week. These are things you should recognize if you see. But you do not need to worry about using these in your code for now. Focus on writing code using the other ideas from the week before worrying about mastering these "extra" tricks.