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

Assignment Help:

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();

}


Related Discussions:- Dynamic initialization of objects and dynamic constructor

Minimum shelfs, Write a program that finds the minimum total number of shel...

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process

C program to display a rectangle, Aim: To implement a program to display a...

Aim: To implement a program to display a rectangle, circle and triangle. Code:                       class shape {             public:                         vir

Explain object-oriented programming, Explain Object-oriented programming ...

Explain Object-oriented programming Object-oriented programming (OOP) attempts to meet these requirements, providing methods for managing enormous complexity, achieving reuse o

Write a program to compute the equation, Write a program to compute the fol...

Write a program to compute the following equation for values of time.           y = 2x+3   The values of time are stored in the file program.dat and the solution should be display

Define the object-oriented terms, Question : (a) Define the following O...

Question : (a) Define the following Object-Oriented terms: (i) Encapsulation (ii) Inheritance (iii) Abstraction (iv) Polymorphism. (b) What are objects in Lingo progra

I need script for auto seating poker, Project Description: Not just like...

Project Description: Not just like that though. I want a similar program that can scan through poker lobbys (pokerstars, full tilt, ongame and ipoker) and seat me to the left of

Write Your Message!

Captcha
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