INTRODUCTION
In this section we’ll cover Object Oriented Programming, C++
and its basics in detail. This section basically focused on basic C++ program
structure, variables used in C++, input/output statements and the use of
operators in the language. Initially C++ was developed by Bjarne Stroustrup during the
early 1980’s. It was design initially to support the features of C like
efficiency and Low-levelsupport for system level coding. Features added to this
were are Classes with Inheritance and virtual functions, which is derived from
Simula language, and operator overloading, derived from Algol. C++ is best
described as a superset of C, with full support for object-oriented
programming. This language is in wide spread use. The first commercial release
of the C++ language was in Oct 1985.
PROGRAM
A program is a set of instructions written in computer
languages to perform a specified task for a computer. A computer program tells
the computer that waht to do and in which order to do. Different types of programing
languages are used to develop programs. Some commoly used programming languages
are C++, JAVA, SQL, HTML, etc.
Header files and Reserved words
Header files and Reserved words are the two important
components of almost every C++ programs.
Header files
Header files also known as include files, are standard library files that have an extension of
(.h) and which are used to hold declarations for other files.
Consider the following program:
//header file example
#inlcude
Int main()
{
Cout<<"Hello, world!";
Return 0;
}
Output of the program
Hello, world!
This program prints the string
“Hello, world!”
to the screen
using cout, However, this program never defines cout, so how does the compiler
know about the object cout? The answer for this is that cout has been declared
in a header file called “iostream”
. When the line #include <iostream.h>
is used in the program, the compiler locates and read all the declarations from
a header file named “iostream”
.
Reserved words
Reserved words or keywords are those words which have their
special meaning within the C++ language and are reserved for some specific
purpose. C++ reserved words cannot be used for any other purpose in a C++ program and even cannot be used as variables.
Here is a list of C++ keywords:
asm
|
auto
|
bool
|
break
|
case
|
catch
|
char
|
class
|
const
|
const_cast
|
Continue
|
default
|
delete
|
do
|
double
|
dynamic_cast
|
else
|
enum
|
explicit
|
export
|
extern
|
false
|
float
|
for
|
new
|
friend
|
goto
|
if
|
inline
|
int
|
long
|
mutable
|
namespace
|
short
|
signed
|
sizeof
|
static
|
static_cast
|
struct
|
switch
|
template
|
new
|
operator
|
private
|
protected
|
public
|
register
|
reinterpret_cast
|
return
|
this
|
throw
|
true
|
try
|
typedef
|
typename
|
union
|
while
|
wchar_t
|
volatile
|
void
|
virtual
|
using
|
unsign
|
else
|
goto
|
STRUCTURE OF A C++ PROGRAM
General syntax of a C++ program is:
Preprocessor directives
Int main()
{
Body of the program
}
Each C++ program has three main components. These are:
1 -
Preprocessor directives
2 -
Main function, and
3 -
Body of the main function
Now consider the following
“Hello World”
program to explain
these components.
#include
#include
Int main()
{
Cout <<”Hello World”;
Getch();
Return 0;
}
Output of the program
Hello World!
The result of the above program is that it prints
“Hello
World!”
on the screen. It is one of the simplist programs that can be written
in C++, but it contains the fundamental components of almost every C++ program.The Author
Imran Khan |
I am Imran Khan, and I am a blogger, Youtuber. If you think that my content has been valuable to you and you got some knowledge from my content then, please share my content with your friends and keep this content active. If you think that my content need improvemnt then please leave your valuable feedback.
EmoticonEmoticon