Skip to main content

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 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: Zero Show () { cout << x; // Ok cout << y; // Ok // Cout << Z; // Mistake , , 🔹 4. Inheritance constctor and distribution order The base class construction is called before the derivative class. The destructive is called in the reverse order. CPP Copy edit A class { public: A () {cout << "base constitution \ n"; , ~ A () {cout << "base disastrous \ n"; , , Class B: Public A { public: B () {cout << "derivative constructor \ n"; , ~ B () {cout << "derivative disastrous \ n"; , , 🔹 5. Single versus multi -layered heritage ✔ single heritage CPP Copy edit A class {}; Class B: Public A {}; ✔ multi -level heritage CPP Copy edit A class {}; Class B: Public A {}; Class C: Public B {}; // C inherited A and B 🔹 6. Function overrising The derivative class can override the methods of the base class with the same signature. CPP Copy

Comments

Popular posts from this blog

C++ Day 4

 Great progress! Let’s jump into Day 4 of C++ learning. Today, you'll explore arrays , strings , and basic loops with data structures . C++ Day 4: Arrays and Strings 🔹 1. Arrays An array is a collection of elements of the same data type , stored in contiguous memory locations. ✅ Declaration: int numbers[5]; // uninitialized int scores[5] = {10, 20, 30, 40, 50}; // initialized ✅ Accessing Elements: std::cout << scores[2]; // Output: 30 ✅ Looping Through an Array: for (int i = 0; i < 5; i++) { std::cout << scores[i] << " "; } 🔹 2. Multidimensional Arrays ✅ Example: 2D Array (Matrix) int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} }; ✅ Accessing: std::cout << matrix[1][2]; // Output: 6 🔹 3. Strings in C++ C++ offers two ways to handle strings: ✅ C-style strings (char arrays) char name[] = "Alice"; std::cout << name; ✅ C++ string class (recommended) #include <string> std::string nam...

C++ Day 8

  Great! On ** day 8 ** of a specific C ++ course, you will usually go into one of these main subjects: , ## ✅ ** string in C ++ ** Strings are sequence of characters. C ++ provides two main methods of working with them: 1. ** C-style strings ** (character arrays) 2. ** c ++ 'string' class ** (from standard library) We will focus on both. , ### 🔹 1. ** C-style strings (character arrays) ** `` `CPP #INCLUDE <iostream> #INCLUDE <CSTRING> using namespace std; int main() { Four names [20]; Cout << "Enter your name:"; Cin >> Name; Cout << "Hello," << Name << "!" << Endl; Return 0; , , #### Useful C-Style String Functions' <cstring> `: * `Strlen () - String length * `Strcpy ()` - Copy Strings * 'Strcat () ` - Constenate * 'Strcmp () ` - Compare `` `CPP Char Str1 [] = "Hello"; char str2 [] = "world"; Cout << Strcat (Str1, Str2); // Hello Worl...

C++ Day1

Theoretically part will begin day one of our C++ course.   The fundamental concepts are: Day 1: Basics of C++: What is C++? A broad, compiled, high-performance programming language is C++.   Essentially C with object-oriented features, it is a superset. It was designed by Bjarne Stroustrup early in the 1980s. It assists procedural, object-oriented, and generic programming. Embedded firmware, driver creation, game development, system/software development, client-server applications, and embedded firmware are among C++'s most important uses. Basics C++ Program Structure: # include int main() { // Starting point of the main function std::cout < ; Return 0; }} Explanations: Add &lt;iostream; this covers the library for input and output. int main() { .   .   .   }; the primary function—every execution begins here. std::cout displays output. Return 0: The software ran without mistake. Concerning the Basics: Variable and Data Type Variables house values. Usual k...