Skip to the content

onlineexamguide

  • Home
  • Courses
  • Engg. Interview
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • Aptitude Tricks
    • Computer Knowledge
    • Logical Reasoning Tricks
    • Networking
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
  • Online Exam
    • Aptitude Tricks
    • Computer Knowledge
    • Logical Reasoning Tricks
    • Networking
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
  • User Login

C++ Programming set 1 :: OOPS Concepts

c++ programming tutorials

The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods. While designing C++ modules, we try

C++ What is OOP ?

OOP stands for Object-Oriented Programming.

Procedural programming is about writing procedures or functions that perform operations on the data, while object-oriented programming is about creating objects that contain both data and functions.

OOP has several advantages over procedural programming:

  • OOP is faster and easier to execute
  • and OOP provides a clear structure for the programs
  • OOP helps to keep the C++ code DRY “Don’t Repeat Yourself”, and makes the code easier to maintain, modify and debug
  • OOP makes it possible to create full reusable applications with less code and shorter development time

Tip: The “Don’t Repeat Yourself” (DRY) principle is about reducing the repetition of code. You should extract out the codes that are common for the application, and place them at a single place and reuse them instead of repeating it.


C++ What are Classes and Objects?

Classes and objects are the two main aspects of OOP.

Look at the following illustration to see the difference between class and objects:

class

Fruit

objects

Apple

Banana

Mango

Class and Objects

A class is like a blueprint of data member and functions and object is an instance of class. For example, lets say we have a class Car which has data members (variables) such as speed, weight, price and functions such as gearChange(), slowDown(), brake() etc. Now lets say I create a object of this class named FordFigo which uses these data members and functions and give them its own values. Similarly we can create as many objects as we want using the blueprint(class).

//Class name is Car
class Car
{
    //Data members
    char name[20];
    int speed;
    int weight;
 
public:
    //Functions
    void brake(){
    }
    void slowDown(){
    }
};
 
int main()
{
   //ford is an object
   Car ford; 
}

Abstraction

Abstraction is a process of hiding irrelevant details from user. For example, When you send an sms you just type the message, select the contact and click send, the phone shows you that the message has been sent, what actually happens in background when you click send is hidden from you as it is not relevant to you.

Encapsulation

Encapsulation is a process of combining data and function into a single unit like capsule. This is to avoid the access of private data members from outside the class. To achieve encapsulation, we make all data members of class private and create public functions, using them we can get the values from these data members or set the value to these data members.

Inheritance

Inheritance is a feature using which an object of child class acquires the properties of parent class.

#include <iostream>
using namespace std;
class ParentClass {
  //data member
  public:
    int var1 =100;
};
class ChildClass: public ParentClass {
  public:
  int var2 = 500;
};
int main(void) {
  ChildClass obj;
}

Now this object obj can use the properties (such as variable var1) of ParentClass.

Polymorphism

Function overloading and Operator overloading are examples of polymorphism. Polymorphism is a feature using which an object behaves differently in different situation.
In function overloading we can have more than one function with same name but different numbers, type or sequence of arguments.

Polymorphism Example

#include <iostream>
using namespace std;
class Sum {
  public:
    int add(int num1,int num2){
      return num1 + num2;
    }
    int add(int num1, int num2, int num3){
      return num1 + num2 + num3;
    }
};
int main(void) {
   //Object of class Sum
   Sum obj;

   //This will call the second add function
   cout<<obj.add(10, 20, 30)<<endl;

   //This will call the first add function
   cout<<obj.add(11, 22);
   return 0;
}

Output:

60
33

Object-oriented programming online test

[WpProQuiz 183]

Write a comment Cancel reply

You must be logged in to post a comment.

*
  • किस राज्य/केंद्र शासित प्रदेश ने ‘कोडवा हॉकी महोत्सव’ (Kodava Hockey Festival) की मेजबानी की?

  • उत्तर – कर्नाटक

  • हाल ही में खबरों में रहा बरदा वन्यजीव अभयारण्य (Barda Wildlife Sanctuary) किस राज्य/केंद्र शासित प्रदेश में स्थित है?

  • उत्तर – गुजरात

  • किस देश ने ‘सऊदी-ईरान सम्बन्ध सामान्यीकरण’ शांति समझौते की मध्यस्थता की?

  • उत्तर – चीन

  • ‘संयुक्त राष्ट्र 2023 जल सम्मेलन’ (United Nations 2023 Water Conference) का मेजबान कौन सा देश है?

  • उत्तर – अमेरिका

  • ‘अल-मोहद-अल हिंदी-23’ (Al-Mohed-Al Hindi-23) अभ्यास भारत और किस देश के बीच आयोजित किया जा रहा है?

  • उत्तर – सऊदी अरब

  • सेमी-हाई-स्पीड वंदे भारत एक्सप्रेस ट्रेन चलाने वाली पहली महिला लोको पायलट कौन हैं?

  • उत्तर – सुरेखा यादव

  • भारतीय रिजर्व बैंक ने 2023 तक कितने देशों के बैंकों को रुपये में व्यापार करने की अनुमति दी थी?

  • उत्तर – 18

  • MD15 बसों का प्रायोगिक परीक्षण और M100 (100% मेथनॉल) का प्रोटोटाइप किस शहर में लॉन्च किया गया?

  • उत्तर – बेंगलुरु

  • फरवरी 2023 में भारत में थोक मूल्य सूचकांक (WPI) आधारित मुद्रास्फीति कितनी है?

  • उत्तर – 3.85%

  • किस संस्थान ने एक व्यापक स्व-निगरानी ढांचा ‘ATL सारथी’ लॉन्च किया है?

  • उत्तर – नीति आयोग

  • उस चक्रवात का क्या नाम है जिससे मलावी और मोज़ाम्बिक में तेज़ हवाएँ चलीं और मूसलाधार बारिश हुई?

  • उत्तर – फ्रेडी

  • ऑस्कर 2023 इवेंट के दौरान किस फिल्म ने सात पुरस्कार जीते?

  • उत्तर – Everything Everywhere All at Once

  • MoSPI के हालिया आंकड़ों के अनुसार, फरवरी 2023 में भारत की खुदरा मुद्रास्फीति कितनी दर्ज की गई?

  • उत्तर – 6.44%

  • कौन सा राज्य/केंद्र शासित प्रदेश ‘साझा बौद्ध विरासत पर पहला अंतर्राष्ट्रीय सम्मेलन’ का मेजबान है?

  • उत्तर – नई दिल्ली

  • किस राज्य ने राज्य के कार्यकर्ताओं को राज्य सरकार की नौकरी में 10% क्षैतिज आरक्षण को मंजूरी दी?

  • उत्तर – उत्तराखंड

  • Unique Land Parcel Identification Number (ULPIN) कितने अंकों वाला एक अल्फा-न्यूमेरिक नंबर है?

  • उत्तर – 14

  •  किस संस्था ने ‘Landslide Atlas of India’ जारी किया?

  • उत्तर – इसरो

  • किस केंद्रीय मंत्रालय ने ‘लीन योजना’ (LEAN Scheme) शुरू की?

  • उत्तर – MSME मंत्रालय

  • कौन सा केंद्रीय मंत्रालय ‘World Food India-2023’ कार्यक्रम की मेजबानी करने जा रहा है?

  • उत्तर – खाद्य प्रसंस्करण उद्योग मंत्रालय

  • माधव राष्ट्रीय उद्यान (Madhav National Park), जो हाल ही में खबरों में था, किस राज्य/केंद्र शासित प्रदेश में है?

  • उत्तर – मध्य प्रदेश

  • किस राज्य/केंद्र शासित प्रदेश ने विभिन्न क्षेत्रों में शहर के विकास का मार्गदर्शन करने के लिए ‘2041 के लिए मास्टर प्लान’ जारी किया?

  • उत्तर – नई दिल्ली

  • हाल ही में ख़बरों में रहा ‘Safe Harbour Principle’ किस अधिनियम से संबंधित है?

  • उत्तर – सूचना प्रौद्योगिकी अधिनियम, 2000

  • 2023 में शंघाई सहयोग संगठन (SCO) की अध्यक्षता किस देश के पास है?

  • उत्तर – भारत

  • हाल ही में खबरों में रहा टोरिनो स्केल (Torino Scale) किस क्षेत्र से जुड़ा है?

  • उत्तर – अंतरिक्ष विज्ञान

  • कृत्रिम बुद्धि (artificial intelligence) द्वारा संचालित दुनिया के पहले रेडियो प्लेटफॉर्म का नाम क्या है?

  • उत्तर – RadioGPT

  • नासा के क्यूरियोसिटी रोवर (Curiosity Rover) ने हाल ही में किस ग्रह पर क्रिपस्कुलर किरणों (crepuscular rays) को कैप्चर किया है?

  • उत्तर – मंगल

  • कौन सा केंद्रीय मंत्रालय ‘स्वदेश दर्शन 2.0 कार्यक्रम’ लागू करता है?

  • उत्तर – पर्यटन मंत्रालय

  • हाल ही में Prevention of Money Laundering Act को किन उत्पादों को शामिल करने के लिए विस्तारित किया गया था?

  • उत्तर – वर्चुअल डिजिटल संपत्ति

  • किस देश ने National Platform for Disaster Risk Reduction (NPDRR) के तीसरे सत्र की मेजबानी की?

  • उत्तर – भारत

  • किस राज्य के राज्यपाल ने राज्य मंत्रिमंडल द्वारा पारित ऑनलाइन जुआ निषेध विधेयक (Prohibition of Online Gambling Bill) को लौटा दिया है?

  • उत्तर – तमिलनाडु

  • भारत में पहली बार माइम्युसेमिया सीलोनिका (Mimeusemia ceylonica), दुर्लभ पतंगे की प्रजाति को किस राज्य में देखा गया है?

  • उत्तर – केरल

  • किस देश ने ‘Illegal Migration Bill’ पेश किया?

  • उत्तर – यूके

  • किस देश ने 25 वर्षों में पहली बार महिलाओं के लिए सैन्य सेवा खोली है?

  • उत्तर – कोलंबिया

  • केंद्र ने हाल ही में NAFED, NCCF को किस उत्पाद की खरीद के लिए बाजार में तत्काल हस्तक्षेप करने का निर्देश दिया है?

  • उत्तर – लाल प्याज

  • ‘ट्रोपेक्स 2023’ किस देश द्वारा आयोजित एक प्रमुख परिचालन स्तर का अभ्यास है?

  • उत्तर – भारत

  • किस संस्था ने ‘Global Greenhouse Gas Monitoring Infrastructure’ पेश किया?

  • उत्तर – WMO

  • किस केंद्रीय मंत्रालय ने ‘स्वच्छोत्सव’ महिलाओं के नेतृत्व में स्वच्छता अभियान शुरू किया?

  • उत्तर – आवास और शहरी मामलों के मंत्रालय

  • सल्हौतुओनुओ क्रूस (Salhoutuonuo Kruse) ने किस राज्य की पहली महिला कैबिनेट मंत्री बनकर इतिहास रचा है?

  • उत्तर – नागालैंड

  • कौन सा शहर वित्तीय समावेशन के लिए वैश्विक भागीदारी की दूसरी बैठक का मेजबान था?

  • उत्तर – हैदराबाद

  • डॉ माणिक साहा ने 2023 में किस भारतीय राज्य के मुख्यमंत्री के रूप में शपथ ली?

  • उत्तर – त्रिपुरा

  • ‘डिजिटल इंडिया बिल’ किस केंद्रीय मंत्रालय से जुड़ा है?

  • उत्तर – इलेक्ट्रॉनिक्स और आईटी मंत्रालय

  • ड्राफ्ट केंद्रीय विद्युत प्राधिकरण विनियम (Draft Central Electricity Authority Regulations) हाल ही में किस प्रजाति की रक्षा के लिए जारी किया गया था?

  • उत्तर – ग्रेट इंडियन बस्टर्ड

  • किस देश ने ‘International Big Cat Alliance’ बनाने का प्रस्ताव दिया है?

  • उत्तर – भारत

  • ब्रह्मोस मिसाइल को रूस के NPO मशीनोस्ट्रोयेनिया और भारत के किस संगठन के बीच साझेदारी से विकसित किया गया है?

  • उत्तर – DRDO

  • दुनिया का पहला 200 मीटर लंबा बैंबू क्रैश बैरियर ‘बाहु बल्ली’ किस राज्य में स्थापित किया गया है?

  • उत्तर – महाराष्ट्र

  • किस देश ने लगभग 8.5 मिलियन मीट्रिक टन लिथियम अयस्क की खोज करने का दावा किया है?

  • उत्तर – ईरान

  • किस संस्था ने ‘Women, Business and the Law Index’ जारी किया?

  • उत्तर – विश्व बैंक

  • 2021-22 के लिए आवधिक श्रम बल सर्वेक्षण (PLFS) रिपोर्ट के अनुसार, कृषि क्षेत्र में रोजगार का अंश कितना है?

  • उत्तर – 45.5%

  • किस संस्था ने ‘Advanced Towed Artillery Gun System (ATAGS)’ डिजाइन किया है?

  • उत्तर – DRDO

  • हाल ही में खबरों में रहा HUID नंबर किस तत्व/उत्पाद से जुड़ा है?

  • उत्तर – सोना

  • किन संस्थानों ने ‘More than a billion reasons: The urgent need to build universal social protection’ शीर्षक से रिपोर्ट जारी की?

  • उत्तर – UNICEF- ILO

  • केंद्रीय सिंचाई एवं विद्युत बोर्ड (CBIP) पुरस्कार किस संस्था को प्रदान किया गया?

  • उत्तर – NTPC

  • किस संस्था ने ‘Mind the Gender Gap’ रिपोर्ट जारी की?

  • उत्तर – CFA Institute

  • हाल ही में खबरों में रही ‘समर्थ योजना’ (SAMARTH scheme) किस मंत्रालय से जुड़ी है?

  • उत्तर – कपड़ा मंत्रालय

  • राष्ट्रीय सुरक्षा दिवस (National Safety Day) 2023 की थीम क्या है?

  • उत्तर – Our Aim – Zero Harm

  • कौन सा शहर ‘G20 विदेश मंत्रियों की बैठक (FMM)’ का मेजबान है?

  • उत्तर – नई दिल्ली

  • किस देश ने इंडो-पैसिफिक टेक दूत (Indo-Pacific tech envoy) की घोषणा की?

  • उत्तर – यूके

  • किस बैंक ने सिटीग्रुप के भारतीय उपभोक्ता कारोबार का अधिग्रहण पूरा कर लिया है?

  • उत्तर – Axis Bank

  • किस केंद्रीय मंत्रालय ने ‘Grievance Appellate Committee (GAC)’ लॉन्च की?

  • उत्तर – इलेक्ट्रॉनिक्स और आईटी मंत्रालय

  • ‘Indian States’ Energy Transition’ रिपोर्ट के अनुसार, किन राज्यों ने स्वच्छ बिजली में परिवर्तन में सबसे अधिक प्रगति की है?

  • उत्तर – कर्नाटक और गुजरात

  • धरोई आर्द्रभूमि (Dharoi wetland), जहाँ हाल ही में एक पक्षी सर्वेक्षण किया गया था, किस राज्य में स्थित है?

  • उत्तर – गुजरात

  • IMF के अनुसार, किस देश में 2023 में वैश्विक विकास में 15% योगदान देने की क्षमता है?

  • उत्तर – भारत

  • भारत के किस पड़ोसी देश ने सौर ऊर्जा के उपयोग को बढ़ाने के लिए ISA के साथ समझौता ज्ञापन पर हस्ताक्षर किए?

  • उत्तर – बांग्लादेश

  • अंतर्राष्ट्रीय बौद्धिक संपदा सूचकांक 2023 में भारत का रैंक क्या है?

  • उत्तर – 42

  • कौन सा राज्य ‘वैश्विक उत्तरदायी पर्यटन शिखर सम्मेलन’ (Global Responsible Tourism Summit) का मेजबान है?

  • उत्तर – केरल

  • ‘UPI LITE पेमेंट्स’ लॉन्च करने वाला पहला प्लेटफॉर्म कौन सा है?

  • उत्तर – पेटीएम पेमेंट्स बैंक

  • किस संस्था ने भारत का पहला म्यूनिसिपल बॉन्ड इंडेक्स लॉन्च किया?

  • उत्तर – NSE

  • किस शहर का नाम बदलकर ‘छत्रपति संभाजीनगर’ कर दिया गया है?

  • उत्तर – औरंगाबाद

  • भारत की G-20 अध्यक्षता के तहत W20 इंसेप्शन मीटिंग की मेजबानी कौन सा शहर कर रहा है?

  • उत्तर – औरंगाबाद

  • कौन सा शहर ‘International Bio-resource Conclave & Ethno-pharmacology Congress 2023’ का मेजबान है?

  • उत्तर – इंफाल

  • फेंटानिल और पशु ट्रैंक्विलाइज़र का मिश्रण जिसे ज़ाइलाज़ीन कहा जाता है, जिसे ‘ट्रांक डोप’ के रूप में जाना जाता है, किस देश में चिंता पैदा कर रहा है?

  • उत्तर – अमेरिका

  • किस राज्य को ‘Foundational Literacy and Numeracy Index 2022’ में शीर्ष प्रदर्शन करने वाला स्थान मिला?

  • उत्तर – पश्चिम बंगाल

  • किस देश ने ‘National Green Fiscal Incentives Policy Framework’ लॉन्च किया?

  • उत्तर – केन्या

  • काजीरंगा राष्ट्रीय उद्यान किस राज्य में स्थित है?

  • उत्तर – असम

  • ‘राष्ट्रीय स्वास्थ्य प्राधिकरण की स्कैन एंड शेयर सर्विस’ किस योजना के तहत शुरू की गई थी?

  • उत्तर – आयुष्मान भारत डिजिटल मिशन

  • किस देश ने ‘कमर्शियल आर्म्स ट्रांसफर (CAT) पॉलिसी’ लॉन्च की है?

  • उत्तर – अमेरिका

  • हाल ही में खबरों में रही ‘INS सिंधुकेसरी’ क्या है?

  • उत्तर – पनडुब्बी

  • 2022 में किस देश की प्रजनन दर दुनिया में सबसे कम 0.78 है?

  • उत्तर – दक्षिण कोरिया

  • हाल ही में खबरों में रहा रिड्यू कैनाल स्केटवे (Rideau Canal Skateway) किस देश में है?

  • उत्तर – कनाडा

Recent Posts

  • Phasor Diagram of 3 Phase Induction Motor
  • बौद्ध कालीन शिक्षा
  • Rotating Magnetic Field in 3 Phase Induction Motor
  • Squirrel Cage Induction Motor
  • वैदिक कालीन शिक्षा
  • Slip Ring Induction Motor
  • 3 phase induction motor Definition & Working Principle
  • Synchronous Motors – Important Questions and Answers
  • Starting Methods of Synchronous Motor
  • Torque and Power Relation
  • Phasor Diagram for Synchronous Motor
  • Synchronous Motor: Applications, Starting Methods & Working Principle
  • Prime mover
  • Parallel Operation of Alternators
  • Slip Test on Synchronous Machine

onlineexamguide

onlineexamguide.com is the ultimate guide that will keep you updated about almost every Exam & Interviews . We aim to provide our readers with an informative details that have been occurring in Examination . Here at onlineexamguide.com , we focus on delivering our readers with the latest exam Pattern Mock test

We Provide Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Quick links

  • About us
  • Privacy Policy
  • Instructor Registration
  • Student Registration
  • Java Programming
  • C programming
  • C++ programming
  • Aptitude Tricks

Follow us

Free Online Mock Test

  • UPTET PRIMARY Online Test Series
  • Super TET Mock Test in Hindi 2023
  • CTET Mock Test 2022 Paper 1
  • SSC CHSL Online Mock Test
  • SSC MTS Mock Test 2023
  • SSC CGL Mock Test
  • SSC GD Mock Test
  • ccc online test

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Contact us

For any queries

Email us on - admin@onlineexamguide.com

We will response fast as much as we can
Copyright © 2023 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.