learn c++ programming
DESCRIPTION
learn c++ programming for coding about object oriented programming language,arrays,everything easily and in less days.in this artice you find all concept of oops,data hiding,inheritence,abstraction,polymorphism etc.for more info go to www.engineerhunt.in.TRANSCRIPT
Programming with C++
Programming with C++Computer Languages: The computer can understand only the high and low voltage power supplies which are represented by 0 and 1 respectively. Instructions given to computer with such binary code (1 & 0) representation are called the machine language instructions. To do programming in machine code is very difficult so computer languages were designed. These languages are classified into two types:
1. Low Level Language
2. High Level Language
Low Level Language: A low level language is called assembly language is designed in the beginning. It has a simple instruction set of command through which all the tasks are done. The Instructions given to the computer are not binary codes but are of English words like MOV, LOAD etc. Hence writing program in assembly was much easier and simpler than machine code. But still the computer can understand only the machine language. Hence a converter or translator is developed to translate the low level language program into machine language. This translator is called an assembler.
High Level Language: These were English like languages and hence the programmers found them very easy to learn. To convert the program written in higher level language into machine level language, compilers and Interpreter are used. Examples of High Level Languages are FORTRAN, COBOL, Pascal, and C. History of C++: C++, an extension of c, as developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories. C++ provides a number of feature that upgrade the C Language, but more impotently, it provides the capabilities for object-oriented programming.
Characteristics of C++: 1. Simplicity
2. Platform Independent3. Architectural Neutral
4. Support OOPs and its feature
a. Object
b. Class
c. Encapsulation
d. Data Abstraction
e. Inheritance
f. Reusability
g. Polymorphism
5. Error Handling
6. Pointers
7. File Handling
8. Case Sensitive
Visit engineerhunt for more::Identifier: Identifiers are the names given to various program elements, such as variables, functions and array. Identifiers consist of letters and digits, in any order, except the first character must be a letter.
Keywords: The Keywords are identifiers that are reserved for their special purpose. These words are not redefined by the user as these words are reserved words. For example if, int and void etc.
Data Types in C++: There are following three data types in C++
1. Character
2. Integer
3. Float
Type
Bytes
Range
int
2
-32768 to 32767
long int
4
-2147483648 to 2147483647
float
4
3.4E-38 to 3.4E+38
double
8
1.7E-308 to 1.7E+308
char
1
-128 to 127
Constant: Constants are the data elements, whose value does not change throughout the program.
Escape Sequence: Escape Sequence are commands included with standard output object (cout) to perform specific actions:
Escape Sequence
Action
\a
sounds a bell
\b
moves cursor back 1 space
\n
next Line
\t
horizontal tab
\r
return
//
for comment statement
Variables: Variables are place holder in memory which is used to store some values. For example: int a,b,c;
char d;
Operators in C++: In C++ there are different types of operators:
1. Assignment Operator
2. Arithmetic Operator
3. Relational Operators.
4. Logical Operators.
1. Assignment Operator (=): An assignment operator is used to assign the value back to a variable.
2. Arithmetic Operator (+, -, *, /, %) : Arithmetic operators are used for performing most common operations of mathematics like addition, subtraction etc.
3. Relational or Comparison Operator (, =, = =,! =): Relational operators are used to compare the value of the variable if they are less than or equal to or greater than the other and so on.
4. Logical Operator ( &&,||, !): logical operators are used to check for more than one condition in a single expression. The logical AND (&&) operators are used along with comparison operators. When two conditions are used along with logical && operator and if both the condition are true it returns true. If one or both the conditions are false then the value returned by the expression is 0.The Logical Operator OR (||) is also used with comparison operators. When
the two conditions are used along with logical (||) operator, and if either both the condition are true or any one of the conditions is true then the expression will return true. The expression with logical OR operator will return false if and only if both the conditions are false.
Logical NOT (!) is generally used with comparison operators to negate their effect.Increment and Decrement: (++ ,--) The increment ++ add 1 to its operand and Decrement operator subtracts one. For example:
a=a+1 or a++
a=a-1or a
Ternary Operator: C++ includes a very special operator called the ternary operator or conditional operator. The ternary operator acts like a shorthand version of the if-else condition. The general format of the ternary operator is:Expr1? Expr2: Expr3
For example: x=10
Y=x>9?100:200;
The sizeof Operator: The sizeof() operator returns the size (in bytes) of an object or data types.
For example:
Int x;
Sozeof(x);
Data Input and Output: cin and cout are the two predefined objects which represent standard input and output stream. These objects are the members of iostream class. Hence the header file should be included in the beginning of all the programs.cout: The cout is used to display an object onto the video screen. The >varaiable;
Write a program to calculate the sum of two numbers:
#include
#include
void main()
{
clrscr();
int a,b;
couta;
coutb;
cout