C++第二个项目实现(三)

2014-11-24 12:08:19 · 作者: · 浏览: 4
***************************************/
static int Voters();
/*******************************************
函数名称:Person& SelectCadidate(PersonSet& cadidates);
函数功能:随机获取候选人
传入参数:N/A
返回 值 :N/A
********************************************/
Person& SelectCadidate(PersonSet& cadidates);

};

#endif


/***************************************************
文件名称:Voter.cpp
作 者:zz
备 注:选举人的头文件
创建时间:2012-4-1
修改历史:2012-4-5
版权声明:CSDN
***************************************************/


#include "Voter.h"
#include
#include
#include "Candidate.h"
#include "PersonSet.h"
#include "Person.h"
using namespace std;
//初始化选举人的个数
int Voter::_totalNumVoters=0;
/*******************************************
函数名称: Voter::Voter(string name,int age,int salary,int polingStation)
函数功能:带参构造函数
传入参数:N/A
返回 值 :N/A
********************************************/
Voter::Voter(string name,int age,double salary,int polingStation):
Person(name,age,salary),_polingStation(polingStation){
_totalNumVoters++;
}
/*******************************************
函数名称:void Vote( Candidate& aCandidate );
函数功能:开始选举
传入参数:N/A
返回 值 :N/A
********************************************/
void Voter::Vote( Candidate& aCandidate ){
aCandidate.AddVoter(*this);
}
/*******************************************
函数名称: void set_polingStation(int newPolingStation);
函数功能:_polingStation的set方法
传入参数:N/A
返回 值 :N/A
********************************************/
void Voter::set_polingStation(int newPolingStation){

_polingStation=newPolingStation;
}
/*******************************************
函数名称:void print();
函数功能:print方法
传入参数:N/A
返回 值 :N/A
********************************************/
void Voter::print()const{

cout<<"voter name is:"<<_name< cout<<"voter _polingStation id is"<<_polingStation<
}
/*******************************************
函数名称:friend bool operator==(Voter& a,Voter& b)
函数功能:判断两个对象是否相同
传入参数:N/A
返回 值 :N/A
********************************************/
bool operator==(Voter& a,Voter& b){

bool flag=false;
if(a._id==b._id){

flag=true;
return flag;
}

return flag;
}

/*******************************************
函数名称:static int Voters();
函数功能:静态的方法,返回所有选举人的个数
传入参数:N/A
返回 值 :N/A
********************************************/
int Voter::Voters(){
//返回所给候选人投票的人数

return _totalNumVoters;


}

/*******************************************
函数名称:Person& SelectCadidate(PersonSet& cadidates);
函数功能:随机获取候选人
传入参数:N/A
返回 值 :N/A
********************************************/
Person& Voter::SelectCadidate(PersonSet& candidates){
int x=candidates.size();
int r=rand()%x;
return candidates[r];
}

/*******************************************
函数名称: int get_PolingStation()const;
函数功能:_polingStation的get方法
传入参数:N/A
返回 值 :N/A
********************************************/
int Voter::get_PolingStation()const{
return _polingStation;
}


/***************************************************
文件名称:Candidate.h
作 者:zz
备 注:候选人的头文件
创建时间:2012-4-1
修改历史:2012-4-5
版权声明:CSDN
***************************************************/

#ifndef _Candidate_H
#define _Candidate_H
#include