Programming via C++



Grip the basics of C++ !!

This article introduces you to C ++ programming from ground level. This article will teach you all the funds of C ++ programming but rather the basis for learning C ++ programming, remember that for further learning, the base should be strong and this is what the article tries to do. It will run you know a lot of funds that will help you learn more about language. As C ++ was developed by Björn Straussstrom at Bell Labs in the 1980s as an Object Oriented Programming Language. This language is considered by many people as an extension of C programming language. This extension of C to create C++ was obtained by adding classes to C. This is why C ++ was in the beginning termed as “C with classes”. The symbolic name of C ++ accurately indicates that this language is the advanced version of C.

Features: The C ++ programming language is a highly flexible, versatile and very powerful programming language to develop any software, especially system software i.e., operating system, compiler, etc.
C ++ is the most appropriate language for the development of reusable programs, which is very important to keep production costs minimal.

Comparison with other programming languages:-
Let's see that how C ++ compares with other programming languages.  All programming languages ​​are branched in two categories: -
Problem oriented languages ​​or high level languages: These languages ​​are designed to give better programming efficiency, i.e. faster program development. Examples of upcoming languages ​​in this category are FORTRAN , BASIC , etc.

Machine-oriented languages ​​( low-level programming languages ): These languages ​​are designed to give a better machine efficiency, that is, faster program execution. Examples of programming languages ​​coming in this category are assembly language and machine languages. And, C ++ stands between these two categories. This is why it is often called a middle-level language, because it was designed for both: relatively good Programming efficiency (compared to machine-oriented languages) and relatively good Machine efficiency (compared to problem-oriented languages).



Getting Started with C ++ Programming:-
To communicate with computer we have to involve the language which it understands and it obviously rules out our communicating language English. However, there is a close similarity between learning English language and
learning C ++ language. The classical method of learning English is to first learn letters or characters used in language, then learn how to combine these letters to make sentences and the sentences are combined to create paragraphs. Learning C ++ programming is similar and it's very easy.
Therefore, instead of learning to write programs, we must first do find out that alphabetical numbers, numbers and special symbols are used in C ++, then how is it used? And, how these constants, variables and keywords are created, and finally how are they all this combined to make an instruction? A set of instructions will be combined later to create a program.
Character set: Character Set is a set of valid characters so that the language can be recognized. A character represents any letters, points or any other signs. C ++ has the following character sets:
Letter:  A-Z, a-z
Integers:  0-9
Special symbols : space + - * / '"() [] and many more we have.
White spaces, spaces, horizontal tabs, carriage returns, newline etc.
Other characters can process C ++ 256 ASCII characters as any data or data literal.
When combining the alphabet, numbers, and special symbols correctly, the constants, variables and keywords are formed. Let's see what these are: -
Constants: There are constant data items that do not change their value at anytime while running a program. The C ++ programming language allows several types of constants.
Variables: There are variables that can vary during program execution. Convertible names are names given in places of memory in the computer where the values ​​are stored.
Keywords: These are words that express a special meaning for language compiler. Keywords are words that have already been interpreted to the C ++ compiler. Keywords cannot be used as variable names because if we do this then we are trying to assign a new meaning for the keyword, which is not permitted by the computer. Examples of keywords are zero, for, switches etc.

Data types in C ++:-
There are tools to identify types of data and related operations to handle it. There are widely two types of c++ data types : -
Fundamental Data Types: These are predefined for C ++ language. There are at least four original data types.
char - indicates that this type of variable can store variable letters
int - indicates integers
float- indicates floating point number
void- indicates valueless data
Derived data types: These are created by fundamental types. I will not give you details here because it is a little higher level.



Instructions in the C ++ programming language:-
Now we have seen different types of constants, variables and keywords , the next logical step is to know how they are added to form instructions.
Type declaration instruction: To declare the type of variable used in the program. Example: - int num; Here a variable number has been declared a type integer.
Input / Output Instructions: To execute a function supplying input data in a program and to obtain output results.
Example: - cin >> A; cout, the first line input is taken from the keyboard by the function cin and it is assigned to pre-declared variable A. In the second line 'Hello' the function is printed using the cout.
Arithmetic Instructions: To perform arithmetic operations between constants and variables. Example:  C = A + B; Here a value is assigned to C which is the sum of the variables A and B.
Control Instructions: To control the sequence of execution of different statements in the C ++ program. Example: - If (A> B) func1 (); Here it has been checked that more than B, if it is, then the program execution goes to user defined function 'func1'.

First C ++ Program:-
Armed with knowledge about types of variables, types, keywords, etc. We will write our first C ++ program. Each instruction in the C ++ program will include a series of statements. The statement should appear in the same order in which we want to execute them. The following rules apply to all C ++ programs whether it is long or complex, they are:-
·      To increase the readability of the statements, the spaces can be inserted between two words. However, no spaces are allowed within a variable, constant or keyword.
·      Generally all statements are entered in small case letters.
·      C ++ does not have any specific rules for the situation on which a statement is to be written. This is why it is often called the free form language.
·      Note, any C ++ statement always ends with a semicolon (;).
Now, let's look at a program that calculates the given two numbers by user:-

//To calculate the sum of two given numbers
#include <iostream.h>
using namespace std;
int main()
{
int num1; //declares a variable num1 of type int
int num2; //declares a variable num2 of type int
int sum; //declares a variable sum of type int
cin>>num1; //takes input and stores to the variable (var) num1
cin>>num2; //takes input and stores to the variable (var) num2
sum= num1+num2; //adds variables (vars) num1 & num2
cout << sum;
return 0;
}

Some useful tips: -
·      A C++ program is a combination of functions.
·      main () is a function that is always there whether in one form or another in a C ++ program.
·      The blank brackets are necessary after the main.
·      The set of statements related to a function is enclosed within a pair of braces. Example: main () {statement 1; statement2; statement3; statement4; }
·      Any variable is declared before use.
·      Any C ++ statement must always end with a semicolon (;).
·      The iostream.h file is the file needed to use Cin and Cout functions, which contains the keywords included in the program.



Summary:-
You have got an introduction to C ++ programming after going through the article, now you know what C ++ is and how it is used. Now you know the C ++ language and have learned some of the most fundamental parts of C ++.
You have learned how to declare variables and use them in arithmetic operations. In one sentence you have got the introduction of  C ++ programming language and now it will help you to learn further.

No comments:

Post a Comment