Wednesday 12 October 2022

C++ Class, Object, Constructor, Destructor, Data Members and Member Functions | All in One Video

                    In this post, we will see C++ Class, Object, Constructor, Destructor, Data Members and Member Functions | All in One Video 


Program Code: (classexample.cpp)

#include<iostream>

using namespace std;


class Sample

{

    private:

    int a,b;

    

    public:


    Sample()  //default constructor

    {

        a=4;

        b=9;

        cout<<"Inside default constructor"<<endl;

    }


    Sample(int x,int y)  //parameterized constructor

    {

        a=x;

        b=y;

        cout<<"Inside parameterized constructor"<<endl;

    }


    ~Sample()  //destructor

    {

        cout<<"Inside destructor"<<endl;

    }

    

    void getdata()

    {

    cout<<"Enter first number"<<endl;

    cin>>a;

    cout<<"Enter second number"<<endl;

    cin>>b;

    }


    void showdata()

    {

    cout<<"Value of a="<<a<<endl;

    cout<<"Value of b="<<b<<endl;

    }

    


};


int main()

{

Sample s1;

Sample s2(5,6);


s1.getdata();

s1.showdata();


Watch following video:


Watch on YouTube: https://www.youtube.com/watch?v=J8Md8rO0y7g

No comments:

Post a Comment