Code :
========================
#include<iostream.h>
#include<string.h>
class Worker{
private:
char name[20];
int hour;
float rate;
public:
Worker();
Worker(char *na,int h,float r);
void input();
void output();
float income();
char *getname(){return name;}
};
Worker::Worker(char *na,int h,float r){
strcpy(name,na);
hour=h;
rate=r;
}
Worker::Worker(){
strcpy(name,"No Name");
hour=0;
rate=0;
}
void Worker::input()
{
cout<<"Input Name:";cin.clear();cin.seekg(0);cin.get(name,20);
cout<<"Input hour:";cin>>hour;
cout<<"Input rate:";cin>>rate;
}
void Worker::output(){
cout<<name<<"\t"<<hour<<"\t"<<rate<<"\t"<<hour<<"\t"<<income()<<endl;
}
float Worker::income(){
return rate*hour;}
float total(Worker a[],int n)
{ float s=0;
for(int i=0;i<n;i++)
s=s+a[i].income();
return s;
}
Worker *maxincome(Worker a[],int n)
{
Worker *p;
p=&a[0];
for(int i=1;i<n;i++)
if (p->income()<a[i].income())
p=&a[i];
return p;
}
void main(){int i,n;
Worker a[3]={Worker("sok",56,3.5),Worker("San",85,3.5),Worker("Lyva",98,3.5)};
cout<<"Constructer name:"<<endl;
for(i=0;i<3;i++)
a[i].output();
cout<<"Input n:";cin>>n;
Worker *p=new Worker [n];
for(i=0;i<n;i++)
p[i].input();
cout<<"All Worker "<<endl;
for(i=0;i<n;i++)
p[i].output();
float s1=total(p,n);
cout<<"Sum of income: "<<s1<<endl;
Worker *ptr;
ptr=maxincome(p,n);
cout<<"The max worker income: "<<ptr->getname()<<endl;
delete[] p;
}
//Share it to your friends ..!
0 comments:
Post a Comment