Skip to main content

Posts

Showing posts from June, 2025

C++ Day 15

  C ++ day 15: polymorphism and virtual work 🔹 1. What is polymorphism? Polytestrality = "many forms". In C ++, it is mainly obtained: Ceremony surcharge (pre -covered) Ceremony overriding Virtual work 🔹 2. Function Overroid (Ricap) CPP Copy edit Class base { public: Zero greetings () {cout << "Hello base \ n"; , , Class derivative: Public base { public: Zero greetings () {cout << "Hello derived \ n"; , , 🔹 3. Virtual work Runtime allows polymorphism. Call the correct function through base class pointer/reference. CPP Copy edit Class animal { public: Virtual zero sound () { cout << "Animal sound \ N"; , , Class Dog: Public Animal { public: Zero sound () override { cout << "dog barks \ n"; , , int main() { Animal* a = new dog (); A-> sound (); // Dog bark Remove A; , 🔹 4. Pure virtual work and abstract class CPP Copy edit Class size { public: ...

C++ Day 15

  C ++ day 15: polymorphism and virtual work 🔹 1. What is polymorphism? Polytestrality = "many forms". In C ++, it is mainly obtained: Ceremony surcharge (pre -covered) Ceremony overriding Virtual work 🔹 2. Function Overroid (Ricap) CPP Copy edit Class base { public: Zero greetings () {cout << "Hello base \ n"; , , Class derivative: Public base { public: Zero greetings () {cout << "Hello derived \ n"; , , 🔹 3. Virtual work Runtime allows polymorphism. Call the correct function through base class pointer/reference. CPP Copy edit Class animal { public: Virtual zero sound () { cout << "Animal sound \ N"; , , Class Dog: Public Animal { public: Zero sound () override { cout << "dog barks \ n"; , , int main() { Animal* a = new dog (); A-> sound (); // Dog bark Remove A; , 🔹 4. Pure virtual work and abstract class CPP Copy edit Class size { public: ...

C++ Day 14

  C ++ Day 14: Types of Heritage and Protected Access 🔹 1. Types of heritage in c ++ Type details Single one base → a derivative class Multi -level base → derived1 → derived2 Many are inherited from a derived class 2+ base A base class ingested → Many derivative classes Two or more hybrid combination 📌 Single Heritage (Review) CPP Copy edit Class animal { public: Eat zero () { Cout << "Food ..." << Endl; , , Class Dog: Public Animal { public: Zero bark () { Cout << "Barking ..." << Endl; , , 📌 multilevel heritage CPP Copy edit Class living public: Zero Breath () {Cout << "Breath" << Endl; , , Class Animal: Public Living public: Eat zero () {cout << "eating" << endl; , , Class Dog: Public Animal { public: Zero bark () {cout << "barking" << endl; , , 📌 Many heritage CPP Copy edit Class printer { public: Zero print () {cout <...

C++ Day 13

  C ++ Day 13: Heritage Basics 🔹 1. What is inheritance? The inheritance allows a square (derivative/child) to obtain qualities and methods from another class (base/parent). This helps reusion the code and establish relationships like "IS-A". 🔹 2. Syntax CPP Copy edit Class base { public: Zero Show () { cout << "base class method" << Endl; , , Class derivative: Public base { public: Zero display () { cout << "derived class method" << endl; , , int main() { Derved OBJ; Obj.show (); // Aadhaar Obj.display (); // derived from Return 0; , 🔹 3. Inheritance Access Specifier Aadhaar Member Public Heritage Protected Heritage Private Heritage Publicly protected private Protected protected private Private heritage has not been inherited by not inherited Example: CPP Copy edit A class { public: Int x; reserve: Int y; Personal: Int z; , Class B: Public A { public: Zer...

C++ Day 12

  C ++ Day 12: Dynamic memory and pointers in OOP 🔹 1. Dynamic memory with new and removal New: Dynamically allocates memory Remove: Dealing Memory (important to prevent memory leaks) CPP Copy edit Int* p = new int (5); // Dynamically allocates memory cout << *p << endl; // print 5 Remove P; // Deals Memory 🔹 2. Dynamic arrays CPP Copy edit Int* Arr = new int [5]; // 5 Allocates memory for integer For (int i = 0; i <5; ++ i) { Arr [i] = i * 10; , Remove [] Arrested; // Removes the entire array 🔹 3. Classes with dynamic memory ❗ It matters: When your class makes new uses to allocate memory (eg, dynamic string or array), you have to define: Copy manufacturer Destroyer Assignment operator (rule of three) 🔹 4. Example: square with dynamic memory CPP Copy edit #INCLUDE <iostream> #INCLUDE <CSTRING> using namespace std; Class student { Personal: char name; public: Student (Const char* n) { Name = new four [s...

C++ Day 11

  C ++ Day 11: Constructors, Districts, and this pointer 🔹 1. Types of constructors 📌 a. Default constctor If no argument is passed, it is said automatically. CPP Copy edit Class car { public: car() { Cout << "Default Constory" << Endl is called Endl; , , 📌 b. Parlokik manufacturer The object takes the argument to the members to initiate. CPP Copy edit Class car { public: String brand; Car (String B) { Brand = B; , , 📌 c. Copy manufacturer Creates a new object as a copy of an existing object. CPP Copy edit Class car { public: String brand; Car (string b) {brand = B; , // Copy constctor Car (Constate Car & C) { Brand = C.Brand; , , 🔹 2. Disastrous A destroyer is used to clean up an object. When the object is out of scope, it is called automatically. CPP Copy edit Class car { public: car() { Cout << "The constitution is called" << Endl; , ~ Car ()...

C++ Day 10

  C ++ Day 10: Introduction to Object-Oriented Programming (OOP) 🔹 1. What is Oop? The object-oriented programming (OOP) is a paradigm centered around objects and classes. This helps the model in real -world institutions and improves the code structure and re -purpose. 🔹 2. Major concepts were launched today: Classes and goods Data member and member work Access Specifier: Public, Private Bunny 🔹 3. Define a square CPP Copy edit #INCLUDE <iostream> using namespace std; Class person { public: String name; Int edge; Zero introduction () { Cout << "Hi, I" << Name << "and I" << Age << "year old." << Endl; , , int main() { Person P1; p1.Name = "Alice"; P1.age = 25; p1.introduce (); Return 0; , 🔹 4. Access Specifier Public: accessible from outside the class. Personal: accessible only inside the classroom. CPP Copy edit Class box { Personal: Int length; public:...

C++ Day 9

  C ++ Day 9: Functions Deep Dive 🔹 1. Function overloading Definition: Function overloading allows many functions with the same name but different parameters. CPP Copy edit #INCLUDE <iostream> using namespace std; Zero print (int I) { Cout << "Printing into:" << I << Endl; , Zero print (double d) { Cout << "Printing double:" << d << endl; , Zero print (string s) { cout << "printing string:" << s << endl; , int main() { Print (5); Print (3.14); Print ("hello"); Return 0; , 🔹 2. Default argument Definition: You can provide a default value for function criteria. CPP Copy edit #INCLUDE <iostream> using namespace std; Zero greeting (string name = "guest") { Cout << "Hello," << Name << "!" << Endl; , int main() { Greetings ("Alice"); greet(); // Uses default Return 0; , 🔹 3. ...