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
to find prime numbers upto any number say "n" entered by user

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

Precedence and Order of evaluation The languages follow a standard precedence for basic operators. Precedence rules help in deleting ambiguity of the order of operations perfor

How to insert values in array - c++ program: Write a program to insert values in array void main() { int a[2][3][2]={                                 {

d) a "static destructor" is a static member function of the class which accepts one argument - a pointer to the object of that class to be cracked. It is probably utilized along wi

Define the Stream Oriented Data Files? There are two dissimilar types of data files called stream-oriented (or standard) data files and system-oriented (or low-level) data file

I need whatsapp software in my website Project Description: i need whatsapp software in my website same this whatsapp if anyone can make to me this in my website Skills


Write a program in C that you will name "divide.exe", to divide one 32-bit twos-complement binary number by another, giving the quotient and the remainder, using the subtract-shift

Ask4. Write a query to display the columns listed below. The query should list each customer in which the video rental is overdue. The Days_Overdue column should calculate the numb