This program describes the use of object array.
output
#include<iostream.h>
#include<conio.h>
class employee
{
int emp_id;
char name[25],post[30];
public:
void read();
void print();
};
void employee::read()
{
cout<<"Enter employee id\n";
cin>>emp_id;
cout<<"Enter employee name\n";
cin>>name;
cout<<"Enter employee post\n";
cin>>post;
}
void employee::print()
{
cout<<emp_id<<"\t"<<name<<"\t"<<post<<endl;
#include<conio.h>
class employee
{
int emp_id;
char name[25],post[30];
public:
void read();
void print();
};
void employee::read()
{
cout<<"Enter employee id\n";
cin>>emp_id;
cout<<"Enter employee name\n";
cin>>name;
cout<<"Enter employee post\n";
cin>>post;
}
void employee::print()
{
cout<<emp_id<<"\t"<<name<<"\t"<<post<<endl;
}
void main()
{
int n;
clrscr();
employee e[20]; // object array creation
cout<<"Enter the number of employees\n(less than or equal to 10)\n";
cin>>n;
for(int i=0;i<n;i++) //read function call for 'n' employees
e[i].read();
cout<<"\n\nID\tNAME\tPOST\n";
for(i=0;i<n;i++) //print function call for 'n' employees
e[i].print();
getch();
}
void main()
{
int n;
clrscr();
employee e[20]; // object array creation
cout<<"Enter the number of employees\n(less than or equal to 10)\n";
cin>>n;
for(int i=0;i<n;i++) //read function call for 'n' employees
e[i].read();
cout<<"\n\nID\tNAME\tPOST\n";
for(i=0;i<n;i++) //print function call for 'n' employees
e[i].print();
getch();
}
output
No comments:
Post a Comment