本文整理汇总了C++中Staff::GetState方法的典型用法代码示例。如果您正苦于以下问题:C++ Staff::GetState方法的具体用法?C++ Staff::GetState怎么用?C++ Staff::GetState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Staff
的用法示例。
在下文中一共展示了Staff::GetState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Save
void Database::Save(){
//若未修改则不保存
if (!changed)return;
changed = false;
ofstream fout("staff.dat");
//Form Header
fout<<"id#name#kind#age#state#manager_id#sales#events\n"; //注意,比如名字输入时要检查,不能存在#
for(auto &mp : staffs){
Staff *p = mp.second;
fout << p->GetID() << "#";
fout << p->GetName() << "#";
fout << p->GetKind() << "#";
fout << p->GetAge() << "#";
fout << p->GetState() << "#";
//注意,SalesManager由于继承了SalesMan,其指针也可以转为SalesMan*
if(p->GetKind() == SALESMAN){
SalesMan *sa = dynamic_cast<SalesMan*>(p);
fout << sa->GetManagerID() << "#";
}else{
fout << "-1#";
}
Achievement ach = p->GetAchievement();
fout << ach.sales << "#" << ach.events << endl;
}
fout.close();
}
示例2: Show
void Database::Show(Exp * filter){
//若不传入过滤器,则使用全局的viewFilter
if (!filter)
filter = viewFilter;
//获取筛选结果
vector<Staff *> vs;
GetStaffList(vs,filter);
//排序
sort(vs.begin(),vs.end(),comparer);
//更正显示页数
max_page = ceil(vs.size() * 1.0 / page_items);
if (cur_page > max_page)cur_page = max_page;
if (cur_page < 1)cur_page = 1;
//填表,为了显示得更好
Form form;
//Header
form.write(0,0,"ID");
form.write(0,1,"Name");
form.write(0,2,"Age");
form.write(0,3,"State");
form.write(0,4,"Kind");
form.write(0,5,"Manager ID");
form.write(0,6,"Sales");
form.write(0,7,"Events");
size_t start = (cur_page - 1) * page_items;
size_t end = start + page_items;
//[start,end)
if (end > vs.size())end = vs.size();
size_t items = end - start;
for (size_t i = 0;i < items;++i){
//多态
size_t r = start + i;
Staff *s = vs[r];
form.write(i+1,0,ITOS(s->GetID()));
form.write(i+1,1,s->GetName());
form.write(i+1,2,ITOS(s->GetAge()));
switch(s->GetState()){
case ACTIVE:
form.write(i+1,3,"在职");break;
case RESIGN:
form.write(i+1,3,"离职");break;
case LEAVE:
form.write(i+1,3,"请假");break;
}
switch(s->GetKind()){
case SALESMAN:
form.write(i+1,4,"SalesMan");break;
case MANAGER:
form.write(i+1,4,"Manager");break;
case SALESMANAGER:
form.write(i+1,4,"SalesManager");break;
case STAFF:
break;
}
SalesMan *psalesman = dynamic_cast<SalesMan*>(s);
Manager *pmanager = dynamic_cast<Manager*>(s);
SalesManager *psalesmanager = dynamic_cast<SalesManager*>(s);
//因为必定只有3类
if (psalesmanager){
form.write(i+1,5,"--");
Achievement ac = psalesmanager -> GetAchievement();
form.write(i+1,6,ITOS(ac.sales));
form.write(i+1,7,ITOS(ac.events));
}else{
if (psalesman){
int manager_id = psalesman -> GetManagerID();
if (manager_id == -1){
form.write(i+1,5,"NULL");
}else{
form.write(i+1,5,ITOS(manager_id));
}
Achievement ac = psalesman -> GetAchievement();
form.write(i+1,6,ITOS(ac.sales));
form.write(i+1,7,"--");
}else{
form.write(i+1,5,"--");
Achievement ac = pmanager -> GetAchievement();
form.write(i+1,6,"--");
form.write(i+1,7,ITOS(ac.events));
}
}
}
cout << "筛选条件:" << filterName << endl;
form.print();
cout << "第" << cur_page << "/" << max_page << "页 (共"<<vs.size()<<"项)" << "\t";
cout << "( n:下一页 N:上一页 gg 39:跳转到39页 )" << endl;
}