A Program of 'Class and Objects' :-


(a) to declare & define member functions of class.
(b) to understand Call by Valuue concept(using a parameterised function).
(c) to display entered values using objects.

#include<iostream.h>
#include<string.h>
#include<conio.h>

class employee
{
public:
 int eid;
 char ename[3];

 int enterdetails(int id,char name[])
 {
 eid=id;
 strcpy(ename,name);
 }
 int showdetails()
 {
 cout<<"Employee ID:"<<eid<<"__"<<"Employee Name:"<<ename<<endl;
 }
 };
 void main()
 {
 clrscr();
 employee e1,e2;
 e1.enterdetails(1,"ABC");
 e2.enterdetails(2,"XYZ");

 e1.showdetails();
 e2.showdetails();

 cout<<endl<<"Employee ID:"<<e1.eid<<"__"<<"Employee Name:"<<e1.ename<<endl;
 cout<<"Employee ID:"<<e2.eid<<"__"<<"Employee Name:"<<e2.ename;

 getch();
 }

Output:


Employee ID:1__Employee Name:ABC
Employee ID:2__Employee Name:XYZ

Employee ID:1__Employee Name:ABC
Employee ID:2__Employee Name:XYZ

			

Previous Next