Dynamic initialization of objects and dynamic constructor, C/C++ Programming

Dynamic Initialization of objects:

It is initializing the objects by passing the valued to the constructor from the user input or

other means.   Through cin operator a value can be stored in a variable and passed through a constructor this form of initializing an object is known dynamic initialization.

Dynamic Constructor:

The memory allocation for a constructor can be managed using new operator called new,

similarly the memory can be free with another operator called deleter.

 

class dynmem

{ char *name;

int length;

public:

dynmem(void)

{length =0;

name = new char[length+1];

}

dynmem(char *s)

{length = strlen(s);

name = new char[length+1];//for null terminator

strcpy(name,s);

}

void display(void)

{cout<

}

void join(dynmem &a, dynmem &b);

};

void dynmem::join(dynmem &a, dynmem &b)

{length = a.length+b.length;

delete name;

name = new char[length+1]; strcpy(name,a.name); strcat(name,b.name);

};

void main()

{

clrscr();

char *first="Electronic ";

dynmem name1(first);

dynmem name2("and Communication ");

dynmem name3("Engineering"); dynmem s1,s2; s1.join(name1,name2); s2.join(s1,name3); name1.display();

name2.display(); name3.display(); s1.display(); s2.display();

}

Posted Date: 9/20/2012 8:12:31 AM | Location : United States







Related Discussions:- Dynamic initialization of objects and dynamic constructor, Assignment Help, Ask Question on Dynamic initialization of objects and dynamic constructor, Get Answer, Expert's Help, Dynamic initialization of objects and dynamic constructor Discussions

Write discussion on Dynamic initialization of objects and dynamic constructor
Your posts are moderated
Related Questions
Program for calculate average of total marks: #include using namespace std; void print(int marks_arr[],int cnt) { int ind[cnt]; int i=0; int j=0; int k=0;

Develop Online Slot Video Game for Facebook Prepare an online slot video game for a Facebook promotion in order to draw new visits and Increase the number of "likes" of the Face

C Program for FUNCTION OF COUNT THE CHARACTERS IN EACH WORD void count(char c[]); void main() {           char a[50];           int i=0;           clrscr();

Classify computer system according to capacity. How they are different from computers according to the classification of technology. Provide comparative study also.

Project Description: Currently seeking someone who can create me a software application (google chrome crx file_ that will auto add all shoe sizes to cart directly and if not av

Hello. I need a solution for this assignment. It is for C++ Language: Create a BusinessPartner class that contains a first name, company name, and a telephone number. Create a Con

Functions Overloading This a capability in which a C++ program can have several functions performing similar tasks on different data types. When an overloaded function is calle

Hiding overloaded functions We cannot overload a base class function by redefining it in a derived class with a dissimilar argument list. Consider examples to see if similar fu

Write a function that has an int parameter n, makes an integer mask having the bit 1 at the nth place from the rightmost bit, and returns the mask. For example, when n = 5 is passe

program coding for the conversion of string to a palindrome