NETB131 Programming Project
Programming language C++
An overview
Nikolay Kirov Kirov, F00000
1. History and Special Features
Bjarne
Stroustrup developed C++ in 1979 at Bell
Labs as an enhancement to the C programming language and named it "C
with Classes". In 1983 it was renamed to C++. Enhancements started
with the addition of classes, followed by, among other features,
virtual functions, operator overloading, multiple inheritance,
templates, and exception handling.
C++ is a general-purpose programming language with
high-level and low-level capabilities. It is a statically typed,
free-form, multi-paradigm, usually compiled language supporting
procedural programming, data abstraction, object-oriented programming,
and generic programming.
2. "Hello World" Program
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
return 0;
}
3. Fundamental Data Types (integer, floating point, string) and
Assignment Operator
Definitions:
int k = 0;
double x = 10.1;
string s = "Hello";
= operator assigns the value
of the
expression on the right to the variable on the left.
total = pennies * 0.01;
total = count * 0.05 + total;
4. Basic Control Flow (conditional and loop statements)
Conditional operator:
if (condition)operator;
// optional
else operator;
Loop operator:
while (condition) operator;
Task: Input an integer number n and output the sum:
1+22+32+...+n2. Use input validation
for n to be positive.
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if (n < 0) return 1;
int sum = 0;
int i = 0;
while (i <= n) sum += i*i;
cout << sum;
return 0;
}
5. Functions - syntax, writing and using functions, example
The following is function's format:
type name ( parameter1, parameter2, ...) { statements }
where:
-
type
is the data type specifier of the data returned by the
function
-
name
is the identifier by which it will be possible to call
the
function
-
parameters
(as many as needed): Each parameter consists of a
data
type specifier followed by an identifier, like any regular variable
declaration (for example: int x) and which acts within the function as
a regular local variable. They allow to pass arguments to the function
when it is called. The different parameters are separated by commas.
-
statements
is the function's body. It is a block of
statements
surrounded by braces { }.
// function example
#include <iostream>
using namespace std;
int addition (int a, int b) // definition
{
int r;
r = a + b;
return r;
}
int main ()
{
int z;
z = addition (5,3); // invoking the function
cout << "The result is " << z;
return 0;
}
6. Arrays - syntax, definition, example
type name[size];
-
type
is the data type specifier of the elements in the array
-
name
is the identifier by which it will be possible to access the array
elements
-
size
is an integer constant. It is the number of elements of the array
// array example
#include <iostream>
using namespace std;
int main ()
{
int array[10];
array[0] = 10;
for (int i = 1; i < 10; i++) array[i] = i*i;
return 0;
}
7. Compilers
8. Projects and Software in C++
- Operating systems (MS Windows, Linux, etc.)
- Application software
9. Standard
The C++ programming
language standard was ratified
in 1998, the current version
of which is the 2003 version.
10. References
[1] Cay
Horstmann, Computing
Concepts
with C++ Essentials, Third
Edition, John
Wiley & Sons, 2003.
[2] Stroustrup, Bjarne, The C++
Programming Language, Special Edition, Addison-Wesley, 2000.
[2] C++, http://en.wikipedia.org/wiki/C++
[3] C++ Language Tutorial, http://www.cplusplus.com/doc/tutorial/