




已阅读5页,还剩30页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
文件名称:Person.h*/#ifndef _Person_H#define _Person_H#include #include using namespace std;class Personfriend ostream& operator(ostream& ,Person&);protected:string _name;int _age;double _salary;const int _id;static int _totalPersons;public:Person(string name=zhangsan,int age=0,double salary=0);void setAge(int newAge);/* 函数名称:void setSalary(int salary) 函数功能:_salary的set方法 传入参数:N/A 返回 值 :N/A*/void setSalary(double salary);/* 函数名称:void setName(int name) 函数功能:_name的set方法 传入参数:N/A 返回 值 :N/A*/void setName(string name);/* 函数名称:string getName(); 函数功能:_name的get方法 传入参数:N/A 返回 值 :N/A*/string getName()const;/* 函数名称:int getAge(); 函数功能:_age的get方法 传入参数:N/A 返回 值 :N/A*/int getAge()const;/* 函数名称:int getSalary(); 函数功能:_salary的get方法 传入参数:N/A 返回 值 :N/A*/double getSalary()const;/* 函数名称:void print(); 函数功能:print方法 传入参数:N/A 返回 值 :N/A*/void print()const;#endif/* 文件名称:Person.cpp 作 者:zz 备 注:人的实现文件 创建时间:2012-4-1 修改历史:2012-4-5 版权声明:CSDN*/#include Person.h#include #include using namespace std;/初始化总人数 int Person:_totalPersons=0;/* 函数名称:Person(string name,int age,int salary) 函数功能:带参构造函数 传入参数:N/A 返回 值 :N/A*/Person:Person(string name,int age,double salary): _name(name),_age(age),_salary(salary),_id(_totalPersons ) _totalPersons+;/* 函数名称:void setAge(int newAge) 函数功能:_age的set方法 传入参数:N/A 返回 值 :N/A*/void Person:setAge(int newAge) _age=newAge;/* 函数名称:void setSalary(int salary) 函数功能:_salary的set方法 传入参数:N/A 返回 值 :N/A*/void Person:setSalary(double salary) _salary=salary;/* 函数名称:void print(); 函数功能:print方法 传入参数:N/A 返回 值 :N/A*/void Person:print()const coutPerson name is_nameendl; coutPerosn id is_idendl;/* 函数名称:ostream& operator(ostream& ,Person&) 函数功能:输出运算符重载函数 传入参数:N/A 返回 值 :N/A*/ ostream& operator(ostream& out ,Person& person) outPerson name:person._nameendl; outPerson age:person._ageendl; outPerson salary:person._salaryendl; outPerson id:person._idendl; return out;/* 函数名称:void setName(int name) 函数功能:_name的set方法 传入参数:N/A 返回 值 :N/A*/void Person:setName(string name) _name= name;/* 函数名称:string getName(); 函数功能:_name的get方法 传入参数:N/A 返回 值 :N/A*/string Person:getName()const return _name;/* 函数名称:int getAge(); 函数功能:_age的get方法 传入参数:N/A 返回 值 :N/A*/int Person:getAge()const return _age;/* 函数名称:int getSalary(); 函数功能:_salary的get方法 传入参数:N/A 返回 值 :N/A*/double Person:getSalary()const return _salary;/* 文件名称:Voter.h 作 者:zz 备 注:选举人的头文件 创建时间:2012-4-1 修改历史:2012-4-5 版权声明:CSDN*/#ifndef _Voter_H#define _Voter_H#include Person.h#include #include using namespace std;class PersonSet;class Candidate;class Voter:public Person/* 函数名称:friend bool operator=(Voter& a,Voter& b) 函数功能:判断两个对象是否相同 传入参数:N/A 返回 值 :N/A*/friend bool operator=(Voter& a,Voter& b);protected:int _polingStation;/站台号public:static int _totalNumVoters; /参加选举的人数/* 函数名称:Voter(string name=zhangsan,int age=0,int salary=0,int polingStation=0); 函数功能:带参构造函数 传入参数:N/A 返回 值 :N/A*/Voter(string name=zhangsan,int age=0,double salary=0,int polingStation=0);/* 函数名称:void Vote( Candidate& aCandidate ); 函数功能:开始选举 传入参数:N/A 返回 值 :N/A*/ void Vote( Candidate& aCandidate );/* 函数名称: void set_polingStation(int newPolingStation); 函数功能:_polingStation的set方法 传入参数:N/A 返回 值 :N/A*/void set_polingStation(int newPolingStation);/* 函数名称: int get_PolingStation()const; 函数功能:_polingStation的get方法 传入参数:N/A 返回 值 :N/A*/int get_PolingStation()const;/* 函数名称:void print(); 函数功能:print方法 传入参数:N/A 返回 值 :N/A*/void print()const;/* 函数名称:static int Voters(); 函数功能:静态的方法,返回所有选举人的个数 传入参数:N/A 返回 值 :N/A*/ 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.husing 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 coutvoter name is:_nameendl; coutvoter _polingStation id is_polingStationendl;/* 函数名称: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 candidatesr;/* 函数名称: int get_PolingStation()const; 函数功能:_polingStation的get方法 传入参数:N/A 返回 值 :N/A*/int Voter:get_PolingStation()constreturn _polingStation;/* 文件名称:Candidate.h 作 者:zz 备 注:候选人的头文件 创建时间:2012-4-1 修改历史:2012-4-5 版权声明:CSDN*/#ifndef _Candidate_H#define _Candidate_H#include Person.h#include PersonSet.h#include #include using namespace std;class PersonSet;class Voter;class Candidate:public Person/* 函数名称:ostream& operator(ostream& ,Person&) 函数功能:输出运算符重载函数 传入参数:N/A 返回 值 :N/A*/friend ostream& operator(ostream&,Candidate&);/* 函数名称:bool operator(Candidate& a,Candidate& b); 函数功能:重载运算符,判断是否ab 传入参数:N/A 返回 值 :N/A*/friend bool operator(Candidate& a,Candidate& b);protected:/定义一个PersonSet 对象 PersonSet _votorSet; double average_age;/平均年龄 double average_salary;/平均薪水 static int _numCandidates;/统计比赛中有多少候选人参加public:/* 函数名称:PersonSet& Candidate:getPersonSet() 函数功能:PersonSet对象的get方法 传入参数:N/A 返回 值 :N/A*/PersonSet& getPersonSet();/* 函数名称: Candidate(string name=lisi,int age=5,int salary=1222); 函数功能:带参构造函数 传入参数:N/A 返回 值 :N/A*/Candidate(string name=lisi,int age=5,double salary=0);/* 函数名称: int getVotesNum(); 函数功能:当前选举人所得到的票数 传入参数:N/A 返回 值 :N/A*/int getVotesNum();/得到每个候选人的票数/* 函数名称: void AddVoter(Voter& aVoter); 函数功能:得到选举人所给的票,记住给当前候选人投票人的信息 传入参数:N/A 返回 值 :N/A*/ void AddVoter(Voter& aVoter);/* 函数名称: int getAverageVotersAge(); 函数功能:获取所以给当前候选人投票的所有选举人的平均年龄 传入参数:N/A 返回 值 :N/A*/double getAverageVotersAge();/* 函数名称: int getAverageVotersSalary(); 函数功能:获取所以给当前候选人投票的所有选举人的平均薪资 传入参数:N/A 返回 值 :N/A*/double getAverageVotersSalary();/* 函数名称: static int Candidates(); 函数功能:获取所有的候选人个数 传入参数:N/A 返回 值 :N/A*/static int Candidates();#endif/* 文件名称:Candidate.cpp 作 者:zz 备 注:候选人的实现文件 创建时间:2012-4-1 修改历史:2012-4-5 版权声明:CSDN*/#include Candidate.h#include Voter.h#include PersonSet.h#include Person.h#include #include using namespace std; /初始化 总候选人的个数int Candidate:_numCandidates=0;/* 函数名称:PersonSet& Candidate:getPersonSet() 函数功能:PersonSet对象的get方法 传入参数:N/A 返回 值 :N/A*/PersonSet& Candidate:getPersonSet() return _votorSet; /* 函数名称: Candidate(string name=lisi,int age=5,int salary=1222); 函数功能:带参构造函数 传入参数:N/A 返回 值 :N/A*/Candidate: Candidate(string name,int age,double salary):Person(name,age,salary) _numCandidates+;/* 函数名称: int getVotesNum(); 函数功能:当前选举人所得到的票数 传入参数: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;isum;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;isum;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); 函数功能:重载运算符,判断是否ab 传入参数:N/A 返回 值 :N/A*/bool operatorb.getVotesNum() flag=false; return flag;/* 函数名称:ostream& operator(ostream& ,Person&) 函数功能:输出运算符重载函数 传入参数:N/A 返回 值 :N/A*/ostream& operator(ostream& out,Candidate& c) if(c.getVotesNum()=0) coutThere are no voters !endl; outc.getName()endl; return out;/* 文件名称:PersonSet.h 作 者:zz 备 注:PersonSet的头文件 创建时间:2012-4-1 修改历史:2012-4-5 版权声明:CSDN*/#ifndef _PersonSet_H#define _PersonSet_H#include Person.hclass Voter;class Candidate;class PersonSetprotected:/定义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*/const PersonSet& operator=(const PersonSet& p);/* 函数名称: void add(Person& element); 函数功能:添加元素 传入参数:N/A 返回 值 :N/A*/ void add(Person& element);/* 函数名称:Person& nextElement(); 函数功能:遍历元素 传入参数:N/A 返回 值 :N/A*/Person& nextElement();/
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 汉字的来历课件
- 云南省昆明市2024-2025学年七年级下学期期中考试地理试卷(含答案)
- 广东省湛江市第一中学2024-2025学年第一学期第三次综合素质评价(期末)试卷(含解析)
- 工地协议书范文
- 工厂厂房转让合同(6篇)
- 2024-2025学年广东省广州市番禺区高二(下)期末物理试卷(含答案)
- 《诗经》与楚辞导读知到智慧树答案
- 成都二手房买卖合同(15篇)
- 房地产誓师大会发言稿
- 汉字书法课件模板图
- 建筑公司分包合同管理办法
- 2025至2030苏打水行业发展趋势分析与未来投资战略咨询研究报告
- 2025年秋季学期德育工作计划:向下扎根向上开花
- 2025-2030中国家政服务行业信用体系建设与服务质量监管报告
- 2025年安徽省普通高中学业水平选择性考试(物理)科目高考真题+(答案解析版)
- 2025年成都东部集团有限公司及下属企业招聘考试笔试试卷【附答案】
- 各分项工程质量保证措施
- 国税编制管理办法
- 特种畜禽管理办法
- 消防员心理健康教育课件教学
- 混凝土外加剂检测原始记录表
评论
0/150
提交评论