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

2014-11-24 12:08:19 · 作者: · 浏览: 7
选举人所得到的票数
传入参数:N/A
返回 值 :N/A
********************************************/
int Candidate:: getVotesNum(){
//static int s=0;

int size= (_votorSet).size();
return size;

}
/*******************************************
函数名称: void AddVoter(Voter& aVoter);
函数功能:得到选举人所给的票,记住给当前候选人投票人的信息
传入参数:N/A
返回 值 :N/A
********************************************/
void Candidate:: AddVoter(Voter& aVoter){

(_votorSet).add(aVoter);

}
/*******************************************
函数名称: int getAverageVotersAge();
函数功能:获取所以给当前候选人投票的所有选举人的平均年龄
传入参数:N/A
返回 值 :N/A
********************************************/
double Candidate:: getAverageVotersAge(){

int sumAge=0;

int sum=Voter::_totalNumVoters;//每位候选人得到的总票数
for(int i=0;i //Voter& v = static_cast(_votorSet.nextElement());
//sumAge+=v.nextElement().getAge();
sumAge+=_votorSet.nextElement().getAge();
}
average_age=sumAge/sum;
return average_age;
}
/*******************************************
函数名称: int getAverageVotersSalary();
函数功能:获取所以给当前候选人投票的所有选举人的平均薪资
传入参数:N/A
返回 值 :N/A
********************************************/
double Candidate:: getAverageVotersSalary(){
double sumSalary=0;

int sum=Voter::_totalNumVoters;//每位候选人得到的总票数
for(int i=0;i PersonSet _votorSet;
//Voter& v = static_cast(_votorSet.nextElement());
//sumSalary+=v.getSalary();
sumSalary+=_votorSet.nextElement().getSalary();
}

average_salary = sumSalary/sum;
return average_salary;
}
/*******************************************
函数名称: static int Candidates();
函数功能:获取所有的候选人个数
传入参数:N/A
返回 值 :N/A
********************************************/
//得到参加比赛的候选人的数量
int Candidate:: Candidates()
{

return _numCandidates;

}
/*******************************************
函数名称:bool operator<(Candidate& a,Candidate& b);
函数功能:重载运算符,判断是否a 传入参数:N/A
返回 值 :N/A
********************************************/
bool operator<(Candidate& a,Candidate& b){
bool flag=true;

if(a.getVotesNum()>b.getVotesNum()){

flag=false;
}

return flag;
}
/*******************************************
函数名称:ostream& operator<<(ostream& ,Person&)
函数功能:输出运算符重载函数 www.2cto.com
传入参数:N/A
返回 值 :N/A
********************************************/
ostream& operator<<(ostream& out,Candidate& c){
if(c.getVotesNum()==0){
cout<<"There are no voters !!!!"<
}
out<
return out;
}


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

#ifndef _PersonSet_H
#define _PersonSet_H
#include "Person.h"

class Voter;
class Candidate;
class PersonSet{

protected:
//定义Person二级指针
Person** _elements;
//容量的大小
int _capacity;
//实际大小
int _size;
//指向
int _index;
public:
/*******************************************
函数名称:PersonSet();
函数功能:默认构造函数
传入参数:N/A
返回 值 :N/A
********************************************/
PersonSet();

// PersonSet(Person& p);
/*******************************************
函数名称: PersonSet(PersonSet& p);
函数功能:拷贝构造函数
传入参数:N/A
返回 值 :N/A
********************************************/
PersonSet(const PersonSet& p);
/*******************************************
函数名称: const PersonSet& operator=(const PersonSet& p);
函数功能:赋值运算符重载
传入参数:N/A
返回 值 :N/A
*******************************