Posts

Showing posts with the label basics of cpp

Operator Overloading in C++ | Operator Overloading Explained With Real Life Examples

Image
 Operator Overloading in C++ What is operator overloading? Operator overloading means overloading an operator. 😑BRUH... I know you don't understand. Let me put it in a simple manner, suppose if I will say make a faulty calculator where "+"  will do subtraction, "-" will do division, "*" will do addition, "/" will do subtraction. So you will say what are you saying Dhruv.  Hmm, but I am not saying wrong it is possible by operator overloading. Let's understand by your favorite example - YOUR WEDDING EXAMPLE 😍🤣( Now don't start thinking about your bride just understand this concept you boiss) So Suppose when your bride was of 8-10 years then what she says that her father's house is her, her father's car is her car. But when her wedding happed then everything will change like the person is the same but now your bride will say Your car is her car also, your home is her home also. So here the person is the same but ownership is c...

Overloading Of Constructor In C++ | Constructor Overloading Explained With Real Life Examples

 Overloading Of Constructor In C++  What is constructor overloading? As you know what is a constructor  and also what is function overloading . So you know constructors are special class methods which is basically a function which runs at the starting of class always. So as you know how to overload a function then the constructor is also a function so you can overload a constructor as same as function overloading. #include   < iostream > using   namespace   std ; class   calculator {      public :      calculator ( int   a ,   int   b )  //constructor with 2 int type parameter      {          cout << " I AM CONSTRUCTOR  " << a + b << endl ;      }      calculator ( int   a ,   int   b ,   int   c )  //c...

Pointers In C++ | Pointer Explained With Real Life Examples | Pointers In OOPs C++

Pointers In C++ What is pointer in c++ ? If you searched about pointers in c++ on google probably you saw that  In C++, a  pointer  refers to a variable that holds the address of another..... BlahBlahBlah..... But you won't able to understand too much about pointers. So don't worry I will explain this concept very easily by a real life example.   So before understanding about pointers first you have to understand why we need pointers? As you know basically when you create variable then it will occupy some space in your pc. And when you create a another variable with same value or modify that variable with some other value then it will occupy more space in the pc. For example -  #include   < iostream > using   namespace   std ; int   main () {      int   var   =   12 ;  //Suppose This will occupy some space which ID is AB12      int...

Container Class In C++ | Container Class Explained With Real Life Examples

 Container Class In C++ What is a container class? A container class is that class in which you can create an object of any other class and use it like you use it in your main()  function. To understand containers more quickly suppose you have a house and a hotel class. So a house class may have data members like a number of rooms, bedroom_size, bedroom_color. And a hotel class may have the same data member as a house but it may have some more functionality like checkin_time, checkout_time, etc. So in this case you can create a hotel as a class container so you can use house data members inside that also. Here is an example of how you can create a container class in C++ -  #include   < iostream > using   namespace   std ; class   house {      public :      int   no_of_rooms   =   5 ;      int   bedroom_size   =   1200 ; //1200 sq.ft.    ...

Array Of Objects In C++ | Array Of Objects Explained With Real Life Example

 Array Of Objects In C++ What is an array of objects? As you know about the array that it is a set of anything like if there is an array of characters then there will be a set of characters. So the same concepts will be applied to objects - A array of objects will be a set of objects. To understand array of objects more clearly suppose you have a form for a job application and you want to send same job application to 100 people. Then rather then creating 100 job application from scratch you can photocopy the same job application form 100 times.Right? So here how you can create array of object in c++ -  #include   < iostream > using   namespace   std ; class   School {      public :        int   std_id ;      int   std_class ;      float   percentage ;      void   add_details ()      {     ...

Constructor In C++ | Constructor Explained With Real Life Example

 Constructor In C++  What is a constructor? Constructor sounds like it will construct something, right? So yeah it is somewhat related to construction. So I will ask you a question if you want to stay in your house which is not built till now then what will you do? Maybe you will say what are you asking Dhruv. Well, the answer is very simple you will construct your house first. Am I right?. And you can do any change in your house during the construction right. So as in this example, the house will call class and the process of building your house will call the  constructor.  So when you create a class or call an object of any class then first before going into class first your class is calling constructor which will run by default but if you want to modify that constructor then you can do it. Constructor is like a simple function that will run every time when we go inside a class. Here is the official definition of a constructor -  A  constructor  is ...

Hospital Management Application In C++ | Using OOPs C++

 Hospital Management Application In C++ We keep improving This Application: -  #include   < iostream > using   namespace   std ; class   Hospital {      public :      int   pat_id   =   12223 ;      char   pat_name [ 50 ]   ;      char   pat_gen ;      int   age ;      float   height ;      float   weight ;      void   admit ()      {          cout << " Admit A Patient " << endl ;          cout << endl ;          cout << " Enter Patient Name " << endl ;          cin >> pat_name ;      ...

Basics Of OOPS In C++ | Classes & Objects In C++

Image
 Basics Of OOPS In C++  What is Class? Class is like a form in programming. You know in a form you have some fields where every user fills that form. So the one form template can be filled by any user. The class can be assumed as a generalized set of programs whereas many objects can access the features of that class. You can understand class by this image easily:-  Here in this example, you can see a template of a car that can be accessed by many car companies like polo, mini, beetle etc. So here polo, mini, beetle are called objects which is an instance (user) of car class. A class may have data members (attributes) and methods (functions) like the structures you can understand this concept by this image -  So here car class has methods and attributes so the objects of this class should have access to these methods and attributes. Access Specifier In OOPS C++ -  public  - members are accessible from outside the class private  - members cannot be acce...

Basic Of Of C++ Programming || Data Types, cout, cin, If-else, for, while in cpp | Math Table Generator In cpp

 Basic Of Of C++ Programming  Starter Template Of C++ : #include   < iostream >   //HEADER FILE using   namespace   std ; int   main ()  //MAIN FUNCTION WHICH RETURN TYPE IS INTEGER {     //WRITE STUFF HERE      return   0 ; } Data Types in C++: /* Data Type   Meaning                  Size (in Bytes) int         Integer                    2 or 4 float      Floating-point                4 double     Double Floating-point    ...