Default Constructors Assignment Help

Assignment Help: >> Union, Nested Classes, Constructors and Destructors - Default Constructors

Default constructors

The default constructor is a particular member function that is invoked through the C++ compiler without any argument for initializing the object class. C++ compiler automatically produces default constructors if it is not defined.

The common form is class user_name

{

private:

-------------

-------------

protected:

-------------

-------------

public:

user_name ( ); //default constructor

-------------

-------------

}

user_name :: user_name ( ) //without any parameters

Example:

// program to elaborate the default constructor

# include<iostream.h>

class student

{

private:

char name[20];

int rollno;

char sex;

float height;

float weight;

public:

};

student( );

void display( );

student :: student( )

{

name[0] = '\0';

rollno = 0; sex = '\0';

height = 0;

weight = 0;

}

void student:: display ( )

{

cout <<"name ="<< name<<endl;

cout <<"rollnumber  ="<< rollnoname<<endl;

cout <<"sex   ="<< sex<<endl;

cout <<"height          ="<< height<<endl;

cout <<"weight         ="<< weight<<endl;

}

void main( )

{

student a;

cout <<"description of default constructor\n";

a.display( );

}

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd