Week 1 - Introduction to C++ Programming

Learning Objectives

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

  • Describe how a C++ program goes from source code to working program
  • Identify the functions of basic components of a C++ program
  • Do basic console input/output
  • Use assignment and the basic math operators

You have a lot of freedom to choose when you get the work done each week. But trying to do all of your learning in one monster day of studying tends to be much less effective than working on smaller chunks of the material more often. The recommended schedule for each week is designed to help you break up the work and practice as you go.

Although the major assignments are always due at the start of next week, there are often mid-week deadlines for other work (check Canvas for all due dates), so you can't wait until the weekend to get everything done.

If your schedule requires you to do most of your work for this class on the weekend, you should try to work ahead on the next week each weekend rather than playing catchup from the previous week. That way you have plenty of time to ask questions and get any needed help before your assignments are due.

Day 1

Day 2

Day 3

Day 4

Course Intro

Review the Syllabus (in eLearn) Background survey and Class Policies quiz in eLearn. The Class Policies quiz can be taken as many times as you like before the deadline. Make sure to get 100%!

CS Background

Read Ch 1.1-1.4. If you took CS160 it will mostly be review. If not, don't panic about memorizing every detail. Just skim for an overview of how software and computers work.

Set up Software

Start by installing and setting up the software for this course.

Then, get your own copy of the course's code samples. They are available using git, the same version control software you will have just installed to use for recording work histories. You can clone a copy of the code samples with a command like this, which will create a new directory named cs161Code in the same directory where you run it.

git clone https://github.com/ChemeketaCS/cs161Code.git

If you prefer, you can instead download a zip file of the repository's current contents.

This video explains how to use VSCode to work with project folders and provided code samples.

All code you submit must build using standard C++. Using VSCode and our project templates will help make sure you write code that will be acceptable. It will also make it easier to test out provided code samples.

The setup we provide and suggest will also automate storing your work history as you work on assignments.

If you try to use another tool for programming it is going to be up to you to make sure you are generating code that works correctly when I run it. "It worked on my computer" is not sufficient. You also will be responsible for manually creating your work history. Start with VSCode and learn to use it until you are very comfortable with building and running C++ code by hand (which will be later in course). At that point, you can experiment with other editors if you like.

C++ & Development Basics

Work through Ch1.6-1.9. This video has a quick overview of what the parts of a very basic program do:

Some of the videos in this course were made using a different IDE (QTCreator). It functions basically the same as VSCode. If you can't figure out how to do something you see in VSCode, please raise the issue in the discussion forum.

For any video, you can click in the lower right corner to watch on YouTube. You can then use the settings icon there (Gear symbol at bottom of video) to watch at higher quality. Doing so can make a big difference when trying to read code examples.

Errors and Warnings

When you have a mistake in your code, it can sometimes produce an error or a warning. A build error prevents the code from building. A warning is a piece of code that can be compiled, but may not actually do what you want. This video shows how to see errors and warnings:

Variables and Math

Read 2.4-2.6 and watch this video:

The Debugger

The debugger is a CRITICAL tool for learning programming. It is what lets you look at what your code is doing step by step. This video introduces it:

Do the MentalCode worksheet to practice using the debugger and test your understanding of how math works in C++ (See the Files link in Elearn/Canvas to access this and future worksheets). There is a key you can use to check your work on the front of the sheet. The back you should be checking with the debugger!

Math Weirdness

Once you are done with it, watch this video about some of the weird answers:

Program Input

Now you should loop back and read 2.1-2.3 if you haven't. This video reviews key bits about getting input:

Writing Programs the Right Way

Start the assignment as you finish 2.8-2.10 and 2.14 and 15. This video talks through building the time program from 2.10 to show how you should approach building programs... one step at a time:

About Assignments

Your weekly assignment is in Canvas. As part of the first assignment, you should make sure to read this document about the work history you must submit as part of every assignment.

Data Conversions and Other Operators

This material you are NOT responsible for using in the first assignment. So feel free to get the assignment started before you study this. But you will need to know this information in future weeks, so do make sure to go over it.

  • 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++
    

Extra Info

Compiling details

Looking for more information on what exactly happens when code is compiled? Read this compiling and linking tutorial.