get set oops

 #include <iostream>

using namespace std;


class student{

    public:

    int roll_no;

    private :

    int age;

    public :

    void display(){

        cout<<age<<" "<<roll_no<<endl;

    }

    int getage(){

        return age;

    }

    void setage(int a, int password){

        if (password!=123){

            return;

        }

        age =a;

    }

    

};


int main() {

    student s1,s2,s3;

    student* s4= new student;

    s1.roll_no=12;

    s1.setage(-2,123);

    s1.setage(23,124);

    s4->setage(25,123);

    s4->roll_no=101;

    

    s1.getage();

    

    cout<<s1.roll_no<<endl;

    s1.display();

    s4->display();


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings