C++ Day 39 STL Containers (Deep Understanding & Real Usage) Till now, you already know arrays, vectors, loops, and STL algorithms. Today, we go one step deeper and understand STL containers , which are the backbone of modern C++ programming. In real projects and competitive coding, choice of container matters a lot. 1. What are STL Containers? STL containers are data structures provided by C++ to store data efficiently. They handle: memory management resizing element access performance optimization You focus on logic , not memory handling. 2. Categories of STL Containers STL containers are mainly divided into: Sequence Containers Associative Containers Unordered Containers Container Adapters 3. Sequence Containers These store data in sequence . 3.1 Vector Most used container in C++. vector< int > v; Key Features: Dynamic size Contiguous memory Fast random access Slower insertion in middle Example: v. push_...
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:
Zero Setlength (Int L) {
Length = L;
,
Int getlength () {
Return length;
,
,
🔹 5. Constructors
The constructor is a special function that automatically runs on the construction of an object.
CPP
Copy
edit
Class car {
public:
String brand;
// Constractor
Car (String B) {
Brand = B;
,
Zero display () {
cout << "brand:" << brand << endl;
,
,
int main() {
Car Car 1 ("Toyota");
Car1.display ();
Return 0;
,
🔹 6. This indicator (introduction)
This indicator refers to the current object inside a square.a
CPP
Copy
edit
Class student {
public:
String name;
Student (string name) {
This-> name = name; // Local versus member decomposes variables
,
,
🧠 practice practice
Create a class book with the title, writer and value as members. Add a method to display the details.
Create a class RE
Comments
Post a Comment