LAB Practical II

i) Write a c++ program to show static member function and static member data.
ii) Write a c++ program to show constructor, destructor, inheritance and dynamic memory allocation in same program.

Comments

  1. Aim:- To write a program to show static member function and static member data.
    Program:-
    #include
    using namespace std;
    class value
    {
    public:
    static int a;
    public:
    static void fun()
    {
    cout<<"value of a"<<a<<endl;
    }
    };
    int value::a=25;
    int main()
    {
    value obj;
    obj.fun();
    return 0;
    }
    Errors:-no errors found.
    Output:-
    a=25.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. AIM : TO create a program to show constructor, destructor, inheritance and dynamic memory location in same program.
    PROCEDURE :
    step 1 : Start the program.
    step 2 : Declear the base class name as b and derived class name as d includind constructon, destructor, inheritance and dynamic memory location.
    Step 3 : Base class is created.
    Step 4 : Derived class is created.
    Step 5: The constructor and destructor is used inside the base class and derived.
    Step 6: The function b() to display the base class.
    Step 7: The function d() to display the derived class.
    Step 8: Stop the program.
    PROGRAM :
    #include
    using namespace std;
    class b

    {
    public:
    b()
    {
    cout << "base class constructor" <<endl;

    }
    ~b()
    {
    cout <<"base class destructor" <<endl;
    }
    };
    class d:public b
    {
    public:
    d()
    {
    cout << "derived class constructor" <<endl;
    }
    ~d()
    {
    cout <<"derived class destructor" <<endl;
    }
    };
    int main()
    {
    d obj;
    }
    OUTPUT :
    base class constructor
    derived class constructor
    derived class destructor
    base calss destructor
    ERROR : 0
    RESULTS : I have successfully done my program.

    ReplyDelete
  5. AIM : To create a program using data member and static member function.
    PROCEDURE :
    step 1 : Start the program.
    step 2 : Declear the class name as stat with data member and member functions.
    Step 3: The constructor stat() which is used to increment the value of count as 1 to assign the variable code.
    Step 4: The function showcount() to display the count value.
    Step 5: The function showcode() to display the code value.
    Step 6: Stop the program.
    PROGRAM :
    #include
    using namespace std;
    class Stat
    {
    int code;
    static int count;
    public:
    stat()
    {
    code = ++count;
    }
    void showcode()
    {

    cout <<"\n\tobject number is :" <<code;

    }
    static void showcount()
    {
    cout <<"\n\tcount objects :" <<cout;
    }
    };
    int stat::count;
    void main()
    {
    stat obj1, obj2;
    obj1.showcount();
    obj1.showcode();
    obj2.showcount();
    obj2.showcode();
    getch();

    }

    OUTPUT :
    Count Objects : 2
    Object Number : 1
    Count Objects : 2
    Object Number : 2

    ERROR : 0
    RESULTS : I have successfully done my program.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. AIM: To create a program using statics data member and statics member function.
      PROCEDURE: I have done my program by using class name as statics demo and also using statics member function and statics data member.
      PROGRAM:
      #include
      using namespace std;
      class staticDemo
      {
      private:
      int static static_var;
      public:
      static void printmsg()
      {
      cout<<"welcome to statics member function"<<endl;
      cout<<"printing global variable:"<<static_var<<endl;
      }
      };
      int staticDemo::static_var=10;
      int main()
      {
      staticDemo::printmsg();
      }
      OUTPUT:
      Welcome to statics member function.
      printing global variable.
      ERROR: 0
      RESULT: I have done my program successfully.

      Delete
  9. AIM: To create a program to show construstor,destructor ,inheritance and dynamics memory allocation.
    PROCEDURE: I have create a class name as parent and derived class as child including constructor,destructor,inheritance and dynammics memory allocation.Parent class and Child class is created .The constructor and destructor is used inside the parent class and child class .
    PROGRAM:
    #include
    using namespace std;
    class parent
    {
    public:
    parent()
    {
    cout<<"Inside base class constructor"<<endl;
    }
    ~parent()
    {
    cout<<"Inside base class destructor"<<endl;
    }
    };
    class child:public parent
    {
    public:
    child()
    {
    cout<<"Inside child class constructor"<<endl;
    }
    ~child()
    {
    cout<<"Inside child class destructor"<<endl;
    }
    };
    int main()
    {
    cout<<"welcoming!!!\n"<<"going to create object dynamically..."<<endl;
    child*obj=new child;
    cout<<"deleting object..."<<endl;
    delete obj;
    return 0;
    }
    OUTPUT:
    Creating object....
    Inside base class constructor
    Inside child class constructor
    Deleting object...
    Inside child class destructor
    Inside base class constructor
    ERROR:0
    RESULT: I have done my program successfully

    ReplyDelete
  10. AIM:
    to create a c++ program to show static member function and static member data.
    PROCEDURE:
    I have made this program using static data member and static member function.
    PROGRAM:
    #include
    using namespace std;
    class umbrella
    {
    private:
    static float x;
    static float y;
    public:
    static void print()
    {
    cout<<"value of x is "<<x<<endl;
    cout<<"value of y is "<<y<<endl;
    }

    };
    float umbrella::x=10;
    float umbrella::y=20;

    int main()
    {
    umbrella u;
    cout<<"using static data member "<<endl;
    u.print();
    cout<<"using static member function "<<endl;
    umbrella::print();
    return 0;
    }
    OUTPUT:
    using static data member
    value ofx is 10
    value of y is 20
    using static member function
    value ofx is 10
    value of y is 20
    ERROR :0
    RESULT:
    I have done this program correctly.

    ReplyDelete
  11. AIM:
    To create a program using inhritance,constructor,destructor and dynamic memory allocation.
    PROCEDURE:
    By using constructor and destructor i made this program,having class name memory and also used th inheritanceit also shows the concept of dynamic memory allocation.
    PROGRAM:
    #include
    using namespace std;
    class memory
    {
    public:
    memory()
    {
    cout<<"using constructor here"<<endl;

    }
    ~memory()
    {
    cout<<"using destructor "<<endl;
    }
    };
    class remember:public memory
    {
    public:
    void memory()
    {
    cout<<"this is child class"<<endl;
    }
    };
    int main()
    {
    remember r;
    r.memory();
    memory*m=new memory[4];
    delete[]m;
    return 0;

    }

    OUTPUT:
    using constructor here
    this is child class
    using constructor here
    using constructor here
    using destructor
    using destructor
    using destructor
    ERROR:
    0
    RESULT:
    I have done this program correctly

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  12. Aim: To write a program to show static member function and static member data.
    Procedure: I have done this program by using static member function and static member data.
    Program: #include
    using namespace std;
    class Box
    {
    private:
    static int X;
    static int Y;
    public:
    static void print()
    {
    cout<<"value of X: "<<X<<endl;
    cout<<"Value of Y: "<<Y<<endl;
    }
    };
    int Box::X=100;
    int Box::Y=200;

    int main()
    {
    Box b;
    b.print();
    return 0;
    }
    Output:
    value of X: 100
    Value of Y: 200

    Error: No error found.

    Result: This program execute successfully.

    https://drive.google.com/open?id=102t0goOdbBmb0PUwttUvHRfXqoD5gjiA

    ReplyDelete
  13. Aim: To write a program to show constructor, destructor, inheritance and dynamic memory allocation in same program.
    Procedure: In this program the base class is created where variables, constructor and destructor are declared. Then in a derived class, a member function through which we are adding the variablesof base class(showing inheritance). Now in main class, an object is created and a function is called through it. For dynamic allocation of memory we implemented the keyword "new" which is used to allocate the memory at runtime.
    Program:
    #include
    using namespace std;
    class Base
    {
    public:
    int a;
    int b;
    Base()
    {
    a=10;
    b=20;
    }

    ~Base()
    {
    cout<<"object delete!!"<<endl;
    }
    };
    class operation:public Base
    {
    public:
    add()
    {
    cout<<"adding to variable of base class"<<endl;
    cout<<"+"<<b<<"="<<a<<endl;
    }
    };
    int main()
    {
    operation o;
    int *var= NULL;
    var=new int;
    *var=35;
    cout<<"value of var: "<<var<<endl;
    o.add();
    return 0;
    }
    Output:
    value of var: 0x1d1840
    adding to variable of base class
    +20=10
    object delete!!
    Error: no error found.
    Result: This program execute successfully.

    https://drive.google.com/open?id=1SB9IwfO-zIoYU1_UylNyLGxjewN_ScPV

    ReplyDelete
  14. AIM: To create a c++ program to show static member function and static member data.
    PROCEDURE: I have made this program using static data member and static member function.
    PROGRAM:
    #include
    using namespace std;
    class demo
    {
    private:
    static int x;
    static int y;
    public:
    static void print()
    {
    cout<<"value of x:"<<x<<endl;
    cout<<"value of y:"<<y<<endl;
    }
    };
    int demo::x=10;
    int demo::y=20;
    int main()
    {
    demo D;
    cout<<"printing through class base:"<<endl;
    demo::print();
    return 0;
    }
    OUTPUT: Printing through class base:
    value of x:10
    value of y:20
    ERROE: no error
    RESULT: I have done my program successfully

    ReplyDelete
  15. AIM: To create a program to show constructor, destructor, inheritance and dynamics memory allocation.
    PROCEDURE: I have create a class name as monthly and derive class weekly including constructor,destructor, inheritance and dynamics memory allocation monthly class and weekly class is created.The constructur annd destructor is used inside the monthly class and weekly class.
    PROGRAM:#include
    using namespace std;
    class monthly
    {
    public:
    monthly()
    {
    cout<<"base class constructor"<<endl;
    }
    ~monthly()
    {
    cout<<"base class destructor"<<endl;
    }
    };
    class weekly:public monthly
    {
    public:
    weekly()
    {
    cout<<"weekly class constructor"<<endl;
    }
    ~ weekly()
    {
    cout<<"weekly class destructor"<<endl;
    }
    };
    int main()
    {
    weekly obj;
    }
    OUTPUT: base class constructor
    weekly class constructor
    weekly class destructor
    base class destructor
    ERROR:0
    RESULT: I have successfully done my program.

    ReplyDelete

Post a Comment

Popular posts from this blog

INTRODUCTION OF HADOOP & SPARK

B.TECH DIP- System Programming