C++ - Programming Language
This course covers the basics of programming in C++. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!

Getters And Setters

Lesson 30
Last Updated : November, 2017


Code

Copyclass Movie{
     private:
          string title;
     public:
          string rating;

          Book(string title, string rating){
               this->title = title;
               this->setRating(rating);
          }

          string getRating(){
               return this->rating;
          }
          void setRating(string rating){
               if(rating == "G" || rating == "PG" || rating == "PG-13" || rating == "R" || rating == "NR" || ){
                    this->rating = rating;
               } else {
                    this->rating = "NR";
               }     
          }
};