Looking for NEET / JEE Coaching? Enquire Now
You must Sign In to post a response.
  • Category: Programming

    Program to explain multiple constructors in a class.


    Want to get program solution for computer programming exam of Diploma? Searching for answers for writing program to explain multiple constructors? Check out this page where our ISC experts have provided program solution.

    Following is a question that was asked in the question paper of Diploma in Computer Technology(Summer 2019)conducted by Maharashtra State Board of Technical Examination, Mumbai for subject Object Oriented Programming(17432)(G Scheme), Semester-IV

    This question is asked for 4 marks.

    Q) Explain multiple constructors in a class with suitable example. [4 Marks]
  • Answers

    1 Answers found.
  • Please include and header files before declaration of class.
    //PROGRAM TO IMPLEMENT MULTIPLE CONSTRUCTOR IN A CLASS.

    #include
    #include
    class example
    {
    private:
    int a,b;
    public:
    example(){} //default constructor
    example(int t)//constructor with one argument
    {
    a=b=t;
    }
    example(int x,int y)//constructor with two argumnts
    {
    a=x;
    b=y;
    }
    example(example &v)//copy consrtuctor
    {
    a=v.a;
    b=v.b;
    }
    void display(void)
    {
    cout<<"value of a is "< }
    };
    void main(void)
    {
    class example obj1,obj2(21),obj3(21,41),obj4=obj3;
    clrscr();
    cout<<"\nDefault Constructor is as follows\n";
    obj1.display();
    cout<<"\nConstructor with one argument is as follows\n";
    obj2.display();
    cout<<"\nConstructor with two arguments is as follows\n";
    obj3.display();
    cout<<"\nCopy Constructor is as follows\n";
    obj4.display();
    getch();
    }


  • Sign In to post your comments