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 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.
5. STRUCTURE OF A C++ PROGRAM
#include <iostream> preprocessor directives
Using namespace std;
int main()
{
//block of codes main
program
return 0;
}
6. 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.
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 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
9. 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
10. 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;
}
11. 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;
}
12. 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;
}