Problem
Create a Class of Employee with static members to count number of employees in the particular department?Code
#include "stdafx.h"
#include<conio.h>
#include<iostream>
#include<string.h>
using namespace std;
class employee
{
private:
static int cs;
static int phy;
static int maths;
static int eng;
static int mtr;
public:
void comp()
{ cs++; }
void PHY()
{ phy++; }
void MATHS()
{ maths++; }
void ENG()
{ eng++; }
void MTR()
{ mtr++; }
void display()
{
cout<<"\nNo. of employees in cs department ="<<cs;
cout<<"\nNo. of employees in physics department ="<<phy;
cout<<"\nNo. of employees in maths department ="<<maths;
cout<<"\nNo. of employees in engineering department="<<eng;
cout<<"\nNo. of employees in metrology department = "<<mtr;
cout<<"\n\nTotal no. of employees= "<<(cs+phy+maths+eng+mtr);
}
};
int
employee::cs=0;
int
employee::phy=0;
int
employee::maths=0;
int
employee::eng=0;
int
employee::mtr=0;
int main()
{
employee c[15],phy[15],mth[15],eng[15],mtr[15],e;
int i,n,j;
cout<<"Enter number of
employees of cs department: ";
cin>>n;
for(i=0;i<n;i++)
{ c[i].comp(); }
cout<<"Enter number of
employees of physics department: ";
cin>>n;
for(i=0;i<n;i++)
{ phy[i].PHY(); }
cout<<"Enter number of
employees of maths department: ";
cin>>n;
for(i=0;i<n;i++)
{ c[i].MATHS(); }
cout<<"Enter number of
employees of engineering department: ";
cin>>n;
for(i=0;i<n;i++)
{ c[i].ENG(); }
cout<<"Enter number of
employees of metrology department: ";
cin>>n;
for(i=0;i<n;i++)
{ c[i].MTR(); }
e.display();
cout<<"\n\nPress any key
to close.";
getch();
return 0;
}
No comments :
Post a Comment
Note: Only a member of this blog may post a comment.