Assignment On Constructor
Assignment On Constructor
#include <iostream>
class student {
int rno;
char name[10];
double fee;
public:
student()
void display()
cout << endl << rno << "\t" << name << "\t" << fee;
};
int main()
{
student s; // constructor gets called automatically when
s.display();
return 0;
PARAMETERISED CONSTRUCTOR
// CPP program to illustrate
// parameterized constructors
#include <iostream>
class Point {
private:
int x, y;
public:
// Parameterized Constructor
x = x1;
y = y1;
};
int main()
{
// Constructor called
return 0;
Copy Constructor
// Example: Explicit copy constructor
#include <iostream>
class Sample
int id;
public:
void init(int x)
id=x;
id=t.id;
}
void display()
cout<<endl<<"ID="<<id;
};
int main()
Sample obj1;
obj1.init(10);
obj1.display();
obj2.display();
return 0;