C++ Tutorial
C- Stuctured Programming Language/ procedural programmingC++ :
- Object oriend Programming Language developed by Bjarne Stroustrup in 1980 at AT&bell Labs
- C++ is also an case sensitive Language.
Object Oriented Programming:
It works on real time objects.And provide the modules to develope our code easily and we can maintain our code using OOP.
OOP Concepts:
1. Object:
Object is a real world Entity. We can Identify any object by identifying it's characterstics and Behaviour.Characterstics Behaviour
Attributes Action
Properties Function or Method
EX: CAR
Model No Drive()
Color brake()
Price stop()
2. Class:
Class is a group of Similar kinds of Objects which have same attributes and actions.3. Abstraction:
It is process of hiding the functionality/ Implementation and showing the essentioal things.Ex: ATM, MEtro stations Entry/exit gate
4. Encapsulation:
Wrapping up of data and it's behaviour into a single unit.Ex: class
5. Inheritance:
It is the process of adopting the features of Base class into Derived class.Super Class --------------- Parent Class ---------Base class
Sub Class ------------------ Child Class ---------Derived Class
6. Polymorphism:
It is a greek word where Poly -ManyMorohism ---- forms
i.e. one thing many forms.
Basic Structure of C++ program:
#include<header file>using namespace std;
int main()
{
Statements;
}
#include : preprocessor
header File: iostream.h : input output Stream
cin>> --------Used for Data input
cout<< ------- Used for Output
int main(): starting function of any program with return type int.
Statements: statements inclludes following:
variable declaration;
variable initialization;
computational statements;
other statements;
Variable : Variable is a named memory location. Which stores the value at a particular memory location.
EX: a = 10;
Where a ======== varibale
10 ======== Value
Data Types:
1. Pre define : int, char, float,double, long,
2. Reference : class, struct,enum,....
1.WAP to print the Message "Welcome to C++ World!!".
#include <iostream>
using namespace std;
int main()
{
cout<<"Welcome to C++ World";
return 0;
}
2. WAP to add two numbers by taking input from user
#include <iostream>
using namespace std;
int main()
{
int n1,n2, res;
cout<<"Enter the number 1:";
cin>>n1;
cout<<"Enter the number 2:";
cin>>n2;
res = n1+ n2;
cout<<"Addition = "<<res;
return 0;
}
Escape Sequence
Escape Sequence | Meaning |
---|---|
\n | New Line |
\r | Carrige Return or Enter |
\t | Horizontal Tab Space |
\v | Vertical Tab Space |
\\ | To Print BackSlash |
\? | To Print Question Mark |
\' | To Print Single Quote |
\" | To Print Double Quote |
Operators:
An operator is a symbol that defines the actionperformed on operands.EX: a + b
where a, b are Operands
+ is an Operators used to perform the task.
Types of Operators in C++ are as Follows:
1. Assignment Operators
[=,+=,-=,*=,/=,%=]
2. Arithmetic
[+,*,-,/,%]
3. Relational/ Comparision
[>,<,>=,<=,==,!=]
4. Logical
[And (&&), OR(||), Not(!)]
5. increment/ decrement
inc dec
pre ++a --a
post a++ a--
6. Bitwise: works for Binary Data only
[And (&), OR(|), Not(~),XOR(^)]
7 .sizeof
These Operators falls into three categories.
a) Unary : Where we can use single operand
b) Binary : Where we can use two operands.
c) Ternary: Where we can use Three Operands. It is also known as Conditional Operator.
Syntax: (condition):true:false;
Table of Operators
Operators | Symbols | Type | Example |
---|---|---|---|
Assignment | =, +=, -=, /= ,*= ,%= | Unary | a=10 |
Arithmetic | +,-,/,*,% | Binary | a+b a-b a*b a/b a%b |
Relational | > , <, >=, <=, ==, !=(Not Equal) | Binary | It gives Result in Boolen value True/False a > b a< b a>=b a<=b a==b a!=b |
Logical | && (AND), ||(OR), !(Not) | Binary | It gives Result in Boolen value True/False a>b a>c a>b || a>c a!=b |
Increment/ Decrement | ++,--
inc dec pre ++a --a post a++ a-- |
Unary | a++, a-- |
Bitwise | And (&), OR(|), Not(~),XOR(^) | Binary except Not is a Unary Operator | Works on Binary Data only. a&b, a^b, a|b, ~a |
Comments
Post a Comment
If you have any doubts, Please let me Know