Solution:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>
class Machine
{
private:
int Machine_Id, Price; //data members
char name[10];
public:
Machine(int x1, int y1,char *z1)
{
strcpy(name,z1);
Machine_Id = x1;
Price = y1;
}
/* Copy constructor */
Machine (const Machine &sam)
{
strcpy(name,sam.name);
Machine_Id=sam.Machine_Id;
Price=sam.Price;
}
void display()
{
cout<<"\n Name:\t"<<name;
cout<<"\n MachineID:\t"<<setprecision(2)<<Machine_Id;
cout<<"\n Price:\t"<<setw(3)<<Price;
}
};
/* main function */
int main()
{
Machine obj1(123, 1534,"archana"); // Normal constructor
Machine obj2 = obj1; // Copy constructor
cout<<"Normal constructor : ";
obj1.display();
cout<<"Copy constructor : ";
obj2.display();
return 0;
}
0 Comments