source file name: constemp.CPP
#include <iostream.h>
#include <conio.h>
#include <string.h>
class Employee {
int id;//data member (also instance variable)
char name[20];//data member(also instance variable)
float salary;
public:
Employee()
{
id = 10;
strcpy(name,"Suresh");
salary = 50000;
}
Employee(int i, char *n, float s)
{
id = i;
strcpy(name, n);
salary = s;
}
void show()
{
cout<<id<<" "<<name<<" "<<salary<<endl;
}
};
int main()
{
Employee e1 =Employee(1, "Suraj", 90000); //creating an object of Employee
Employee e2=Employee(2, "Mukund", 60000);
Employee e3;
clrscr();
e1.show();
e2.show();
e3.show();
return 0;
}
output:
0 Comments
Post a Comment