Straight-Line Computation in C++

Steven Zeil

May 25, 2013

Course Home   e-mail

Read chapters 1 and 2 of your text, if you have not already done so.

Chapter 2 of your text takes off at a pretty good pace. Don’t worry if not everything in there is clear right now – it’s really intended as an overview and we’ll be revisiting a lot of it in more detail later.

At its most basic, a program is a collection of instructions for manipulating data. Data comes in many different types in C++, and you will eventually see that one of the language’s strengths is in allowing you to define new types of data of your own.

Similarly, there are many different kinds of instructions that we can issue to manipulate data. More importantly, however, we can arrange instructions in varied and subtle ways. Just like when you follow someone’s directions on how to drive to a destination, or try to carry out a recipe when cooking, or when following an instruction booklet to assemble something, sometimes the instructions are simple and straightforward ("Go straight on down the road. You can’t miss it!", "Insert tab A into slot B") or moderately complicated ("Turn right at the schoolhouse, then go to the next light, make a U-turn, come halfway back", "Bake at 350 for one hour or until the internal temprature reaches 165 degrees") or downright complicated ("Bake for longer at high altitudes. Reduce baking time if using a glass pan.").

In programming, the simplest way to arrange instructions is in a "straight line" computation so that we do the first instruction, then the second, then the third, and so on, never varying the order. That’s our goal for this section.

1 Data Types
2 Assignment Statements
3 Examples of Straight-Line Computations
 3.1 Farenheit to Centigrade
 3.2 Quadradic Formula

[Previous]