C++ GETTERS & SETTERS explained easy 🔒

แชร์
ฝัง

ความคิดเห็น • 13

  • @BroCodez
    @BroCodez  2 ปีที่แล้ว +6

    #include
    class Stove{
    private:
    int temperature = 0;
    public:
    int getTemperature(){
    return temperature;
    }
    void setTemperature(int temperature){
    if(temperature < 0){
    this->temperature = 0;
    }
    else if(temperature >= 10){
    this->temperature = 10;
    }
    else{
    this->temperature = temperature;
    }
    }
    };
    int main() {
    Stove stove;
    stove.setTemperature(5);
    std::cout

  • @hupmitom5509
    @hupmitom5509 11 หลายเดือนก่อน +2

    You make it very easy to understand!

  • @Janak217
    @Janak217 หลายเดือนก่อน +1

    Great explanation as always

  • @Dazza_Doo
    @Dazza_Doo ปีที่แล้ว

    Class Methods Get and Sets
    Ctor is setting values in the Class methods
    vs
    internal int Age (get; set init);

  • @JackEvans-hf7qt
    @JackEvans-hf7qt 11 หลายเดือนก่อน

    //Volume adjuster program using getters & setters in c++
    //Getters and setters allow you to enforce certain rules or conditions on the data being accessed or modified.
    # include
    using namespace std;
    class sony
    {
    private:
    int volume;
    public:
    sony(int avolume)
    {
    setVolume(avolume);
    }
    int getVolume()
    {
    return volume;
    }
    void setVolume(int avolume)
    {
    if(avolume>50)
    {
    volume=50;
    }
    else if(avolume

  • @dimitrijbender7285
    @dimitrijbender7285 หลายเดือนก่อน

    Dankeschön 🙏🏼

  • @minmyatthukha1160
    @minmyatthukha1160 วันที่ผ่านมา

    Bro i really need Angular Framework bro help

  • @danaildoganov
    @danaildoganov 2 หลายเดือนก่อน

    #include
    class Pan{
    private:
    int temperature = 19;
    public:
    Pan(int temperature){
    setTemperature(temperature);
    }
    int getTemperature(){
    return temperature;
    }
    void setTemperature(int temperature){
    if(temperature >= 10){
    this->temperature = 10;
    }
    else if(temperature temperature = 0;
    }
    else{
    this->temperature = temperature;
    }
    }
    };
    int main(){
    Pan pan1(1 0);
    //pan1.setTemperature(97);
    std::cout

  • @khoanguyen-px5yc
    @khoanguyen-px5yc หลายเดือนก่อน

    1:07 :v

  • @user-jl5rg2xz3z
    @user-jl5rg2xz3z 8 หลายเดือนก่อน

    #include
    class human{
    private:
    std::string name = "null";
    int age =0;
    public:
    void setName(std::string name){
    this->name=name;
    }
    void setAge(int age){
    this->age=age;
    }
    std::string getName(){
    return name;
    }
    int getAge(){
    return age;
    }
    };
    int main()
    {
    human h1;
    h1.setName("sam");
    h1.setAge(20);
    std::cout

    • @PSIwolf39
      @PSIwolf39 7 หลายเดือนก่อน

      This code does work perfectly fine but I just wanted to let you know that that isn't how you set a NULL value.
      std::string name = "null"; // This sets the name as text string that has the letters of the word "null", not a NULL value.
      std::string name = NULL; // This is how you're supposed to set a NULL value.
      // (and yes, NULL does have to be in all caps for it to work)

    • @Janak217
      @Janak217 หลายเดือนก่อน

      string name = "";