Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: Overview of c++ progamming language
Description: The notes are quite simple friendly even to beginners
Description: The notes are quite simple friendly even to beginners
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
OVERVIEW OF C++ PROGRAMMING LANGUAGE
1
...
When variable is declared in a program, compiler allocates a maximum memory space for
it which depends on its data type
...
Data type
char
float
double
int
short int
long int
unsigned short int
unsigned long int
unsigned int
boolean
Maximum Size (in bytes)
1
4
8
4
2
4
2
4
4
1
Range of Values
256 characters
1
...
4X1038
2
...
8x10308
-2,147,483,648 to 2,147,483,647
-32,768 to 32,767
-2,147,483,648 to 2,147,483,647
0 to 65,535
0 to 4,294,967,295
0 to 4,294,967,295
True or false
Unsigned integers are always positive ones while int, short int or long int can be negative or positive
...
C++ uses other more complex data types such as string
...
To use this data type, the file
has to be included as described in the next section
...
Structure of a C++ program
A C++ program has three main sections;
A
...
In this section, all libraries whose objects are to be used in the program have to be declared so that they get called during
execution
...
Declaration of library file is done through the use of include statement
...
Declaration of global variables, subroutines or classes
...
C
...
This is the function which is automatically called by the compiler for execution
...
It has the general structure as to any other functions (look at the section of function) but is considered to be the special
one in C++
...
3
...
Assignment Operator (=)
This is used to assign the left hand variable with a value or expression
...
Mathematical operators
The mostly used are addition (+), subtraction (-), multiplication (*) and division (/)
...
g p=50/10;
The value of p will be 5 as the result of 50 divided by 10
...
Increment and Decrement operators
These are ++ for increment and - - for decrement
...
age=5; y=12;
age=age++; z=y- -;
The value of age now is 6 and z is 11
...
Relational operators
Name
Equals
Not equals
Greater than
Greater than or equals
Less than or equals
Operator
==
!=
>
>=
<=
The operators are used to compare the two values/expressions and return the result as true or false
...
if (x != 10) {
cout << “You have entered correct number”; }
if x is 5 then the if statement is true and will be executed
...
Logical operators
Operator
AND
OR
NOT
Symbol
&&
||
!
Example
condition1 && condition2
condition1 || condition2
!x
These are used to check if the two conditions are both met (with &&) or at least one of the two is met (with ||)
or a certain condition is not met (with !)
...
4
...
Its definition begins by symbol { and ends by }
...
This is a function which also calls any other function defined in
the program by declaring its name
...
If returns, it returns only one data at once and its data
type should be declared before its name
...
Example 1
#include
using namespace std;
float convert(float tempFer) {
float tempCel;
tempCel=((tempFer -32) * 5)/9;
return tempCel;
}
int main () {
float tempFer1,tempCel1;
cout << “Please enter the temperature in Fahrenheit:”;
cin >> tempFer1;
tempCel1=convert (tempFer1);
cout << “\n Here is the temperature in Celsius:”;
cout << tempCel1;
system (“pause”);
return 0;
}
The program has two functions, main and convert
...
Note how the function is defined before the main and is called in the main to return its data
...
When the function
returns data, the variables are no longer valid and cannot be recalled by any other function including main
...
#include
using namespace std;
float divide(float a, float b) {
float w;
if (b!=0) {
w=a/b;
return w;
}
else {
cout<< “Make sure the second number entered is not equal to 0!”;
}
}
int main () {
float q,x,y;
cout <<” Enter the first number”;
cin >>x;
cout <<” \n Enter the second number”;
cin >>y;
q=divide(x,y);
cout <<”\n The result is ”;
cout<system (“pause”);
3|Page
return 0;
}
Function Overloading
C++ enables us to create more than one function having the same name
...
In order
to achieve this, the functions have to differ in either number of parameters, type of parameters or both
...
Implementation of only one function will be called in
the main function if matching parameters with the calling statement
...
Function overloading can be also known as function polymorphism
...
For instance you can create functions that find the average of integers, floats or double using the same name but will be
different in parameters
...
If statement
This is a section of a program which tests at least one condition using an expression
...
if (condition) {
Statement1;
Statement2;
Statement3;
}
Condition can be one or more than one which are joined together by logical operators
...
See the example below with two conditions
...
6
...
……
...
switch (x) {
case 0: cout << “Too small”;
break;
case 5: cout << “Average”;
break;
4|Page
case 100: cout << “Too big”;
break;
default: cout << “Within the range”;
break;
}
7
...
While Loop
While loop causes your program to repeat a sequence of statements as long as the stated condition remains true
...
while (condition)
statement
Example:
int x=0;
while (x<10) {
cout <<”x”;
x++; }
B
...
while
The loop executes the body of the loop before its condition is tested and ensures that the body is always executes at least ones
...
Example:
z=10;
do {
cout<< “Hello!”;
z- -;
} while (z > 0);
C
...
Example:
for (int w=0; w < 5;w++) {
cout <<”Looping”; }
NB: You can use the statement break to escape from any type of a loop before its end or continue to jump to the next loop
round before finishing the current one
...
Example 2:
5|Page
for (int w=0; w < 5;w++) {
cout <<”Looping”;
if (w==3) {
break; }
}
When w equals to 3, the program quits the loop and goes to the next statement just after the loop
...
Arrays
It is a collection of data storage locations, each of which holds the same data type
...
When declaring an array, data type and size of the array should be included
...
Not all C++ features have been explored
...
6|Page
Title: Overview of c++ progamming language
Description: The notes are quite simple friendly even to beginners
Description: The notes are quite simple friendly even to beginners