webspace hosting web hosting| online dating| joomla themes| website hosting| free web hosting| com domains| report abuse
Unlimited Web Hosting

Unlimited disk space/traffic/domains
1-click app installer, $9.99/month

VPS Hosting

Free Control Panel, full root access
Virtuozzo Containers, $25.00/month

Unlimited Internet Fax to Email

Unlimited faxes, no fees
dedicated phone number

Reseller Hosting

Reseller hosting services, domains,
vps, dedicated servers. Join free!

The C++ Programming Adventure!


Join the Fun!

Session 1: Welcome to Programming!

Welcome to this simple C++ programming course! This C++ "adventure" takes you into the wild programming world, giving you a sampling of what C++ has to offer.

  • This course is oriented around video game development; after all, games are fun! By the end, you'll be making real 2D video games!
  • This course uses C++, a high-performance programming language that sets the industry standard for video game development.
  • Programming is not hard -- at first. So, this course attempts to keep it as simple as possible. In fact, you'll be programming after this first session with some simple "fill-in-the-blank" code.

The following is an introduction to C++. If you would rather make programs first, skip to the bottom of the page. However, please don't move on until you have read and understood The Basics.

The Basics

Basically, programming a computer is telling it what to do. Computers need a list of step-by-step procedures to follow in order to do the things they do. As a programmer, you'll be preparing these instructions. A computer program is a list of procedures that performs a specific task; for example, Notepad in Windows lets a computer user edit text files. Programs can vary in size and complexity, but they all have a definite purpose and a way to reach that purpose.

To tell somebody what to do, you have to be able to speak their language first. Otherwise, you might tell them something they don't understand -- and that's not too productive! As a programmer, you have to speak the language of the computer to control it; unfortunately, today's computers are electronic, and communicate with pulses of electric current (kind of like Morse code or signal lanterns). Since programmers wished to avoid the insane asylum over this, they created an easier way to program computers: the programming language.

A programming language, often using English-like keywords, is a language structured enough to define good programs yet readable enough to understand.. C++ is a programming language -- it's halfway between our regular English and the electronic pulses of cyberspace. We convert our ideas into C++ mentally (don't worry, it's not hard to do!), and a special translator called a compiler converts C++ into machine code -- the code the computer reads. Then, the computer can run the programs -- without ever needing us to edit a line of machine code.

Into the C++

C++ is a very simple programming language -- meaning your C++ code is only as complex as your program. A C++ program is comprised of statements, each of which is a single command. For example,

cout << "Hello!";
puts the word "Hello!" on the screen. Statements are grouped using {braces}, and can contain C++ expressions -- like 2 + 2. And, most importantly, all statements end with a semicolon (;). The semicolon is like a period on the end of a sentence; your English teacher won't let you forget them!

Yes, you do have to be careful when you enter in commands. C++ is "structured enough to define good programs" because the compiler will only translate your program if it makes sense -- meaning you'd better not just bang on the keyboard! Pretty much, as long as you follow the rules, you'll be fine. That's because the rules in C++ are made so that, if you follow them, you'll make a program that has clear, sensible, and easy-to-follow steps and procedures. If you forget a rule, the compiler will tell you; before you can make an actual program, you have to debug it, or weed out the mistakes. (You'll learn much more about this later!)

It's Time to Program!

#include <iostream>
#include <cstdlib>

using namespace std;

int main (int argc, char *argv[]) {
// Your stuff here, like:
    cout << endl << "Hello, Aliens! My SSN is " << 11235813 << ".";

    system("PAUSE");
    return EXIT_SUCCESS;
}

Here is a C++ console program. It prints some important information (!) to a console, which is like an old-school terminal or instant-messaging screen -- without the screen names. The console is where you enter commands and see output; it works like a conversation between you and "Mr. Computer". It shows up as a black box on the screen, and at the end of the program states "Press any key to continue . . .". Since the console is easy to use, you'll use it for many of your C++ programs. Here's what the program output looks like on the console (the key I pressed is highlighted in white):

Hello, Aliens! My SSN is 11235813.
Press any key to continue . . . _
[Enter]

This sample C++ program is primarily "standard stuff". Everything that's not highlighted in yellow must be included in every C++ program you'll make for a while. All you'll change is the code in the highlighted section.

Try It Out!

Now, you can try making a console program for yourself. You'll use the cout command to show text on the screen. Basically, the information you send to the console comes out in the order you put it in, and each piece of data is separated with <<. Here's what you can use with cout:

cout << "Hello, Aliens! My SSN is " << 11235813 <<
    ", and 15 + 1568 is" << 15 + 1568 << ".";
Your code:
#include <iostream>
#include <cstdlib>

using namespace std;

int main (int argc, char *argv[]) {
    // Your stuff here
    
    

    system("PAUSE");
    return EXIT_SUCCESS;
}