Skip to main content

Application of C++, feature of C++ and 1st program in C++

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:-

Comments

Popular posts from this blog

Advantage and disadvantages of Structure and object oriented programming

In my last post, i discussed about structured oriented programming, object oriented programming and language processors. Today i am going to discuss about :- 1. Advantages and Disadvantages of structured oriented programming. 2. Advantages and Disadvantages of object oriented programming. 3.Difference between them. And in the next post i will discuss about:- 1. 1st C++ program and explanation. 2. Structure of a C++ program. 3. Data types, Identifiers, Variable and Keywords. Let's start: Advantages of Structure oriented programming:- 1. It is easy to understand. 2. It is to test a program that is divided into modules(sub-problem) and sub-module(sub-sub-problem). 3. Modification is easier. 4. It results in speedy execution of the program. 5. Development of modules is easier. Disadvantages of Structured oriented programming:- 1. Modules occupy more space in the memory. 2.  Testing of every module is time consuming process. 3. Combination of modules becomes di

size and range of basic data types and modifing the basic types.

Size and range of basic data types:-   Modifying the basic types:-  Except for type void, the basic data types may have various modifiers preceding them.  You use a modifier to alter the meaning of the base type to fit various situations more  precisely. The list of modifiers is shown here: signed unsigned long short You can apply the modifiers signed, short, long, and unsigned to integer base  types. You can apply unsigned and signed to characters. You may also apply long to  double. The above  table shows all valid data type combinations, along with their minimal ranges and approximate bit widths. (These values also apply to a typical C++  implementation.) Remember, the table shows the minimum range that these types will  have as specified by Standard C/C++, not their typical range. For example, on  computers that use two's complement arithmetic (which is nearly all), an integer will have a range of at least 32,767 to –32,768. The use of signed on integers is al

C++ tokens, rule for naming variable and rule for constructing integer constant, real constant and character constant

 C++ character set :- The following image shows the valid character that are used in C++.  C++ data types:- 1st of all we have to know that What is a data? Data is a raw material for constructing a information. For example, the following list are the data:- Ram,17, XII C. And from this data we can construct the information as Ram Aged 17 years is in class XII C. Data may be any number,words, amount,quantity. Now, Let's come on the topic: Latter i will discus about 'structure', 'Union', 'Class', Array', 'function','pointer','reference' for now there are five basic data types that are: 1. int(integer)  2. char(Character) 3. float 4. double  5. void  Now look at variable:  Variable is a entity whose value may change and in programming language it is used to store data. A integer type variable can hold a integer number(number must be a whole number either in positive or in negative but not in fraction),  a ch