class employee
{
private:
//Employee details;
public:
employee(); //Constructor
};
class employee
{
private:
//Employee Details
public:
employee(); //Constructor declared
};
employee::employee() //Constructor definition outside class definition
{
//Statements;
}
#include<iostream>
using namespace std;
class Rectangle
{
public:
float l,b;
Rectangle() //Constructor created
{
l=3;
b=6;
}
};
int main()
{
Rectangle rect;
cout <<"Area of Rectangle : "<<rect.l*rect.b;
}
#include<iostream>
using namespace std;
class Rectangle
{
public: int l=3,b=3;
};
int main()
{
Rectangle rect;
cout<<"Area of Rectangle : "<<rect.l*rect.b;
}
#include<iostream>
using namespace std;
class Square
{
public:
float side;
Square(float s) //Parameterized Constructor
{
side = s;
}
};
int main()
{
Square sq(5);
cout <<"Area of Square : "<<sq.side*sq.side<<endl;
}
#include<iostream>
using namespace std;
class CopyConst
{
private:
int a, b;
public:
CopyConst(int a1, int b1)
{
a = a1;
b = b1;
}
CopyConst(const CopyConst &obj2) // Copy constructor
{
a = obj2.a;
b = obj2.b;
}
int getA()
{
return a;
}
int getB()
{
return b;
}
};
int main()
{
CopyConst obj1(10, 20); // Normal constructor is called
cout<<"Normal Constructor"<<endl;
cout << "Value of a and b" <<"\n a is : "<< obj1.getA() <<"\n b is : "<< obj1.getB()<<endl; //Access values assigned by constructors
cout<<"\n Copy Constructor";
CopyConst obj2 = obj1; // Copy constructor is called
cout << "\n Value of a and b" <<"\n a is : "<< obj2.getA() <<"\n b is : "<< obj2.getB();
return 0;
}