1. Jubair Ahmed Junjun
B.Sc in Computer Science & Engineering(CSE)C++Lecture.
https://www.youtube.com/c/JubairAhmedJunjun/videos?view_as=subscriberYouTube :
2. C++
• C++ is Known to be a very powerful Computer programming language.
• C++ is a general purpose,case sensitive,OOP(Object oriented programming language).
Uses of C++
• It's use to developed game engines,games and desktop apps,art applications,music
players etc.
• C++ is being highly used to write device drivers and other software.
Jubair Ahmed Junjun
B.Sc in Computer Science & Engineering(CSE)
3. History of C++
• C++ programming language was developed
in 1980 by Bjarne Stroustrup at bell
laboratories of AT
• Bjarne Stroustrup is known as the founder of
C++.
• C++ was derived from c,and is largely based
on it.
• 4th most used language
4. Overlap of C,C++ and Java
Jubair Ahmed Junjun
B.Sc in Computer Science & Engineering(CSE)
C++
C Java
5. Feature of C++
• Simple
• Mid Level Programming Language.
• Rich - Library
• Memory management.
• Fast speed.
• Pointers.
• Recursion
• OOP(Object oriented programming).
• Compiler based. Jubair Ahmed Junjun
B.Sc in Computer Science & Engineering(CSE)
6. প্রোগ্রোম :ক োনএ টি সমসযো সমোধোননর জনয ম্পিউটোনরর
ভোষোয়(0,1) ম্পিম্পিত ম্পনর্দ নের সমম্পিন কেগ্রোমবনি।
প্রোগ্রোমমিং ভোষো :
কেোগ্রোমরচনোর জনয ম্পবম্পভন্ন (েব্দ,বর্দ,অং ,সংন ত) এবং এগুনিো
ম্পবনযোনসর ম্পনয়মম্পমম্পিনয় ততম্পর রোহয় কেোগ্রোম্পমংভোষো।নমমন:
C,C++,Java,Assemblylanguageetc.
প্রোগ্রোম(P R O G R A M )
ও
প্রোগ্রোমমিং
ভোষো(P R O G R A M M I N G L A N G U A G E )
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
7. 1.Source code and Object code
2.What is Translator?
3.Types of Translator
4.How to Translator
work(assembler,compiler,interpret
er)
TOPIC :
TRANSLATOR
(অনু বোদক প্রোগ্রোম)
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
11. Compiler(কম্পোইলোর)andInterpreter(ইন্টোরসরটোর)
COMPILER( িোইিোর)
সিূর্দ কেোগ্রোমন এ সোনথ অনুবোর্ নর।
কম সব কেোগ্রোম্পমং ভোষোন িোইি রো হয় : --
C,C++,object-
c,C#,Pascal,COBOL,ADA,Visual
Basic,Smalltalk etc.
INTERPRETER(ইন্টোরনেটোর)
সিূর্দ কেোগ্রোমন এ িোইন এ িোইন নর অনুবোর্ নর।
কমসব কেোগ্রোম্পমং ভোষোন ইন্টোরনেটোর রো হয়
: Basic,php,python,Perl,Ruby,javascript
etc.
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
12. কোসেরধোপেমূহ
COMPILER(কম্পোইলোর) INTERPRETER(ইন্টোরসরটোর)
Source
code Compiler
List of error
Object code
1st Step :
2nd Step :
Input
Object
code
Output
Source
code Interpreter Output
Input
Total program translate at a timethen
execute
Line by line translate then
execute
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
13. কম্পোইলোরএবিং ইন্টোরসরটোসরর মসধযপোর্থকয
কম্পোইলোর ইন্টোরসরটোর
➢ সিূর্দ কেোগ্রোমন এ সোনথ অনুবোর্ নর।
➢ কেোগ্রোনমর সব ভূ ি এ সোনথ ের্েদন নর ।
➢ িোইিোর দ্রুত োজ নর।
➢ এ বোর কেোগ্রোম িোইি রোর পর পরবতী িোইি রনত হয় নো।
➢ বড় ধরননর ম্পিউটোনর কবম্পে বযবহোর হয়।
➢ এ িোইন এ িোইন নর অনুবোর্
নর।
➢ এ িোইন নর ভূ ি ের্েদন নর।
➢ ধীনর োজ রো।
➢ েম্পতটি োনজর পূনবর্ অনুবোর্ রোর
েনয়োজন হয়।
➢ মোইনরো ম্পিউটোনর কবম্পে বযবহোর
রো হয়।
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
14. অযোি ম্পরর্ম(Algorithm)
কম পদ্ধম্পতনত ক োন এ টি সমসযোন ধোনপ ধোনপ সমোধোন রো হয়,তোন অযোলগমরদম(Algorithm) বনি ।
কমমন : ম্পতনটি সংিযোর কমো ফি ম্পনর্দয় রোর অযোি ম্পরর্ম(Algorithm) ।
Step-1: Start
Step-2: Read/Input
Step-3: Summation of Three numbers.
Step-4: Print/Output
Step-5: End
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
16. প্লোচোটথ
(Flowchart)
কম পদ্ধম্পতনত ক োন কেোগ্রোমন ম্পচত্র বো েম্পতন র মোধযনম ে োে রো হয়।তোন কলোচোটদ বনি।
প্লোচোটথ
➢ System এ কডটোর
েবোহ েম্পরয়ো রর্,সংরক্ষর্ ও
ফিোফি ের্েদননর
ম্পর্ ম্পচম্পিতহয়,তোন System
Flowchartবনি।
➢ কেোগ্রোম রচনোর
সময় কম Flowchartততম্পর
রো হয়,তোন Program
Flowchartবনি।
System
Flowchart
Program
Flowchart
Provided by : Jubair Ahmed Junjun
B.Sc in Computer Science & Engineering(CSE)
24. C++Programএবিং এর মবমভন্ন অিংি ।
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World";
return 0;
}
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
Input output stream.এটিএ টি কহডোর ফোইি#include এর সোহোনময এটিন
কেোগ্রোনম সংমুক্ত রো হয়।
রসতযক প্রোগ্রোমমিং লযোঙ্গুসয়সের মকছু লোইসেমর ফোিংিনআসছ । প্তমমন মে++এরও আসছ । স্ট্যোন্ডোিথ মে ++লোইসেরীসতেমস্ত উপোদোনগুমল র
কোিকরো আসছ , যোসক namespace stdবলো হয়।
লোইসেমর ফোিংিন এররসতযকটি উপোদোনগুমলর বযবহোর প্যোগযতো অেথ ন করোর েনযই usingnamespace std;বযবহোরকরো হয়।
int একটি keyword ।কম্পোইলএবিং মনর্ বোসহর েময় মে/মে++ এ main() ফোিংিন
প্র্সক শুরু হয় ।তোই প্রোগ্রোসম এ ফোিংিনঅবিযই মলখসত হসব ।
cout<<হসে Standardoutputstream.
এটি দ্বোরো মমনটসর প্কোন মকছু রদিথন করো হয় ।Keyword,Returning 0 means
a successfultermination.
25. Escapesequence/Backslashcharacter
C++ কেোগ্রোনম ম্প ছু Backslash character বযোবোম্প র রো হয় ।মো ফোংেন ম্পহনসনব োজ নর ।
Character Escape Sequence Meaning
a (Alert)Bell
b Backspace
f Form feed
n Newline
r Carriagereturn
t HorizontalTab
v Verticaltab
o Null character
' Single quote
" Double quote
Backslash
? Question mark.
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
29. কটোন ন(Token)
A token is the smallest element of a program that is meaningful to the compiler.
Types of Token
✓ Keywords : int,float,while
✓ Identifiers : sum,main
✓ Constants : 100,555
✓ Strings : “JAJSoftTech”
✓ Special Symbols : [] () {}, ; * = #
✓ Operators : +,-,*,/,%
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
30. asm continoue float new signed try
auto default for operator sizeof union
break delete friend private static unsigned
case do go to protected struct virtual
catch double if public switch void
char else inline register template typedef
class enum int return this volatile
const extern long short throw while
Keywordহনিো এমন ম্প ছু সংরম্পক্ষতেব্দ,মোএ টি ম্পনম্পর্দ িঅথদ বহর্ রনবএবং কেোগ্রোনম এ টি ম্পনম্পর্দ ি োমদ সিোর্ন রনব।
মে++ প্রোগ্রোমমিং এ Keyword েমূহ :
Keyword
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
31. Keyword বযবহোনরনর ম্পনয়ম
➢Keyword িননো variable বো চিন র নোম ম্পহনসনব বযবহোর রো হয় নো।
➢Keyword সমূনহর েম্পতটি বর্দ small letterএর হয়।
➢মম্পর্ িননো দুটি keyword এ সোনথ বযবহোর রনত হয়,তোহনি মোঝিোনন ফো োাঁ স্থোন থো নত হনব।
➢keyword সমূনহর নোম এ টি এ েব্দ,অথদোৎ মোনঝ ক োন ফোাঁ ো স্থোন থোন নো।
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
32. Identifier
Identifiers are used as the general terminology for naming of variables, functions and
arrays. Some identifiers are used:
A-Z,a-z,0-9,$,_
Some valid and non-valid identifier example
Valid identifiers Non-valididentifiers
Number1,Int,std_name 1number,int, std name
Keyword(Reservedword)
Space can’tbe used
Digit can not be used
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
33. Constant
Constants are also like normal variables. But, only difference is, their values can
notbe modified by the program once they are defined. Constants refer to fixed
values.
Types of Constants :
✓Integerconstants– Example: 0, 1, 1218, 12482
✓Real or Floating point constants– Example: 0.0, 1203.03, 30486.184
✓Octal &Hexadecimalconstants– Example: octal: (013)8 = (11)10,Hexadecimal:(013)16= (19)10
✓Characterconstants-Example: ‘a’,‘A’, ‘z’
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
34. String&SpecialSymbols
In C, a string is a sequence of characters.
chargreeting[6]= {'H', 'e', 'l', 'l', 'o', '0'};
chargreeting[]= "Hello";
Special Symbols :The following special symbols are used in C having some special meaning and thus,
cannot be used for some other purpose.[] () {}, ; * = #
Brackets[]: Openingandclosing bracketsareused as arrayelement reference.These
indicatesingle and multidimensionalsubscripts.
Parentheses():These special symbols areused to indicatefunction calls andfunction
parameters.
Braces{}: These openingandendingcurly braces marksthestartandendofa block of
code containingmorethanone executable statement.
comma (, ): Itis used to separatemorethanonestatements like forseparating
parametersinfunction calls.
semi colon : It is anoperatorthatessentially invokes something called aninitialization
list.
asterisk(*): It is used to create pointervariable.
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
40. গোমণমতক ফরমুলোসক এসেসরিসনরূপোন্তর :
গোমণমতক এেসরিন েমতু লয মে এেসরিন
X = a2-2ab + b2 X=a*a– 2*a*b + b*b;
Area =√ s(s - a)(s - b)(s - c) Area = sqrt(s*(s-a)*(s-b)*(s-c));
x = Y X ==Y;
Y=AB2+C Y = A*B*B+C;
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
41. AssignmentOperator
Operator Example Full meaning
= X = x+5 X=x+5
+= X+=5 X=x+5
-+ X-=5 X=x-5
*= X*=y X=x*y
/= X/=5 X=x/5
%= X%=5 X=x%5
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
42. RelationalOperator
Operator Meaning Example Result
== Equal to 5==2 False
!= Not equalto 5!= 2 True
< Lessthan 5<2 False
> Greater than 5> 2 True
<= Lessthan or equal
to
5<=2 False
>= Greater than or
equalto
5>=2 True
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
43. LogicalOperator
Operator Name Example
&& Logical AND A&&B
|| Logical OR A||B
! Logical NOT !a
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
44. Conditional
Operator
A ternary operator pair "?:" is available in c construct
conditional expression of the forms.
Exp1 ? Exp2: Exp3;
Example :
If(a>b)
X=a;
Else
X=b;
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
45. UnaryOperator
Operator Meaning
+ Unary Plus
- Unary minus
++ Increment
-- Decrement
! Logical implement
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
& Addressofoperator
46. BitwiseOperator
Operator Meaning Example
& Binary ANDOperator (A& B) = 12, i.e., 00001100
| Binary OR Operator (A| B) = 61, i.e., 0011 1101
^ Binary Ex-OR Operator (A^ B) = 49, i.e., 0011 0001
>> Binary Right Shift Operator A >>2 = 15 i.e., 00001111
<< Binary LeftShift Operator A <<2 = 240 i.e., 1111 0000
~ Binary One'sComplement
Operator
(~A) = ~(60), i.e,. 1100 0011
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
47. Data Type in C++
Data ’রধরর্ন ইসোধোরর্ত কডটো টোইপ বিো হয় ।
Datatypes in C++
User define data-type Build in datatype Derive data-type
Integer Floating point number
int char float doublevoid bool
• Structure
• Union
• Class
• enumeration
• Array
• Pointer
• Function
• etc
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
48. Modifiers
Variable এ কম কডটো টোইপ বযবহোর রো হয়,কসগুনিো Modifier রো ।
4 types of Modifiers in C++
✓ signed.
✓ unsigned.
✓ long
✓ short
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
49. Data Type Size(in bytes) Range
shortint 2 -32768 to 32767
unsigned short int 2 0 to 65535
unsigned int 4 0 to 4294967295
int 4 -2147483648to2147483647
unsigned long int 4 0 to 4294967295
long long int 8 -(2^63)to (2^63)^-1
unsigned long long int 8 0 to 18446744073709551615
signed char 1 -128 to 127
unsigned char 1 0 to 255
float 4 3.4E - 38 to 3.4E + 38
double 8 1.7E-308 to 1.7E +308
long double 10 3.4E - 4932 to 3.4E + 4932
wchar-t 2 to 4 1 wide character
long int 4 -2147483648to2147483647
Bytes and Range
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
50. FormattingoutputinC++
ক োন এ টি Data type ক অনয এ টি Data type এ রূপোন্তর রো ।
Typecasting
▪showpoint
▪noshowpoint
▪fixed
▪setw()
▪setprecision
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
51. DecisionmakingStatement
Decision making statement is depending on the condition block need to be executedor
not which is decided by condition.
If the condition is "true" statement block will be executed,if condition is "false"then
statement block will not be executed.
Therearethreetypesof decision makingstatement:
➢ if
➢ if-else
➢ switch
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
52. if -Statement
Basic Syntax :
if(condition)
{
.......
.......
}
Condition
ConditionBlock
Flowchart:
if condition
is false
if condition
is true
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
56. Loops in C++
A loop statementallowsusto executeastatementorgroupof statementsmultiple times.
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
forloop
while loop
do...while loop
nested loop
Sr.No Loop Type & Description
1 while loop
Repeats a statementor group of statements while agiven conditionis true. It tests the condition
beforeexecutingthe loop body.
2 for loop
Executes a sequence of statementsmultiple times andabbreviatesthe code thatmanagesthe loop
variable.
3
do...while loop
Itis more like a while statement, except thatit tests the conditionatthe end of theloop body.
4 nestedloops
You canuse oneor moreloops inside any other while, for,or do..while loop.
C++programminglanguageprovidesthefollowingtypesofloopsto handle looping
requirements.
60. for ( init; condition; increment ) {
for ( init; condition; increment ){
statement(s);
}
statement(s);
}
do{
statement(s);
do{
statement(s);
}while(condition);
}while(condition);
while(condition){
while(condition){
statement(s);
}
statement(s);
}
nested loops in c++
while loop do...while for loop
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
Basic Syntax :
61. JumpStatementinC++
jump statements are used to interrupt the normal flow of program.
Types of Jump Statements :
•Break
•Continue
•GoTo
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
62. goto label;
- - - - - - - - - -
- - - - - - - - - -
label:
- - - - - - - - - -
- - - - - - - - - -
int a=0;
while(a<10)
{
a++;
if(a==5
continue;
cout << "nStatement " << a;
}
cout << "nEnd of Program.";
}
Thebreakstatementis
usedinside loopor switch
statement.
Jump Statements
break continue Go to
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
Basic Syntax :
while(a<=10)
{
if(a==5)
break;
cout << "nStatement " << a;
a++;
}
cout << "nEnd of Program.";
}
The continue statement is also
used inside loop.
The goto statement is a jump
statement which jumps from one
point to another point within a
function.
63. Array
An array is a collection of variable of same data type.
Array declaration :
data_typearray_name[array-size]
Example : int mark[100]
Array initialization:
int marks[0]= 80;
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
Initialization array during declaration :
int marks[5]= {80,65,75,82,45};
64. TypesofArray
Array
Multi-dimentional arraysOne - dimentional array
or
Three dimentionalarrayTwodimentional array
or
matrix arrays
Linear arrays
Exm : int marks[10];
Exm : int marks[2][3]; Exm : int marks[2][3][2];
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
65. Pointer(*)
Pointer is a variable that stores/points the address of another variable.
Pointer এমন এ টি variable মোর মনধয অনয এ টো variable এর address, store ম্প ংবো points রনত পোম্পর ।
Declarationof pointers:
data_type * variable_name.
Example : int * p;
asterisk symbol
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
66. Symbolofpointer
Therearetwosymbols of pointer:
i.&(address of variable) :Thissymbol used to get the address ofthe variable .
ii. asterisk (*): It is used to create pointer variable.
int x = 5;
int *p;
cout<<x<<endl;
cout<<&x<<endl;
cout<<p<<endl;
cout<<*p<<endl;
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
67. Function
A function is a group of statement that perform a particular task.
ক োন এ টি ম্পনম্পর্িদ োজ সিোর্ননর জনয অনন গুনিো statement এর সমন্বনয় ঠিত single এ টি unit ক Function বনি ।
Function
Libraryfunction
User-definedfunction▪ কম function গুনিো ততম্পর রো আনছ ।
get ch()
toupper()
toloweer()
pow()
sqrt()
▪ কম function গুনিো ততম্পর রো হয়।
Provided by:JubairAhmed Junjun
B.ScinComputerScience&Engineering(CSE)
68. Declarationof a function
void addition(int a,int b)
{
int sum = a+b;
cout<<sum;
}
Return type Function name
Parameter
Body of
the
function
Advantageoffunction :
➢ Code Reusability.
➢ Can use the same function for different
inputs.
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
69. Function Overloading
• Function overloading হনিো এমন এ টো process কমিোনন এ র অম্পধ ফোংেননর নোম এ ই থো নব ,ম্প ন্তু পযোরোম্পমটোর ম্পভন্ন হনব ।
i.Multiple functions with the samename.
ii.differentparameters.
Example :
void sum(int a,intb)
{
int sum =a+b;
cout<<sum<<endl;
}
void(int a,intb,int c)
{
int sum = a+b+c;
cout<<sum<<endl;
}
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
70. Recursion
Recursion is a processwhere a function can call itself.
Recursion হনিো এমন এ টি process কমিোনন এ টি ফোংেন ম্পননজন ই ম্পননজন call নর ।
2 important poits in case of recursion :
▪ RecursionCall.
▪ Base case.
Example:
int fact(intn)
{
//base case
if(n==1)
return 1;
else {
return n*fact(n-1)
}
fact(4)
4*fact(3)
3*fact(2)
2*fact(1)
1
if n = 4;
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
71. OOP(ObjectOrientedProgramming)
➢C + OOP = C++.
➢Real life object .Example : Human , device etc.
➢Object-oriented programming consist to implement real-world entities like
inheritance, hiding, polymorphism, etc in programming.
➢The main aim of OOP is to bind togetherthe data and the functions that operate on
them so that no other part of the code can access this data exceptthat function.
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
73. Class and Object
DB CA
003 004002001
Object
ClassStudent
Name
Roll No
SetName()
SetRollNo()
State Variable
Behavior/function
Class
Fig : Class and object
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
74. ClassandObject
অনন গুনিো Object এর common collection ই হনিো Class ।
Class : A class is a template from which individual object can be created.
Object : Any class type variable is called object.
Declaration of classand object :
classStudent
{
private:
//data member
public :
//member function
}; Student AStudent B Student C
class
Object of Studentclass
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
75. Constructor
Constructor is a specialtype of function that is used to initialized
the object.
Constructor হনিো কস্পেোি টোইপঅব ফোংেন,মোরসোহোনময objectক initialized রো মোয় । অথদোৎobjectএর
মোন set নরকর্ওয়ো মোয় ।
Propertiesof constructor :
➢ Constructor is a specialtype of function.
➢ Constructor has the samenameas that of the class it belongs.
➢ It has no return type not even void.
➢ It's called automatically.
Typesof constructor
Defaultconstructor
Parameterizedconstructor
▪ Without parameter ▪ With parameter
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
76. Destructor
Destructor হসলো এমন একটি ফোিংিন যো Automatically create হসব ,যখন প্কোন একটি object delete বো
destroyed করসব ।
এ টি কেোগ্রোনম এ টি মোত্র Destructor বযবহোর করো যোয় ।
Destructor এর মসধয প্কোন parameter বযবহোর করোর রসয়োেন পসে নো ।
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
77. Access Specifiers in C++
ক োন এ টি Class এর Member ক অথদোৎ Variableঅথবো function ক বোইনর কথন Access রো মোনব ম্প মোনব নো
কসটো ম্পনভদ র রনব AccessSpecifiers এর উপর ।
In C++, there are three access specifiers:
o public - members are accessible from outside the class
o private - members cannot be accessed (or viewed) from outside the class
o protected - members cannot be accessed from outside the class, however, they
can be accessed in inherited classes. You will learn more about Inheritance later.
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
78. Syntax of Access specifiers
class Test
{
public:
int roll;
void display()
{
-----------------
-----------------
}
private:
string name;
protected:
float cgpa;
};
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
79. Encapsulation
Encapsulation is a processof combining variables and functions in a string unit(class).
Encapsulation িব্দটি এসেসছ capsul প্র্সক । capsul প্যমন অসনকগুসলো উপোদোন মনসয় গঠিত,প্তমমন Encapsulation হসলো এমন একটি
রসেে প্যখোসন variables এবিং functions প্ক একেোসর্ কসর একটি class এ রোখো হয় ।
Click to addtext
Encapsulations
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
80. this keyword
➢ Class variable এবং local variable এর মম্পর্ এ ই নোম হনয় মোয়,তোহনি Class variable ক বুঝোননোর জনয this
keyword বযবহোর রো হয় ।
➢ এন (this->) দ্বোরো ে োে রো হয় ।
Example :
classstudent{
public:
string name;
Student(string name)
{
this->name=name ;
}
void display(){
cout<<name<<endl;
}
};
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
81. Inheritance
The process of obtaining the datamembersandfunctions fromone class to anotherclass is knownas
inheritance.
ক োন এ টি class এর তবম্পেি অনয এ টি class এ ম্পননয় মোওয়োন বিো হয় Inheritance।
কম Class ক inherit রো হয়
কম Class টো inherit নর
Parent class/
Base class/
Super class/
Mother class
Child class/
Derived class/
Sub class/
Daughter class
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
82. class person{
public :
stringname;
int age;
void display1(){
cout<<"Name : "<<name<<endl;
cout<<"Age: "<<age<<endl;
}
};
class student{
public :
stringname;
int age;
int id;
void display2(){
cout<<"Name : "<<name<<endl;
cout<<"Age: "<<age<<endl;
cout<<"Id: "<<id<<endl;
}
};
class person : public person{
public :
int id ;
//stringname;
//int age;
//void display1()
void display2(){
cout<<"Id : "<<id<<endl;
}
};
If studentclassinherit theperson class
Inheritance Example
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
83. Importanceof inheritance
➢Code Resuability.
➢Application development time is less.
➢Application take less memory.
➢Inheritance makes the application code more flexible to change.
➢The program structure is short and concise which is more reliable.
➢It improves the program structure which can be readable.
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
84. Types of Inheritance
Thereare5 types of inheritance:
i. Single inheritance
ii. Multilevelinheritance
iii. Hierarchicalinheritance
iv. Multiple inheritance
v. Hybride inheritance
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
85. Single inheritance
In this shortof inheritance,onesubclass inheritsfromonesuperclass.
এ মোত্র Superclass ক মম্পর্ এ টি মোত্র sub class inherit নর , তোন Single inheritanceবনি।
classA
{
----------
----------
};
classB: public A
{
----------------
----------------
}
A
B
Super Class
Sub Class
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
86. Multilevelinheritance
In this shortof inheritance,thesuperclass foroneis the subclass foranother.
কমিোননএন রঅম্পধ super clas ও subclass থো নব,এবংএ টি আনর টিন inherit রনবতোন Multilevelinheritance
বসল।
class A
{
----------
----------
};
class B: public A
{
----------------
----------------
};
class C: public B
{
----------------
----------------
};
A
B
C
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
87. Hierarchicalinheritance
In shortof inheritance, multiple sub class derived fromsingle super class
মম্পর্ এ টি superclass ক অনন গুনিোsub class inherit নর, তোন Hierarchicalinheritanceবনি।
class A
{
----------
----------
};
class B: public A
{
----------------
----------------
};
class C: public A
{
----------------
----------------
};
A
B C D
Super Class
Sub Class
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
88. Multiple inheritance
In shortmultiple inheritance, A class can inheritmorethanoneclass.
➢ ক োনclass এন র অম্পধ class ক inherit রনি,তোন Multipleinheritance বনি।
➢ এ টি single class এর এ োম্পধ Parentclass থো ো ।
ClassA
SuperClass
ClassB
ClassC
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
89. Hybrid Inheritance
Hybrid inheritanceis a combination of more than one type of inheritance.
➢ এন র অম্পধ inheritance ম্পমম্পিত হনয়কম inheritance ততম্পরহয়, তোন Hybrid Inheritance বনি।
ClassA
ClassC
ClassB
ClassD
Single
inheritance
Multiple
inheritance
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
90. Function Overloading vs Function Overriding
➢ Parameterম্পভন্নম্পভন্ন থো নব ।
➢ Overloading একই class এর মসধয হয় ।
➢ Inheritanceএর রসয়োেন হয় নো ।
➢ একটি ফোিংিনঅনয ফোিংিনসকhide কসর নো ।
➢ Checked at compile time .
➢ Parameterএ ই থো নব ।
➢ এসকর অমধক class,অর্থ াোৎএকটি superclass এবিং
sub class এর মসধয হয় ।
➢ Inheritanceএর রসয়োেন হয়।
➢ একটি ফোিংিনঅনয ফোিংিনসকhide কসর ।
➢ Checked at run time.
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
91. Polymorphism
Polymorphism= Poly + morphism(2 Greekword).
Many Forms
প্কোন একটি মেমনসের মভন্ন মভন্ন রূপসক Polymorphism বসল ।
Polymorphism
Compile time Polymorphism Run time polymorphism
(Static or early binding) (Dynamic or late binging)
Exam : function overloading
Exam : function overriding
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
92. Abstraction
Abstraction is the process of hidingthe implementation details andshowingonly the
functionalityto the user.
Abstractionহনিো এমন এ টি েনসস কমটো implementation details টো hide নর শুধুমোত্র functionality
টো user ক কর্িোনব ।
কমোযো থো,Abstruction হনিো এমন এ টি ম্পজম্পনস কমটো অভযন্তরীর্ ম্পজম্পনস user ক কর্িোনব নো,কসটো hide নর রোিনব।ম্প ন্তু বোইনরর
ম্পজম্পনসগুনিো user Access রনত পোরনব ।
Example : ATM,Message send,Calletc.
Properties of Abstracclass:
➢ Object Can'nt be created.
Exm : Mobile user m;
➢ We can create pointer andreferenceof base abstractclasspoints.
Exam : Mobile user *m;
➢ It can have Constructor.
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
93. Function Template
ম্পভন্ন ম্পভন্ন datatypeএর জনয ম্পভন্ন ম্পভন্ন ফোংেন ততম্পর নো নর এমন এ টি ফোংেন ততম্পর রো মোর মনধয সব ধরনর্র datatype োজ রনব ।
অথদোৎ এমন এ টি ফোংেন ততম্পর রো মো int,float ম্প ংবো double type এর কম ক োন datatype এর জনয োজ রনব ।
template<class myTemplate>
myTemplate add(myTemplatea,myTemplateb)
{
returna+b;
}
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
94. ExceptionHandling
▪ Exception is a run time Error.
▪ Exception handlingis a machanismthatcan handletheexception.
Error
Compiletimeerror Run time error
Programরোন করোর পূসবথ । Programরোন করোর েময় বো চলোকোলীন েম য় ।
There are three Keyword in ExceptionHandling :
➢ Try
➢ Catch
➢ Throw
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
95. Try,Catch,throw
try catch throw
A try block identifies a block
of code for which particular
exceptionswill be activated.
It's followed by one or more
catch blocks.
catch− A programcatchesan
exceptionwith an exception
handlerat theplace in a program
where you wantto handlethe
problem. The catchkeyword
indicates the catchingof an
exception.
throw − Aprogramthrowsan
exceptionwhen a problem
shows up. This is done using
a throw keyword.
try {
// protectedcode
} catch( ExceptionNamee )
{
// code to handleExceptionName
exception
}
try {
// protectedcode
} catch( ExceptionNamee )
{
// code to
handleExceptionNameexc
eption
}
double division(int a, int b) {
if( b == 0 )
{
throw "Division by zero
condition!";
}
return (a/b);
}
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)
96. Join with me
Fbpage: https://www.facebook.com/jajsofttech
Fbgroup: https://www.facebook.com/groups/2704079586349093
YouTube:https://www.youtube.com/c/JubairAhmedJunjun/videos?view_as=subscriber
LinkedIn : https://www.linkedin.com/in/jubair-ahmed-junjun-4ab6a0177/
Providedby :Jubair AhmedJunjun
B.Sc inComputer Science&Engineering(CSE)