You are on page 1of 7

Fundamentals of C++

Compiled & Prepared by: Instructor Eyasu Mulugeta

E-mail: eyasu@india.com

Mobile: (+251)927-182804

Our Services:

 Computer Maintenance
 Website & Software Development
 Website & Mobile Application Development
 Home 2 Home Computer Training
 Software, Apps ,Games & Movie Sale

High Quality for Fair Price


Chapter - One

C++ Overview

C++ is a general purpose programming language invented in the early 1980s by Bjarne Stroustrup at Bell
Labs.

It is similar to C, invented in the early 1970s by Dennis Ritchie, but is a safer language than C and includes
modern programming techniques such as object oriented programming.

In fact C++ was originally called C with Classes and is so compatible with C that it will probably compile
more than 99% of C programs without changing a line of source code.

The purpose of C++ is to precisely define a series of operations that a computer can perform to
accomplish a task. Most of these operations involve manipulating numbers and text, but anything that
the computer can physically do can be programmed in C++.

Computers have no intelligence- they have to be told exactly what to do and this is defined by the
programming language you use.

Once programmed they can repeat the steps as many times as you wish at very high speed. Modern PCs
are so fast that they can count to a billion in a second or two.

What can a C++ program do?

Some typical programming tasks includes

 Putting data into a database or pulling it out,


 Displaying high speed graphics in a game or video,
 Controlling electronic devices attached to the PC
 Playing music and/or sound effects.
 Generate music or help you compose, etc.

Main Features of the C++ Language

The C++ programming language is based on the C language. Although C++ is a descendant of the C
language, the two languages are not always compatible.

In C++, you can develop new data types that contain functional descriptions (member functions) as well
as data representations.

You can define a series of functions with different argument types that all use the same function name.
This is called function overloading.
The C++ language provides templates and several keywords not found in the C language. Other features
include try-catch-throw exception handling, etc.

Environment Setup

First you need a C++ compiler. There are many commercial and free ones available.

Both the below listed compilers are completely free and include an IDE to make life easier for you to edit,
compile and debug your applications.

 Download and Install Borland Turbo C++ Explorer


 Download and Install Dev C++

In this class, we will be using Dev C++.

What is a compiler?

A compiler is a special program that processes statements written in a particular programming language and turns
them into machine language or "code" that a computer's processor uses.

How do I begin writing C++ applications?

C++ can be written using a text editor. This can be notepad or an IDE like those supplied with the two
compilers listed above. You write a computer program as a series of instructions (called statements) in a
notation that looks a little like mathematical formulas.

int c=0;
float b= c*3.4+10;

This is saved out in a text file and then compiled and linked to generate machine code which you then can
run.

Every application you use on a computer will have been written and compiled like this, and many of them
are getting written in C++.

Basic Syntax

Structure of a program

The best way to learn a programming language is by writing programs. Typically, the first program beginners write is
a program called "Hello World", which simply prints "Hello World" to your computer screen. Although it is very
simple, it contains all the fundamental components C++ programs have:

Let us look at a simple code that would print the words Hello World.

#include <iostream>
using namespace std;
// main() is where program execution begins.

int main()
{
cout << "Hello World"; // prints Hello World
return 0;
}

Let us look various parts of the above program:

 The C++ language defines several headers, which contain information that is either necessary or
useful to your program. For this program, the header <iostream> is needed.

 The line using namespace std; tells the compiler to use the std namespace. Namespaces are a
relatively recent addition to C++.

 The next line // main() is where program execution begins. It is a single-line comment available in
C++. Single-line comments begin with // and stop at the end of the line.

 The line int main() is the main function where program execution begins.

 The next line cout << "This is my first C++ program."; causes the message "This is my first C++
program" to be displayed on the screen.

 The next line return 0; terminates main( )function and causes it to return the value 0 to the
calling process.

C++ Identifiers:

A C++ identifier is a name used to identify a variable, function, or any other user-defined item. An
identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters,
underscores, and digits (0 to 9).

C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is a case-sensitive
programming language. Thus, Manpower and manpower are two different identifiers in C++.

Here are some examples of acceptable identifiers:


C++ Keywords:

The following list shows the reserved words in C++. These reserved words may not be used as constant or
variable or any other identifier names.

Comments

Comments are used to document and explain our codes and program logic. Comments are not
programming statements and are ignored by the compiler, but they VERY IMPORTANT for providing
documentation and explanation for others to understand your program (and also for yourself three days
later).

There are two kinds of comments in C/C++:

1. Multi-line Comment: begins with a /* and ends with a */, and can span several lines.
2. End-of-line Comment: begins with // and lasts till the end of the current line.
You should use comments liberally to explain and document your codes. During program development,
instead of deleting a chunk of statements permanently, you could comment-out these statements so that
you could get them back later, if needed.
Visit shegertech to learn more!
https://shegertech.blogspot.com

You might also like