Introduction To OOPS Concept

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

Unit - 1

Introduction To CPP
Introduction :-
• C++ Programming Language ये OOP(Object-Oriented Programming) Language है, इससे
पहले भी 'Simula' ये भी OOP Language बनाई गयी थी |
• C++ Programming Language ये Middle Level Language है |
• C++ Programming को Windows, Linux, Mac OS या आदि Operating Systems पर चलाया जाता है
|

History of C++ :-
•C++ Programming Language को बनाने की शुरुआत 1979 में हुई |
•C Programming में ही कु छ बदल करके 'C with Classes' ये C का concept आया |
•'C with Classes' के साथ और भी कई concepts को बनाकर Bjarne Stroustrup ने 1983 में AT &
T's Bell Labs में C++ Programming का अविष्कार किया गया |
Advantage of OOP’s
OOPS द्वारा Develop किए जाने वाले Programs में निम्न विशेषताएं होती हैं-

1. Problem में Procedures के बजाए Data का महत्व है। यानी OOPS में Data को Primary Level पर रखा गया
है और Data पर Perform होने वाले Operations के Functions को Secondary Level पर रखा गया है।
2. Problem को Functions में विभाजित करने के बजाय Objects में विभाजित किया जाता है।
3. Data Structure को इस प्रकार से Design किया गया है, जो कि Object को Characterize करते हैं।
4. Data पर Perform होने वाले Operations के Functions को Object के Data Structure के साथ ही
Combined कर दिया गया है, जिसे Encapsulation कहते हैं।
5. Data को के वल Data के साथ Associate किए गए Functions ही Access कर सकते हैं, जिससे Data
External Functions के लिए Hidden रहता है। इस प्रक्रिया को OOPS में Data Hiding कहते हैं।
6. Objects आपस में Functions द्वारा Communication करते हैं। इस प्रक्रिया को Message Passing करना
कहते हैं।

7. आवश्‍यकता होने पर Object में नए Data व Data पर Perform होने वाले Operations को Add किया जा सकता है।

इस प्रक्रिया को OOPS में Inheritance कहते हैं।

8. Program Design में OOPS के Approach को Bottom-Up Approach कहते हैं।


Inheritance का प्रयोग करके एक Programmer बार-बार एक जैसी Coding लिखने से बच जाता है। वह एक बार लिखी
गई Coding को बार-बार Reuse कर पाने में सक्षम हो जाता है। Coding को Reuse करने के कारण Programmer

को Program Develop करने में कम समय लगता है और Program को Maintain करना सरल हो जाता है।

9. चूंकि, OOPS में Program का Data पूरी तरह से Outer World से Hide रहता है। Data को Access करने के

लिए अधिकृ त Member Functions ही उस Data को Access करने में सक्षम होते हैं। चूंकि, Program के Data

को कोई भी Unauthorized External Function Access करने में सक्षम नहीं होता है, इसलिए Accidental

Modifications से Data सुरक्षित रहता है।


10. एक ही Object के कई Instances बिना किसी Interference के एक ही Program में एक साथ
Exist हो सकते हैं।
11. Program को Objects में विभाजित करने के कारण Program Real World Concepts को
Logically ज्यादा बेहतर तरीके से Computer में Represent करने में सक्षम होता है।
12. OOPS पर आधारित Application को Upgrade, Modify व Change करना काफी सरल व
सुविधाजनक होता है।
बहुत ही जटिल समस्याओं के समाधान को भी
Control Structure

प्रोग्रामिंग भाषा में, प्रोग्राम के execution के flow को नियंत्रित करने के लिए जो स्टेटमेंट्स या
structures प्रयोग किये जाते है उन्हें control statements (structures) कहते है.
control statements दो प्रकार के होते है:-
1. conditional statements
2. loop statements
1. Conditional statement
1. If Statement :- if statement एक control statement है जिसका प्रयोग एक विशेष कं डीशन को test करने
के लिए किया जाता है. if Statement में अगर Condition true होती है तब Statement Execute होता है|

Syntax for if Statement :-

if(condition)
{
statement(s);
}
Example : -
class IfStatement {
public static void main(String[] args)
{
int number = 10; // checks if number is greater than 0
if (number > 0) {
System.out.println("The number is positive.");
}
System.out.println("Statement outside if block");
}
}
Output
The number is positive. Statement outside if block
If Else Statement :- if else Statement में अगर Condition true हो तो वो if का statement
Execute करता है | अगर Condition false होती है तो else का Condition करता है|

Syntax for if else Statement


if(condition)
{
statement(s);
}
else
{
statement(s);
}
Example :-
class MyifElse
{
public static void main(String args[])
{
int x = 3; if (x > 10)
{
System.out.println("Inner If");
}
else
{
System.out.println("Inner Else");
}
System.out.println("Outer If Else");
}
}

Output :Inner Else Outer If Else


Else If Statement :- else if Statement में अगर if की Condition true होती है तो if का
statement execute होता है | अगर if का condition false होता है तो वो अगले condition पर जाकर
check करता है | अगर वो condition true होता है तो वो उसका statement execute करता है | अगर कोई
भी condition true नहीं होती तो वो else का statement execute करता है |

Syntax for Else If Statement


if(condition)
{
statement(s);
}
else if(condition)
{
statement(s);
}
else
{
statement(s);
}
Example : -
class MyElseIf {
public static void main(String args[])
{
int x = 3;
if (x > 10)
{
System.out.println("x is greater than 10");
}
else if (x < 10)
{
System.out.println("x is less than 10"); }
else
{ System.out.println("x is equal to 10");
}
System.out.println("Outer Else If");
}
}
Output : x is less than 10 Outer Else If
Switch Case Statement :- Switch case statement में expression होता है और उससे
related कु छ cases होते है | जो case उस expression या declare किये हुए variable से match होती
है तब वो output में print होता है | अगर कोई भी case expression से match नहीं होती तो वो default का
statement output में print करेगा | आपको हर statement के बाद break लगाना पड़ता है, इसका मतलब वो
उसके पहले का statement ही print करेगा | अगर आप break नहीं लगाते तो वो पहला और दूसरा ये दोनों statement
को print करेगा | default case के बाद break नहीं लगाते |

Syntax for Switch Case Statement


switch (expression)
{
case value1 :
statement1;
break;
case value2 :
statement2;
break;
case value N :
statement N;
break;
default :
statement3 ;
}
Example :-
class MySwitch
{
public static void main(String args[])
{
int x = 1;
switch(x)
{
case 0:
System.out.println("x is equal to 0."); break;
case 1:
System.out.println("x is equal to 1."); break;
case 2:
System.out.println("x is equal to 2."); break;
default:
System.out.println("x is not found."); break;
}
}
}

Output :x is equal to 1.
Break Statement :- Break Statement Program के loops और switch case के
execution का काम किसी condition पर बंद कर देता है |

Syntax for Break Statement


break;
Output :
class MyBreak value of i is 0
{
public static void main(String args[]) value of i is 1
{ value of i is 2
int i=0; while ( i < 20 )
{ value of i is 3
System.out.println("value of i is %d\n", i); value of i is 4
i++;
if ( i == 10 ) value of i is 5
{ value of i is 6
break;
} value of i is 7
} value of i is 8
}
} value of i is 9
Continue Statement :- Continue Statement Program के loops के condition के हिसाब
से बीचवाले statements को skip कर देता है और बादवाले statement को execute करता है|
Syntax for Continue Statement :-
continue;
Example :- Output :
class MyContinue{ 0
public static void main(String args[]) 1
{ 2
int i; for(i=0; i<10; i++) 3
{ 4
if(i==7) 5
{ 6
System.out.println("Number "+ i +" is skipped."); Number 7 is skipped.
continue; 8
} 9
System.out.println(i);
}

}
}

You might also like