by Forest J. Handford

This chapter is geared to people who have never programmed in C++ and those who have never programmed at all.

The Basics - C++ is a procedural and Object Oriented Programming (OOP) language.  What does that mean to us?  Not much at the moment!  Let's start with the concept of procedural programming.  We will get to OOP in a later chapter.

Procedures - Procedural programming is a way to divide a program up into segments.  In C++ these segments are called functions.

Languages like C++, Java and F are all OOP languages.  OOP is currently considered the best type of programming languages.  Before OOP, procedural languages like PASCAL and C were considered the greatest type of programming language.


Most parts of a C++ program is written in class definitions and functions.  We will get to classes in a later chapter.

Your first C++ program:

<Code> <Program>

#include <iostream.h>

void main()
{
    cout<<"Game programmers are huggable!"<<endl;
}

The above code will print "Game programmers are huggable!" followed by a carriage return, a carriage return is a line break on a screen or printer.  The code is usable in any C++ standard compiler.  The compiler I will use throughout this tutorial for samples is Microsoft C++ 4.  This program could also work in a Borland or GCC compiler.

The first line of code opens a header file.  The file defines the cout class.  This allows us to use the line that starts with cout, cout is used for text output.  You can send any text to it.  This header also provides other standard I/O stream capabilities.

The I/O stream consists of all input and output devices.  Some input devices commonly used are scanners, keyboards, mice, and modems.  Some output devices are screens, printers, speakers, and modems.


#include <header.h> is the way to access any header that is in your compilers library.  In a later chapter I'll teach you how to create your own header file.

void defines the type of function main is.  A void function returns no value to what ever called it.  An int function would return an integer value.

After the name of the function you must type "()" followed by a "{".  All "{" brackets must have a corresponding closing "}" bracket.  All lines of code must end with a ";".  Lines of code can have an unlimited amount of empty spaces and carriage returns.  Spaces and carriage returns are ignored by the compiler unless they are within a string.  A compiler reads C++ code and re-writes it first into assembly language and then machine language.

C++ IS case sensitive so be careful.  I often get errors due to incorrect capitalization.

cout is a defined class from iostream.h.  It is usually used in conjunction with the "<<" operator.  The "<<" operator and the ">>" operator are both bit shift operators.  The "<<" or left bit shift operator sends bits to the structure on the left and the ">>" is the right shift operator.  The right shift operator sends bits to the structure on the right.  The endl will create a carriage return.

The bit shift operator is important in math that we will deal with in a later chapter. All data on a computer is stored in bits.  Bits can have two values on or off.  Bits could also be considered true/false or yes/no.  Eight bits form a byte.  Characters take up eight bits or one byte.  A kilobyte (KB) is 1,024 bytes, a megabyte (MB) is 1,024 kilobytes and 1,048,576 bytes.  A gigabyte (GB) is 1,024 megabytes or 1,073,741,824 bytes.  A terabyte is 1,024 gigabytes or 1,099,511,627,776 bytes.


In C++ " are used to enclose strings.  A string is a field of characters.  The string "Game programmers are huggable!"  was shifted to cout along with endl witch will give the following output:

Game programmers are huggable!

I think that we have done enough for this chapter.  In the next chapter you'll learn about constants, variables, arithmetic operators and some other fun things!

HOME       NEXT CHAPTER