Thursday, November 14, 2013

C++ Class 1: Some Basic Concepts

What is a Computer?

  • A computer is an electronic device that can follow instructions to
    • Accept input (data)
    • Process that input
    • Produce output (information)
Data is raw, unorganized facts that need to be processed. Data can be something simple and seemingly random and useless until it is organized.
For Example:
Each student's test score.

When data is processed, organized, structured or presented in a given context so as to make it useful, it is called Information.
For Example:
The class' average score or the school's average score.

  • A computer is an electronic device, operating under the control of instructions (software) stored in its own memory unit, that can accept data (input), manipulate data (process), and produce information (output) from the processing.
  • Generally, the term is used to describe a collection of devices that function together as a system.

What does a Computer do?

  • Computers perform four general operations, which make up the information processing cycle
    • Input
    • Processing
    • Output
    • Storage

Devices that comprise a Computer System

  • Monitor (output)
  • Speaker (output)
  • Printer (output)
  • System Unit (processor, memory)
  • Scanner (input)
  • Keyboard (input)
  • Mouse (input)
  • Storage Devices (CD-RW, Floppy, Hard disk etc)

Introduction to C++ Programming

The Computer
The Computer: "I only know Binary 0s and 1s"

The Programmer
Programmer writes a 'set of instructions' for Computer. This set is called a 'Computer Program'

Programming Languages

  • Programmers write these instructions in different programming languages.
    • Directly understandable by Computer
      • Machine Languages
    • Requiring intermediate translation steps
      • Assembly Languages
      • High Level Languages
  • Machine Languages
    • Strings of 0s and 1s
    • Directly understandable by computer
    • Defined by hardware of the machine
    • Hard for human beings to learn, error prone
    • Slow Programming
  • Assembly Languages
    • English like abbreviations
    • Not directly understandable by computer, hence required translator programs called 'Assemblers'
    • Relatively easier for human beings to learn
    • Slightly faster programming
  • High Level Languages
    • Developed for fast and speedy programming
    • Not directly understandable by computer, hence required translator programs called 'Compilers'
    • Not dependent on hardware of the machine (mostly)
    • Easy to learn, less chances of error
    • Fast programming
Interpreters are another important category of translator programs.

Why C++

  • C is a language designed by and for programmers
  • C++ is an expanded and enhanced version of C Programming Language
  • It is the language of choice for professional programmers worldwide
  • Once mastered, C++ will give you complete control over the computer
  • C++ is, above all, the most powerful programming language even invented


1: C++ Program (Created with text editor or development environment):
int main()
int i=1;
    . . .

2: C++ Compiler:
e.g. g++

3: Machine Language Program

Basics of a Typical C++ Environment

  • C++ Systems
    • Program-development environment
    • Language
    • C++ Standard Library
  • Phases of C++ Programs
    • Edit (Program is created in the editor and stored on disk.)
    • Preprocess (Preprocessor program processes the code.)
    • Compile (Compiler creates object code and stores it on disk.)
    • Link (Linker links the object code with the libraries, creates a.out and stores it on disk.)
    • Load (Loader puts program in memory.)
    • Execute (CPU takes each instruction and executes it, possibly storing new data values as the program executes.)

The C++ Standard Library

  • C++ programs consist of pieces/modules called classes and functions
    • A programmer can create his own functions
      • Advantage: the programmer knows exactly how it works
      • Disadvantage: time consuming
    • Programmers will often use the C++ library functions
      • Use these as building blocks
    • Avoid re-inventing the wheel
      • If a pre-made function exists, generally best to use it rather than write your own
      • Library functions are carefully written, efficient, and portable



Copyright @ 2014 CPP Fuzz.