C++: AN INTRODUCTION
Presented at the ICT Unit,
TV Gotel
By
Paul Lucky Bwaromale
WHAT IS C++?
C++ is an object-oriented High Level Language used in programming
awesome applications ranging from OS, scientific research software to
scheduler applications.
BRIEF HISTORY OF C++
In 1983, a Danish scientist Bjarne Stroustrup at the AT & T Bell
Laboratories improved a C simula which he researched and presented
as his Ph. D thesis.
He made his own version of C called “C with Classes” later renamed
C++ which has all the features and supports C libraries/syntax; and
new additions such as classes, derived classes, strong typing,
improved type checking, default arguments and many more.
FEATURES OF C++
HLL
Speed
Portability
Systems Progamming
Write-Only
C Library support
STRUCTURE OF A C++ PROGRAM
#include <iostream> preprocessor directives
Using namespace std;
int main()
{
//block of codes main
program
return 0;
}
VARIABLE DECLARATION IN C++
Rules
i. Unique name
ii. Appropriate datatype association
e. g. int x;
char z;
float r;
x, z and r are now variables that can be used in the program they are
declared.
C++ DATATYPES
 int (integer)
supports whole numbers ranging from -214783648 to 214782647
 double (double floating point)
best for numbers with decimal points
 float (floating point)
best for scientific mantissa figures
 char (Character)
supports all ASCII characters ranging from -128 to 127 or 0 to 255 for
signed and unsigned respectively
 bool (Boolean)
0 and 1
BASIC OPERATORS IN C++
<< - extraction
>> - insertion
+ - Addition
- - Subtraction
* - Multiplication
/ - Division
; - end of statement
// - single line commenting
/* */ - multiple line
commenting
|| - OR
&& - AND
< - Less than
<= - Less than or equal to]
> - Greater than
>= - Greater than or equal to
CONTROL STRUCTURES
Control structures are programming functions that alter the flow of a
program pending a condition been met. They are also called loops.
C++ control structures include
while
if – else
Nested ifs
elseif
For
switch
WHILE LOOP
It executes a block of code while a condition is met
e. g.
#include <iostream>
Using namespace std;
Int main()
{
int x=2;
while(x<10)
{
cout << “Welldone”;
}
return 0;
}
IF - ELSE
Executes a block of code if a particular
condition is met or executes another if the
conditions are not met
e. g.
#include <iostream>
using namespace std;
int main()
{
int x=2;
if(x<10)
{
cout <<“Less thsn 10”;
}
else
{
cout<<“Greater than 10”;
}
return 0;
}
NESTED IF
An if statement within an if statement
e. g.
#include <iostream>
Using namespace std;
int main()
{
int x ;
cin>>x;
if(x!=)
{
if (x<2)
{
cout << “not equal to 2”;
}
}
else
{
cout<<“Great number”;
}
return 0;
}

C++: An Introduction

  • 1.
    C++: AN INTRODUCTION Presentedat the ICT Unit, TV Gotel By Paul Lucky Bwaromale
  • 2.
    WHAT IS C++? C++is an object-oriented High Level Language used in programming awesome applications ranging from OS, scientific research software to scheduler applications.
  • 3.
    BRIEF HISTORY OFC++ In 1983, a Danish scientist Bjarne Stroustrup at the AT & T Bell Laboratories improved a C simula which he researched and presented as his Ph. D thesis. He made his own version of C called “C with Classes” later renamed C++ which has all the features and supports C libraries/syntax; and new additions such as classes, derived classes, strong typing, improved type checking, default arguments and many more.
  • 4.
    FEATURES OF C++ HLL Speed Portability SystemsProgamming Write-Only C Library support
  • 5.
    STRUCTURE OF AC++ PROGRAM #include <iostream> preprocessor directives Using namespace std; int main() { //block of codes main program return 0; }
  • 6.
    VARIABLE DECLARATION INC++ Rules i. Unique name ii. Appropriate datatype association e. g. int x; char z; float r; x, z and r are now variables that can be used in the program they are declared.
  • 7.
    C++ DATATYPES  int(integer) supports whole numbers ranging from -214783648 to 214782647  double (double floating point) best for numbers with decimal points  float (floating point) best for scientific mantissa figures  char (Character) supports all ASCII characters ranging from -128 to 127 or 0 to 255 for signed and unsigned respectively  bool (Boolean) 0 and 1
  • 8.
    BASIC OPERATORS INC++ << - extraction >> - insertion + - Addition - - Subtraction * - Multiplication / - Division ; - end of statement // - single line commenting /* */ - multiple line commenting || - OR && - AND < - Less than <= - Less than or equal to] > - Greater than >= - Greater than or equal to
  • 9.
    CONTROL STRUCTURES Control structuresare programming functions that alter the flow of a program pending a condition been met. They are also called loops. C++ control structures include while if – else Nested ifs elseif For switch
  • 10.
    WHILE LOOP It executesa block of code while a condition is met e. g. #include <iostream> Using namespace std; Int main() { int x=2; while(x<10) { cout << “Welldone”; } return 0; }
  • 11.
    IF - ELSE Executesa block of code if a particular condition is met or executes another if the conditions are not met e. g. #include <iostream> using namespace std; int main() { int x=2; if(x<10) { cout <<“Less thsn 10”; } else { cout<<“Greater than 10”; } return 0; }
  • 12.
    NESTED IF An ifstatement within an if statement e. g. #include <iostream> Using namespace std; int main() { int x ; cin>>x; if(x!=) { if (x<2) { cout << “not equal to 2”; } } else { cout<<“Great number”; } return 0; }