COPY CONSTRUCTORS
AIM:
- To write the C++ program and to implement the concept of copy constructor
1. Start the program
2. Include suitable header file
3. Declare constructor with empty arguments and another ,object as arguments
4. Initialize the value of a variable by calling a constructor in main function
5. Assign the value of one object to another object
6. Execute the program
7. Print the statement
8. Stop the program
CODING:
#include<iostream.h>
#include<conio.h>
class code
{
int id;
public:
code(){}
code(int a)
{
id=a;
}
code(code&x)
{
id=x.id;
}
void display(void)
{
cout<<id;
}
};
int main()
{
clrscr();
code a(100);
code b(a);
code c=a;
code d;
d=a;
cout<<"\nid of a:"; a.display();
cout<<"\nid of b:"; b.display();
cout<<"\nid of c:"; c.display();
cout<<"\nid of d:"; d.display();
getch();
return 0; }
OUTPUT:
id of A:100
id of B:100
id of C:100
id of D:100
RESULT:
- Thus to write the c++ program and implement the concept of copy constructor was successfully completed.
0 comments:
Post a Comment