(Basic Elements of C++)
Today’s topic is how to learn basic elements of c++ . before
starting we should know something about c++. It’s a object oriented programming
language developed in the year of 1980by Bjarne stroustrup in (AT&T BELL
LABORATORIES,USA) the purpose to make this language is to simplify the
procedure of problem solving that’s why it has all the qualities of c and add
some more qualities and developed a language first its name is (C WITH
CLASSES),but after some time he gave the name c++.
[Program Structure of C++]:=
To understand the program structure of c++ watch this
program :-
//wish.cpp: printing a simple message
#include<iostream.h>
Void main()
{
Cout<<”WISH
YOU HAPPY LEARNING C++”?
}
The given program has
six lines:-
DISCRIPTION OF PROGRAM
1: //wish.cpp: printing a
simple message à(COMMENT)
2:#include<iostream.h> à(PREPROCESSOR
DIRECTIVE)
3: void main() à(FUNCTION DECLARATOR)
4:{
à
(START OF FUNCTION)
5: Cout<<”WISH YOU
HAPPY LEARNING C++”? à (MAIN FUNCTIONS
IMPORTANT PART)
6:} à(END OF FUNCTION)
First Line:-
The statement given in the double slash (//) called comment
and compiler not run this line , comment is not part of the program but it
works like the header of the program ,this line is written just for the
convenience of the programmer so that in future it helps in modifying the code.
Second Line:-
The second line is preprocessor directive
#include<iostream.h>
Include the statement of header file .It consist commands
and constants which is used in program. In iostream file it consist declaration
which is needed to cout and cin (stream objects).
There are lots of preprocessor directives in c++.
Third Line:-
C++ is depended on a set of functions just like C. Every c++
program has a main function from where the execution of program is started
.Except main all program is given by the
programmer .after the function there is a pair of parenthesis it has arguments
and sometimes not. The parenthesis is important to mention otherwise it will show
an error message.
Fourth Line:-
The main part of the c++ program is its curly braces({) arguments
are written within this braces.
Fifth Line:-
Cout this function Is used to show the given message and is
related to console. A console is a black dos like screen is show when the
program is execute and all results are
shown on that black screen.
Sixth Line:-
(}) show the end of the function body.
HOW TO RUN A C++ PROGRAM
Writing a program:-
Before writing the program start the turbo c++ software
.after showing program window press ALT+F and choose NEW and after this a
window show written at the top NONAME00.CPP ,now you can start writing the
code.
Saving a Program:-
After creating the program press ALT+F and choose save
option or you can press F2 after that a save dialog box shown here you can give
a name to the file and give a extension and save it.
Compiling a program:-
Now save the file with cpp extension and save it with any
name. after compiling process your file become a object file . if there is any error in the code it show a
error message otherwise show a message like( 0ERROE0WARNING).You can compile
the program after pressing the key ALT+F9.
Linking the Program:-
The purpose to link a
program is make the program executable. after this you can run it independently
.To link press ALT+C together.
Executing the Program:-
For execution of program press CTRL+F9.
Implementing the user window:-
To see the output on the screen press ALT+W and choose USER
WINDOW ,or you can use ALT+F5when output not shown on the screen.
No comments:
Post a Comment