Notes for Day 3

Notes on Section 2.1

Terms

  • Variable

  • Value

  • Identifiers

  • Declare

  • Assignment

  • Initializing

Syntax

  • Identifiers may use only letters, numbers, and the symbol __ ; furthermore, they may not begin with a number.

  • Two types of variable: int and double.

  • To declare a variable “var_1” of type int: int var_1;

  • To declare multiple variables of type int: int var_1, var_2, var_3;

  • To declare and initialize a variable: double balance = 536.22;

  • Alternate method to declare and initialize: double balance(536.22);

  • To set the value of a variable after it has been declared: var_1=7;

Take Note

  • IdEntiFIerS are case-sensitive.

  • Don’t use keywords (command-words from C++) as variable names!

  • The statement balance = balance + 18.26; means that the new value of the variable balance is the sum of the old value and 18.26.

Notes on Section 2.2

Terms

  • Input Stream

  • Output Stream

  • Include directive

  • Escape sequence

  • I/O

  • Echoing the input

Syntax

Either

  • cout << "Your balance is $" << balance << ".\n";

or
  • cout << "Your balance is $";

cout << balance;

cout << ".\n";

or

  • cout << "Your balance is $" << checking + savings << ".\n";

More stuff:
  • Use #include directives to call on predefined operations. Make sure to begin every program with #include <iostream>.

  • \n produces a new line

  • \t produces a tab

  • \\ produces a single \

  • \" produces a " character.

  • endl outside quotation marks also produces a new line

  • The following lines are “magic” code which will produce two-decimal place output.

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

  • You may use either cin >> checking >> savings; or

cin >> checking;

cin >> savings;

but the former is preferable, since it gives the user more options for how to input the information.

Take Note

  • Pay attention to spaces. You need to put them inside quotation marks for them to be sent to the output.

  • End each program’s output with either a \n or an endl.

Topic revision: r1 - 2015-09-03 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback