domingo, 10 de noviembre de 2013

Basic C++

Input and Output
  • A data stream is a sequence of data.
  • An input stream is data for the program to use.
    • cin is an input stream bringing data from the keyboard
    • The extraction operator (>>) removes data to be used
    • Example:
      • cin >> number_of_bars;

  • An output stream is the program's output.
    • cout is an output stream sending data to the monitor.
    • The insertion operator "<<" inserts data into cout
    • Example:
      • cout << number_of_bars << " candy bars\n";
    • Showing decimal places:
      • fixed point notion - cout.setf (ios :: fixed);
      • To specify that the decimal point will always be shown - cout.setf (ios :: showpoint);
      • To specify that two decimal places will always be shown - cout.precision (2);






Data Types
  • Type char - can be any single character from the keyword.
    • char constants are enclosed in a single quote.
      • char letter = 'a';
  • Type string - is a class, different from the primitive data type.
    • Requires the following be added to the top of the program:
      • #include <string> 
    • string are enclosed in a double quote:
      • string name = "Apu Nahasapeemapetilon";
  • Type Compatibilities - in general store values in variables of the same type.
  • Variables of type double should not be assigned to variable of type int.
  • Integer values can normally be stored in variables of type double.
  • It is possible to store char values in integer variables:
    • int value = 'A';
  • It is possible to store int values in char variables:
    • char letter = 25;
  • Values of type bool can be assigned to int variables
    • True is stored as 1 
    • False is stored as 0
  • Values of type int can be assigned to bool variables
    • Any non-zero integer is stored as true
    • Zero is stored as false







No hay comentarios.:

Publicar un comentario