In the last post, i discussed about Advantages, disadvantages of structured and object oriented programming and difference between them.Today i am going to discuss about:-
1. Application of C++
2. Features of C++
3. 1st program in C++
4. Structure of a C++ program
And in the next post i will discuss about:
1. C++ character set.
2. Data types, Identifier, Variable, Constant and Keywords.
3. Types of Constant.
4.Rules for constructing integer constant.
5. Rule for constructing real constant.
6. Rule for constructing character constant.
7. Rules for constructing variable name.
Let's start:
Application of C++:-
C++ is a versatile language for handling very large programs. It is suitable for virtually any programming task including development of editor, compilers, database, communication system and complex real-life application system.
The following are some application of C++;
1. C++ allow us to create hierarchy related objects, we can build special object oriented libraries which can be used later used by many programmers.
2. While C++ is able to map real world problem properly, the C part of C++ gives the language ability to get close to the machine level details.
3. C++ programs are easily maintainable and expandable. When a new feature needs to be implemented, it is very easy to add to the existing structure of an object.
4. It is exacted that C++ will replace C as a general purpose language in the near future.
Features of the C++ or OOP:-
1. Emphasis is on data rather than procedure.
2. Programs are divided into what are known as objects.
3. Data structures are designed such that characterize the objects.
4. Functions that operate on the data of an object are tied together in the data structure.
5. Data is hidden and cannot be accessed by external functions.
6. Objects may communicate with each other through functions.
7. New data and functions can be easily added whenever necessary.
8. Follows bottom-up approach in program design.
A simple C++ Program:-
//Text printing program
//Date:-15th June, 2019
#include<iostream> //include header file
using namespace std;
int main(){
cout<<"C++ is the better than C\n"; // C++ statement
return 0;
} // End of program
Output of the above program:-
Program features:-
1. Comments:-
The 1st and 2nd line are started with double slash (//) indicating the start of comment on the program and it terminated at the end of the line. A comment may start any where in the line, and whatever follows till the end of the line is ignored. Note that there is no closing symbol.
The double slash comment is basically a single line comment. Multi-line comments can be written as follows:
// This is an example of
// C++ program to illustrate
// Some of its features
The C comment symbols /*,*/ are still valid and are more suitable for multi-line comments.
The following comment is allowed:
/* This is an example of
C++ program to illustrate
some of its features
/*
2. The iostream file:-
We have used the following #include directive in the program.
#include<iostream>
This directive cause the preprocessor to add the contents of the iostream file to the program. It contains declarations for the identifier cout and the operator <<. Some old style versions of C++ use a header file called iostream.h. This is one of the changes introduced by ANSI C++.(We should use iostream.h if the compiler does not support ANSI C++ features.)
The header file iostream should be included at the beginning of all programs that use input/output statements.
3. Namespace:-
Namespace is a new concept introduced by the ANSI C++ standards committee. This defines a scope for the identifiers that are used in a program. For using the identifiers defined in the namespace scope we must include the using directive, like
using namespace std;
Here, std is the namespace where ANSI C++ standard class libraries are defined. All ANSI C++ program must include this directive. This will bring all the identifies defines in std to current global scope.
4. The main() function:-
Like C, the C++ program is a collection of functions. The above example contains only one function, main(). The execution of every C and C++ program begins at main(). So, every C++ program must have a main() function. And after the main() a opening curly braces "{" indicate the start of the main() function body and at the last line a closing curly braces "}" indicate the ending of the main() function. Every function body start with "{" and end with "}".
5. Output operator:-
The only statement in the above program is an output statement. The statement
cout<<"C++ is better than C.";
causes the string in the quotation marks to be displayed on the screen. this statement introduces two new C++ features, cout and <<. The identifier cout (pronounced as "C out") is a predefined object that represents the standard output stream in C++.
6. Return type of the main():-
In the C++, main() returns an integer type value to the operating system . Therefore, every main() in the C++ should end with a return 0; statement otherwise a warning or an error might occur.
Since main() returns an integer type value , return type for main() is explicitly specified as int(letter i will discus it in this post). Note that the default rerturn type for all functions in the C++ is int. The following main() without type and return will run with a warning:
main()
{
............
............
}
Structure of a C++ program:-
1. Application of C++
2. Features of C++
3. 1st program in C++
4. Structure of a C++ program
And in the next post i will discuss about:
1. C++ character set.
2. Data types, Identifier, Variable, Constant and Keywords.
3. Types of Constant.
4.Rules for constructing integer constant.
5. Rule for constructing real constant.
6. Rule for constructing character constant.
7. Rules for constructing variable name.
Let's start:
Application of C++:-
C++ is a versatile language for handling very large programs. It is suitable for virtually any programming task including development of editor, compilers, database, communication system and complex real-life application system.
The following are some application of C++;
1. C++ allow us to create hierarchy related objects, we can build special object oriented libraries which can be used later used by many programmers.
2. While C++ is able to map real world problem properly, the C part of C++ gives the language ability to get close to the machine level details.
3. C++ programs are easily maintainable and expandable. When a new feature needs to be implemented, it is very easy to add to the existing structure of an object.
4. It is exacted that C++ will replace C as a general purpose language in the near future.
Features of the C++ or OOP:-
1. Emphasis is on data rather than procedure.
2. Programs are divided into what are known as objects.
3. Data structures are designed such that characterize the objects.
4. Functions that operate on the data of an object are tied together in the data structure.
5. Data is hidden and cannot be accessed by external functions.
6. Objects may communicate with each other through functions.
7. New data and functions can be easily added whenever necessary.
8. Follows bottom-up approach in program design.
A simple C++ Program:-
//Text printing program
//Date:-15th June, 2019
#include<iostream> //include header file
using namespace std;
int main(){
cout<<"C++ is the better than C\n"; // C++ statement
return 0;
} // End of program
Output of the above program:-
Program features:-
1. Comments:-
The 1st and 2nd line are started with double slash (//) indicating the start of comment on the program and it terminated at the end of the line. A comment may start any where in the line, and whatever follows till the end of the line is ignored. Note that there is no closing symbol.
The double slash comment is basically a single line comment. Multi-line comments can be written as follows:
// This is an example of
// C++ program to illustrate
// Some of its features
The C comment symbols /*,*/ are still valid and are more suitable for multi-line comments.
The following comment is allowed:
/* This is an example of
C++ program to illustrate
some of its features
/*
2. The iostream file:-
We have used the following #include directive in the program.
#include<iostream>
This directive cause the preprocessor to add the contents of the iostream file to the program. It contains declarations for the identifier cout and the operator <<. Some old style versions of C++ use a header file called iostream.h. This is one of the changes introduced by ANSI C++.(We should use iostream.h if the compiler does not support ANSI C++ features.)
The header file iostream should be included at the beginning of all programs that use input/output statements.
3. Namespace:-
Namespace is a new concept introduced by the ANSI C++ standards committee. This defines a scope for the identifiers that are used in a program. For using the identifiers defined in the namespace scope we must include the using directive, like
using namespace std;
Here, std is the namespace where ANSI C++ standard class libraries are defined. All ANSI C++ program must include this directive. This will bring all the identifies defines in std to current global scope.
4. The main() function:-
Like C, the C++ program is a collection of functions. The above example contains only one function, main(). The execution of every C and C++ program begins at main(). So, every C++ program must have a main() function. And after the main() a opening curly braces "{" indicate the start of the main() function body and at the last line a closing curly braces "}" indicate the ending of the main() function. Every function body start with "{" and end with "}".
5. Output operator:-
The only statement in the above program is an output statement. The statement
cout<<"C++ is better than C.";
causes the string in the quotation marks to be displayed on the screen. this statement introduces two new C++ features, cout and <<. The identifier cout (pronounced as "C out") is a predefined object that represents the standard output stream in C++.
6. Return type of the main():-
In the C++, main() returns an integer type value to the operating system . Therefore, every main() in the C++ should end with a return 0; statement otherwise a warning or an error might occur.
Since main() returns an integer type value , return type for main() is explicitly specified as int(letter i will discus it in this post). Note that the default rerturn type for all functions in the C++ is int. The following main() without type and return will run with a warning:
main()
{
............
............
}
Structure of a C++ program:-
Comments
Post a Comment