{"id":116,"date":"2023-03-01T06:37:10","date_gmt":"2023-03-01T06:37:10","guid":{"rendered":"https:\/\/alitousen.com\/?page_id=116"},"modified":"2025-03-14T14:36:21","modified_gmt":"2025-03-14T14:36:21","slug":"programming","status":"publish","type":"page","link":"https:\/\/alitousen.com\/?page_id=116","title":{"rendered":"Programming"},"content":{"rendered":"\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Programming is the process of designing, writing, testing, and maintaining computer programs, which are sets of instructions that a computer can execute.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Programs are written using programming languages such as Python, Java, C++, and others. The process of programming involves breaking down a problem into smaller parts, designing an algorithm to solve each part, and then writing code that implements the algorithm.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Programming can be used to create a wide variety of software, including web applications, mobile apps, video games, and desktop applications. It is a valuable skill that is in high demand in today&#8217;s technology-driven world and can be a rewarding career for those who enjoy solving problems and working with computers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-pale-cyan-blue-color has-black-background-color has-text-color has-background\">Object Oriented programming<\/h2>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which can contain data (attributes) and behavior (methods).<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">In OOP, programs are designed by creating classes, which define objects of a particular type. A class is a blueprint or template that defines the attributes and methods of an object. Objects are instances of classes, which means that they have the same attributes and methods as the class they are created from.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">The four main principles of OOP are:<\/p>\n\n\n\n<ul class=\"has-white-color has-black-background-color has-text-color has-background\">\n<li>Encapsulation: The idea of bundling data and methods together into a single unit, and hiding the implementation details from the outside world.<\/li>\n\n\n\n<li>Inheritance: The ability of a subclass to inherit properties and methods from its superclass, allowing for code reuse and modularity.<\/li>\n\n\n\n<li>Polymorphism: The ability of objects to take on multiple forms or behaviors, depending on the context in which they are used.<\/li>\n\n\n\n<li>Abstraction: The idea of focusing on the essential features of an object, while ignoring the details that are not relevant to its use.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">OOP allows for modular, maintainable, and reusable code, which can make software development more efficient and less error-prone. It is used in a wide range of programming languages, including Java, C++, Python, and Ruby.<\/p>\n\n\n\n<h3 class=\"wp-block-heading has-light-green-cyan-color has-black-background-color has-text-color has-background\">Encapsulation<\/h3>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Encapsulation is a fundamental concept in object-oriented programming (OOP) that refers to the practice of hiding the internal details of an object and exposing only what is necessary to interact with it.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">In other words, encapsulation is a mechanism that allows an object to control its own data and behavior by providing a public interface through which other objects can access it. The internal workings of the object are kept private, which prevents other objects from interfering with its state or behavior.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Encapsulation is achieved in OOP by using access modifiers such as public, private, and protected to control the visibility of an object&#8217;s data and methods. The public interface provides a set of methods and properties that other objects can use to interact with the encapsulated object, while the private interface is hidden from external objects.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Encapsulation helps to improve the maintainability, reliability, and security of code by preventing unintended modification of an object&#8217;s state or behavior. It also facilitates modular programming and code reuse by allowing objects to be developed and tested independently of one another.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include &lt;iostream&gt;\nusing namespace std;\n\nclass Circle {\nprivate:\n    double radius;\n\npublic:\n    void setRadius(double r) {\n        if (r &gt; 0) {\n            radius = r;\n        } else {\n            cout &lt;&lt; &quot;Invalid radius value.&quot; &lt;&lt; endl;\n        }\n    }\n\n    double getRadius() {\n        return radius;\n    }\n\n    double getArea() {\n        return 3.14 * radius * radius;\n    }\n};\n\nint main() {\n    Circle myCircle;\n    myCircle.setRadius(5);\n    \n    cout &lt;&lt; &quot;Radius: &quot; &lt;&lt; myCircle.getRadius() &lt;&lt; endl;\n    cout &lt;&lt; &quot;Area: &quot; &lt;&lt; myCircle.getArea() &lt;&lt; endl;\n\n    return 0;\n}\" style=\"color:#f6f6f4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&lt;<\/span><span style=\"color: #E7EE98\">iostream<\/span><span style=\"color: #DEE492\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">using<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">namespace<\/span><span style=\"color: #F6F6F4\"> std;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Circle<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">double<\/span><span style=\"color: #F6F6F4\"> radius;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">setRadius<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">double<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">r<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (r <\/span><span style=\"color: #F286C4\">&gt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            radius <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> r;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        } <\/span><span style=\"color: #F286C4\">else<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Invalid radius value.<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">double<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">getRadius<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> radius;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">double<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">getArea<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">3.14<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> radius <\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> radius;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">main<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    Circle myCircle;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    myCircle.<\/span><span style=\"color: #62E884\">setRadius<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #BF9EEE\">5<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Radius: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> myCircle.<\/span><span style=\"color: #62E884\">getRadius<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Area: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> myCircle.<\/span><span style=\"color: #62E884\">getArea<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-light-green-cyan-color has-black-background-color has-text-color has-background\">Inheritance<\/h3>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Inheritance is a key concept in object-oriented programming (OOP) that allows a new class to be based on an existing class. Inheritance enables the creation of new classes that are built upon existing classes, thereby reusing code and reducing development time.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Inheritance works by allowing a new class (called the &#8220;subclass&#8221; or &#8220;derived class&#8221;) to inherit properties and methods from an existing class (called the &#8220;superclass&#8221; or &#8220;base class&#8221;). The subclass can then extend or modify the properties and methods inherited from the superclass, or add new properties and methods of its own.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">The advantage of inheritance is that it promotes code reuse and modularity by allowing related classes to share code and functionality. This makes it easier to maintain and update the codebase, since changes made to the superclass are automatically inherited by all its subclasses.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Inheritance also supports the concept of polymorphism, which allows objects of different classes to be treated as if they are of the same class. This means that a method defined in the superclass can be called on an object of the subclass, and the subclass can override or extend the behavior of the method as needed.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Overall, inheritance is a powerful tool for creating flexible and reusable code in OOP, and is widely used in many programming languages, including Java, Python, and C++.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#Inheritance\n#include &lt;iostream&gt;\nusing namespace std;\n\n\/\/ Base class\nclass Animal {\npublic:\n    void eat() {\n        cout &lt;&lt; &quot;Animal is eating&quot; &lt;&lt; endl;\n    }\n\n    void sleep() {\n        cout &lt;&lt; &quot;Animal is sleeping&quot; &lt;&lt; endl;\n    }\n};\n\n\/\/ Derived class\nclass Dog : public Animal {\npublic:\n    void bark() {\n        cout &lt;&lt; &quot;Dog is barking&quot; &lt;&lt; endl;\n    }\n};\n\n\/\/ Derived class\nclass Bird : public Animal {\npublic:\n    void fly() {\n        cout &lt;&lt; &quot;Bird is flying&quot; &lt;&lt; endl;\n    }\n};\n\nint main() {\n    Dog dog;\n    dog.eat();\n    dog.sleep();\n    dog.bark();\n\n    Bird bird;\n    bird.eat();\n    bird.sleep();\n    bird.fly();\n\n    return 0;\n}\" style=\"color:#f6f6f4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F6F6F4\">#Inheritance<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&lt;<\/span><span style=\"color: #E7EE98\">iostream<\/span><span style=\"color: #DEE492\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">using<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">namespace<\/span><span style=\"color: #F6F6F4\"> std;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">\/\/ Base class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Animal<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">eat<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Animal is eating<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">sleep<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Animal is sleeping<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">\/\/ Derived class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Dog<\/span><span style=\"color: #F6F6F4\"> : <\/span><span style=\"color: #F286C4\">public<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">Animal<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">bark<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Dog is barking<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">\/\/ Derived class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Bird<\/span><span style=\"color: #F6F6F4\"> : <\/span><span style=\"color: #F286C4\">public<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">Animal<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">fly<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Bird is flying<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">main<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    Dog dog;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    dog.<\/span><span style=\"color: #62E884\">eat<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    dog.<\/span><span style=\"color: #62E884\">sleep<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    dog.<\/span><span style=\"color: #62E884\">bark<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    Bird bird;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    bird.<\/span><span style=\"color: #62E884\">eat<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    bird.<\/span><span style=\"color: #62E884\">sleep<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    bird.<\/span><span style=\"color: #62E884\">fly<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-light-green-cyan-color has-black-background-color has-text-color has-background\">Polymorphism<\/h3>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Polymorphism is a fundamental concept in object-oriented programming (OOP) that refers to the ability of objects to take on many forms. It allows objects of different classes to be treated as if they are of the same class, making code more flexible, reusable, and easier to maintain.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Polymorphism is enabled by inheritance and method overriding, which allow a subclass to inherit methods from a superclass and override them with its own implementation. This means that objects of the subclass can be treated as objects of the superclass, and can be used interchangeably in code that uses the superclass.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">For example, consider a program that has a superclass called &#8220;Shape&#8221; and two subclasses called &#8220;Circle&#8221; and &#8220;Rectangle&#8221;. Each of these classes has a method called &#8220;getArea()&#8221;, which calculates the area of the shape. The Circle and Rectangle classes override the getArea() method with their own implementation to calculate the area of a circle or rectangle.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Now, if we have a variable of type Shape, we can assign it to an object of either Circle or Rectangle, since both of these classes are subclasses of Shape. Then, we can call the getArea() method on the Shape variable, and the correct implementation of the method will be called based on the actual type of the object.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">This allows us to write code that is more flexible and adaptable, since it can work with a variety of different objects without needing to know their specific types. Polymorphism is a powerful tool for creating extensible and reusable code in OOP, and is widely used in many programming languages, including Java, Python, and C++.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include &lt;iostream&gt;\nusing namespace std;\n\nclass Shape {\npublic:\n    \/\/ Virtual function\n    virtual void draw() {\n        cout &lt;&lt; &quot;Drawing Shape&quot; &lt;&lt; endl;\n    }\n};\n\nclass Circle : public Shape {\npublic:\n    \/\/ Override draw function for Circle\n    void draw() override {\n        cout &lt;&lt; &quot;Drawing Circle&quot; &lt;&lt; endl;\n    }\n};\n\nclass Square : public Shape {\npublic:\n    \/\/ Override draw function for Square\n    void draw() override {\n        cout &lt;&lt; &quot;Drawing Square&quot; &lt;&lt; endl;\n    }\n};\n\nint main() {\n    Shape* shape1 = new Circle();\n    Shape* shape2 = new Square();\n    \n    shape1-&gt;draw(); \/\/ Calls draw() from Circle class\n    shape2-&gt;draw(); \/\/ Calls draw() from Square class\n    \n    delete shape1;\n    delete shape2;\n    \n    return 0;\n}\" style=\"color:#f6f6f4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&lt;<\/span><span style=\"color: #E7EE98\">iostream<\/span><span style=\"color: #DEE492\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">using<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">namespace<\/span><span style=\"color: #F6F6F4\"> std;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Shape<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">    \/\/ Virtual function<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">virtual<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">draw<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Drawing Shape<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Circle<\/span><span style=\"color: #F6F6F4\"> : <\/span><span style=\"color: #F286C4\">public<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">Shape<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">    \/\/ Override draw function for Circle<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">draw<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">override<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Drawing Circle<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">Square<\/span><span style=\"color: #F6F6F4\"> : <\/span><span style=\"color: #F286C4\">public<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">Shape<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">    \/\/ Override draw function for Square<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">draw<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">override<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Drawing Square<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">main<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    Shape<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> shape1 <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4; font-weight: bold\">new<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">Circle<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    Shape<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> shape2 <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4; font-weight: bold\">new<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">Square<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    shape1<\/span><span style=\"color: #F286C4\">-&gt;<\/span><span style=\"color: #62E884\">draw<\/span><span style=\"color: #F6F6F4\">();<\/span><span style=\"color: #7B7F8B\"> \/\/ Calls draw() from Circle class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    shape2<\/span><span style=\"color: #F286C4\">-&gt;<\/span><span style=\"color: #62E884\">draw<\/span><span style=\"color: #F6F6F4\">();<\/span><span style=\"color: #7B7F8B\"> \/\/ Calls draw() from Square class<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">delete<\/span><span style=\"color: #F6F6F4\"> shape1;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">delete<\/span><span style=\"color: #F6F6F4\"> shape2;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading has-light-green-cyan-color has-black-background-color has-text-color has-background\">Abstraction<\/h3>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Abstraction is a fundamental concept in object-oriented programming (OOP) that refers to the process of representing complex real-world entities as simplified models or representations in code. Abstraction allows developers to focus on the essential features of an object or system, while hiding irrelevant details.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">In OOP, abstraction is achieved through the use of abstract classes, interfaces, and methods. An abstract class is a class that cannot be instantiated, but serves as a template or blueprint for other classes. It can define abstract methods, which are methods that have no implementation but must be implemented by any concrete subclass of the abstract class.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">An interface is similar to an abstract class, but it contains only abstract methods and cannot define any implementation. It is used to define a contract that a class must adhere to in order to be considered a particular type.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Abstraction helps to simplify complex systems and make them more manageable by providing a clear separation between the essential features of an object and the implementation details. It also allows for greater flexibility and modularity in code, since changes can be made to the implementation of an object without affecting the external interface.<\/p>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background\">Overall, abstraction is a powerful tool for creating modular, flexible, and maintainable code in OOP, and is a key component of many programming languages, including Java, C++, and Python.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include &lt;iostream&gt;\nusing namespace std;\n\nclass BankAccount {\nprivate:\n    int accountNumber;\n    float balance;\n\npublic:\n    BankAccount(int accNo, float bal) {\n        accountNumber = accNo;\n        balance = bal;\n    }\n\n    void deposit(float amount) {\n        balance += amount;\n    }\n\n    void withdraw(float amount) {\n        if (amount &gt; balance) {\n            cout &lt;&lt; &quot;Insufficient balance.&quot; &lt;&lt; endl;\n        }\n        else {\n            balance -= amount;\n        }\n    }\n\n    float getBalance() const {\n        return balance;\n    }\n};\n\nint main() {\n    BankAccount account(123456, 1000.00);\n\n    account.deposit(500.00);\n    cout &lt;&lt; &quot;Balance after deposit: &quot; &lt;&lt; account.getBalance() &lt;&lt; endl;\n\n    account.withdraw(1500.00);\n    cout &lt;&lt; &quot;Balance after withdrawal: &quot; &lt;&lt; account.getBalance() &lt;&lt; endl;\n\n    return 0;\n}\" style=\"color:#f6f6f4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&lt;<\/span><span style=\"color: #E7EE98\">iostream<\/span><span style=\"color: #DEE492\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">using<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">namespace<\/span><span style=\"color: #F6F6F4\"> std;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">BankAccount<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> accountNumber;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">float<\/span><span style=\"color: #F6F6F4\"> balance;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">BankAccount<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">accNo<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #F286C4\">float<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">bal<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        accountNumber <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> accNo;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        balance <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> bal;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">deposit<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">float<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">amount<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        balance <\/span><span style=\"color: #F286C4\">+=<\/span><span style=\"color: #F6F6F4\"> amount;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">withdraw<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">float<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">amount<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (amount <\/span><span style=\"color: #F286C4\">&gt;<\/span><span style=\"color: #F6F6F4\"> balance) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Insufficient balance.<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">else<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            balance <\/span><span style=\"color: #F286C4\">-=<\/span><span style=\"color: #F6F6F4\"> amount;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">float<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">getBalance<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">const<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> balance;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">main<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    BankAccount <\/span><span style=\"color: #62E884\">account<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #BF9EEE\">123456<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #BF9EEE\">1000.00<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    account.<\/span><span style=\"color: #62E884\">deposit<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #BF9EEE\">500.00<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Balance after deposit: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> account.<\/span><span style=\"color: #62E884\">getBalance<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    account.<\/span><span style=\"color: #62E884\">withdraw<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #BF9EEE\">1500.00<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Balance after withdrawal: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> account.<\/span><span style=\"color: #62E884\">getBalance<\/span><span style=\"color: #F6F6F4\">() <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Programming is the process of designing, writing, testing, and maintaining computer programs, which are sets of instructions that a computer can execute. Programs are written using programming languages such as Python, Java, C++, and others. The process of programming involves breaking down a problem into smaller parts, designing an algorithm to solve each part, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/alitousen.com\/index.php?rest_route=\/wp\/v2\/pages\/116"}],"collection":[{"href":"https:\/\/alitousen.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/alitousen.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/alitousen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alitousen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=116"}],"version-history":[{"count":6,"href":"https:\/\/alitousen.com\/index.php?rest_route=\/wp\/v2\/pages\/116\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/alitousen.com\/index.php?rest_route=\/wp\/v2\/pages\/116\/revisions\/295"}],"wp:attachment":[{"href":"https:\/\/alitousen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}