Week 2 - Floating Point Values and Math Functions

Learning Objectives

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

  • Write programs that use floating-point variables to represent real numbers
  • Use library functions to do math calculations
  • Build and run a program from the command line

Day 1

In class:

  • Floating points and math weirdness

For next class:


Day 2

In class:

  • Introduce math functions

For next class:


Day 3

In class:

  • Wrap up Ch 4
  • More Ch 4 exercises

For next class:

  • Finish Floating Points and Math Functions
  • Do Ch 4 exercise set 2
  • Check out assignment 2. Warning - it involves math. There are worked samples of everything you will need to do. But if math isn't your strong suit, make sure to read through the samples early and ask questions if you need help understanding them.

Day 4

In class:

For next class:

  • Work on assignment 2

Floating Points and Math Functions

Work through Chapter 4 of the book.

These videos review key concepts from the chapter. (They are not required, and do not cover everything, but may help to reinforce the material.)

Type Conversions (4.5):

Constants (4.7):

Common gotchas with math in C++:

Using Math Functions (4.8-4.9):

Math Function Tour (4.10-4.13):


Command Line Basics

Before there were windows and mice, the way we interacted with computers was all based on text input into consoles (like the programs we are currently writing). Many tools programmers use work on the command line (behind the scenes, VSCode is using text-based commands to call the compiler) - learning to use the command line is essential.

Although most of the time we will be using programming environments like GitHub Codespaces or Visual Studio Code, it is important to understand how to build and run programs from the command line. As you move on to more advanced programming, you will often need to use the command line to do things that are not supported by your programming environment.

These videos demonstrate the basics:

This Command Line Guide provides detailed instructions for how to open a command prompt, set up the path, navigate, and use g++.

For a more detailed treatment read either this Windows command line guide (up to 2.6). or this Mac/Linux command line guide (up to 3.5).