The Code Fix

شرح C++

البرمجة كائنية التوجّه

الصنف والكائن

#include <iostream>
#include <string>
using namespace std;

class Car {
public:
    string brand;
    int speed;

    void drive() {
        cout << brand << " بسرعة " << speed << endl;
    }
};

int main() {
    Car myCar;
    myCar.brand = "Toyota";
    myCar.speed = 120;
    myCar.drive();
}

الباني (Constructor)

class Car {
public:
    string brand;
    Car(string b) {   // constructor
        brand = b;
    }
};

Car c("Honda");

التغليف (private/public)

class Account {
private:
    double balance;   // مخفي
public:
    void deposit(double amount) { balance += amount; }
    double getBalance() { return balance; }
};

الوراثة

class Animal {
public:
    void eat() { cout << "يأكل"; }
};

class Dog : public Animal {
public:
    void bark() { cout << "ينبح"; }
};

Dog يرث eat() ويضيف bark().

🎉 أكملت أساسيات C++! أصبحت قادرًا على بناء برامج سريعة وكائنية التوجّه. اختبر نفسك واحصل على شهادتك.