Template:Cpptutorial Introduction

From assela Pathirana
Revision as of 15:06, 8 June 2007 by Root (talk | contribs) (1 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

This tutorial is designed for you to learn the C/C++ language in a rapid-phased way, generally over a period of four days of intense work. Even though you will have some time with an instructor, you will have to do a lot of practice as homework in order to gain sufficient confidence as a programmer. Most of the material is ideal for self-study.

Acknowledgment

A number of sections of this tutorial were adopted with permission from Juan Soulie's excellent C++ Language Tutorial published in cplusplus.com. In many of the lessons, changes from original tutorial are minor. However, there are some important differences in a few sections. Therefore, you are advised to follow the present tutorial during the course. On the other hand, remember that Juan Soulie's site will hopefully be updated more frequently, therefore for general look-up for help, that site will be better.

My colleague Billah helped to convert the original tutorial to this format. Thanks, Billah.

How to use this material effectively

Green info.gif

It is important to keep in mind that C++ and Visual C++ 2005 Express Edition are not the same thing. C++ is the language. Visual C++ 2005 Express Edition is the compiler used to build a program with that language. There are many other alternatives to Visual C++ 2005 Express Edition as compilers. These can do the task of compiling a C++ program equally well.

Let's face it, our mission here is not to become professional programmers. The objective is rather to become familiar with programming as a tool. Think of programming as a challenge similar to learn cycling. You need some instructions and perhaps a bit of 'pep-talk', but what is mostly needed is to go out there and do it! And then practice a lot. It may be not possible for everybody to become a racing cyclist, but anyone can learn how to ride a bike for leisure or commuting. In my decade-long experience in teaching programming as a useful tool, I never came across someone who could not master it with adequate practice.

I will help you to set up a environment where you can write and test programs. There are many good compilers out there for C++ and some of the best ones are free and open source. However, the platform we use to try-out these examples is Visual C++ 2005 Express Edition which is a free version of a commercial software. Please keep in mind that there are many other ways of doing the same thing.

If you want to install and configure Visual C++ 2005 Express Edition yourself, please follow the instructions given in this page.

Some platform related stuff

Visual C++ 2005 Express Edition manages its files organized into 'Projects' and 'Solutions'. A 'Solution' can have several 'Projects' under it. This creates a multitude of files, that has nothing to do with C++, but just to help Visual C++ 2005 Express Edition to do the housekeeping. In the beginning, this can lead to confusion.

I have prepared a template project that you can download and extract in your working computer. Using this project will make your life much easier. Download it from here and unzip it in an empty directory. Then clicking on file cbcpp.sln should open the solution and project in Visual C++ 2005 Express Edition. The file structure will be something like the following:

 
├───myprograms
│   ├───lesson1
│   ├───lesson2
│   └───lesson3
└───vsee2005stuff
    │   cbcpp.ncb
    │   cbcpp.sln
    │   cbcpp.vcproj
    │
    └───Debug
            BuildLog.htm
            cbcpp.ilk
            cbcpp.pdb
            mt.dep
            ptr2.obj
            vc80.idb
            vc80.pdb

All the files in the folder vsee2005stuff and its sub-folders are not important for our learning tasks. Following figure shows the Visual C++ 2005 Express Edition environment with this project (and solution) open.

File:Vcppee2005.ep.jpg

In order to compile and run a program, you should write it in this environment (We will come to that in the next chapter.) This can be done by right-clicking on source files, then Add, New Item. You will get a dialog like the following.

File:Vcppee2005.ep2.jpg

Remember two things here:

  • Save your source code as *.cc or *.cpp (e.g. hello.cc or hello.cpp) (Name box)
  • In the Location box navigate to a sub-folder in myprograms (e.g. myprograms\lesson1. This will keep your code neatly sepearted from Visual C++ 2005 Express Edition related stuff.