COSC 1320 C/C++ Programming

Course Introduction
  1. Syllabus
  2. Overview of C++
  3. Math Review
    While this is not a math course you should be famaliar with the following concepts:
    1. Numbers
      1. Cardinals 1,2,3
      2. Natural 0,1,2,3
      3. Integers -3,-2,-1,0,1,2,3
      4. Rational
      5. Irrational
      6. Complex
    2. Operations
      1. Addition
      2. Subtraction
      3. Multiplication
      4. Division
      5. Powers
    3. Base Conversion
      1. Any base to Base 10
      2. Base ten to any base
      3. Binary to Octal
      4. Binary to Hex
      5. Hex-Octal Conversions
  4. Programming Review
    Since this is the second programming course you should have knowledge of each of the following concepts:
    1. variables
      1. storage
      2. typing
      3. scalar
      4. arrays
    2. Logic constructs
      1. sequence
      2. selection
      3. iteration
    3. subroutines
      1. scope of variables
      2. parameters
      3. recursion
    4. file I/O


C/C++ Syntax
  1. Character set
      a .. z
      A .. Z
      0 .. 9
      ! # % ^ & * ( ) - _
      + = ~ [ } \ | ; : '
      " { } , . < > / ?
    
  2. Comments
    Any sequence that begins with /* and ends with */. Or starts with // to the end of the line. C++ ignores anything within comments. Comments may not be nested.

  3. Tokens
    The lexical structure of a C++ programs is divided into 5 classes
    1. Operators
      !	%	^	&	*
      -	+	 = 	~	|
      .	<	>	/	? :
      ->	++	--	<<	>>
      <=	>=	==	!=	&&
      ||	+=	-=	*=	/=
      %=	<<=	>>=	&=	^=
      |=	->	::
      
    2. Separators
       ( ) [ ] { } , ; :
      
      and a blank.

    3. Identifiers
      A sequence of letters and digits and underscores, which is not a reserved word. Must start with a letter. Note case is important. Identifiers may either be variable, structure, class or function names.

    4. Reserved words
      asm auto break bool case catch char class
      const const_class continue default delete do double
      dynamic_cast else enum explicit extern
      false float for friend goto if inline int long mutable
      namespace new operator private protected public
      register return short signed sizeof static static_cast struct
      switch template this throw true try typedef
      typeid typename union unsigned using virtual void
      volatile wchar_t while

    5. Constants
      1. Integer
        whole numbers specified in the program.
      2. Octal
        preceded with 0 as in 077
      3. Hex
        preceded with 0x as in 0xa7
      4. Floating point
        1.0
        1.0e3
        2e+9
        
      5. Character
        enclosed in single quotes. special sequence with \
        \n  newline
        \t  horizontal tab
        \v  vertical tab
        \b  backspace
        \r  carriage return
        \f  formfeed
        
      6. String
        constants are enclosed in double quotes like "hello".
  4. A C++ program
    is made up of expressions and statements. Statements are terminated with a semicolon (;) or compound statements are enclosed in { }.
    1. Expression
         x++
      
    2. Simple statement
         x++:
      
    3. Compound statement
      {
          x++;
          y--;
      }
      

  5. C++ Functions
    The general format of a C++ function is:
     function_name (formal argument list)
     {
      body of function
     }
    
    Every C++ program MUST have at least one function called main. This function receives control from the Operating system and is executed first. The simplest program given in most C++ texts is the ubiquitous Hello World.
    #include <iostream>
    
    using namespace std;
    
    void main()
    {
      cout << "Hello World" << endl;
    }
    


© Allan Kochis Last revision 8/26/2002