C++ GETTERS & SETTERS explained easy 🔒

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии •

  • @BroCodez
    @BroCodez  2 года назад +11

    #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

  • @naboulsikhalid7763
    @naboulsikhalid7763 7 дней назад +1

    Magic just happened in front of my eyes. Thank you for making it easy and understandable.

  • @hupmitom5509
    @hupmitom5509 Год назад +5

    You make it very easy to understand!

  • @Josuke217
    @Josuke217 7 месяцев назад +3

    Great explanation as always

  • @JackEvans-hf7qt
    @JackEvans-hf7qt Год назад +5

    //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

  • @Kushagra-sj7bn
    @Kushagra-sj7bn 12 дней назад

    thank you bro

  • @Dazza_Doo
    @Dazza_Doo 2 года назад

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

  • @dimitrijbender7285
    @dimitrijbender7285 7 месяцев назад

    Dankeschön 🙏🏼

  • @gamsterilyass2952
    @gamsterilyass2952 6 месяцев назад

    ❤❤❤❤❤

  • @DrunkSober-n2h
    @DrunkSober-n2h 4 месяца назад

    Thx bro

  • @minmyatthukha1160
    @minmyatthukha1160 6 месяцев назад

    Bro i really need Angular Framework bro help

  • @danaildoganov
    @danaildoganov 9 месяцев назад

    #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

  • @Hazar-bt6nf
    @Hazar-bt6nf 2 месяца назад

    Hi, Is that the complete series for c++? Is there any missing concept?

  • @khoanguyen-px5yc
    @khoanguyen-px5yc 7 месяцев назад

    1:07 :v

  • @user-lyf4isnt7daijobu
    @user-lyf4isnt7daijobu 6 месяцев назад

    #include
    class Age
    {
    private: // makes the members read-only and can only be modified using setters
    int age = 0;
    public:
    std::string name;
    Age()
    {
    }
    Age(std::string _name)
    {
    setName(_name);
    }
    Age(std::string _name, int _age)
    {
    setName(_name);
    setAge(_age);
    }
    std::string getName()
    {
    return name;
    }
    void setName(std::string _name) // setter
    {
    this->name = _name;
    }
    int getAge() // getter
    {
    return age;
    }
    void setAge(int _age)
    {
    if (_age < 0)
    {
    std::cout

    • @johanghes6520
      @johanghes6520 3 месяца назад

      infini loop when enter age 50.5

  • @AhmadAbubakar-w5f
    @AhmadAbubakar-w5f Год назад

    #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 Год назад

      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)

    • @Josuke217
      @Josuke217 7 месяцев назад

      string name = "";