Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
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(); }
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();
A: Along with the C++ language, you can overload operators and functions. Overloading is the practice of supplying more than one definition for a provided function name in the same
Develop a program to meet the following requirements: 1. Must use at least one function in addition to main (you can use more) 2. Must use selection 3. Must use deference/indire
There are ''''n'''' ants on a ''''n+1'''' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are mov
in this problem you are given a board in which some of the elements are placed as shown in below diagram.each element represent a color.fill the other element in the board,such tha
Define a structure of student class: Write a program to define a structure of student record in C. class student { char name[20]; int roll_no; int marks[2];
program that convert take decimal digit and convert it to binart digit
Friend classes are used when two or more classes are designed to work together and require access to each other's execution in ways that the rest of the world shouldn't be permitte
Ask question #Minimum 100 words acceptedEducational Objectives: After completing this assignment, the student should be able to accomplish the following: Apply generic algorithms i
A: Method of passing arguments to a function that takes parameter of type reference. for instance: void swap( int & x, int &amp; y ) { int temp = x; x =
- Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles. The user should be able to view all DVD titles in his library, add and d
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!
whatsapp: +91-977-207-8620
Phone: +91-977-207-8620
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd