In: Computer Science
Class object in C++ programming language description about lesson copy constructor example.
#include
#include
#include
using namespace std;
class emp{
private:
char name[30];
float salary;
public:
float getsalary();
emp(const char[]="Seyha",float=0.0);
emp(const emp &a);
~emp();
void input();
void print();
};
emp::emp(const char *nm, float salary)
:salary(salary){
strcpy(name,nm);
}
emp::~emp(){
cout<<" Calling destructor... "< } emp::emp(const emp &a){ strcpy(this->name,a.name); this->salary=a.salary; cout<<" Calling copy constructor..."< } void emp::input(){ cout<<" Enter name: ";cin.getline(name,30); cout<<" Enter Salary: ";cin>>salary; cin.sync(); } void emp::print(){ cout< } float emp::getsalary(){ //no return salary; } void infor(emp em){ //NO em.print(); if(em.getsalary()>=1000){ cout<<" You got too hight salary "< }else cout<<" Try more to get a higher salary"< } int main(){ emp obj1("Run seyha",1700); emp obj2(obj1); emp obj3=obj2; obj1.print(); obj2.print(); obj3.print(); infor(obj1); }