int main(int argc, char *argv[])
{
//创建选举人
Voter *v1 = new Voter("John", 20, 6000.0,1);
Voter *v2 = new Voter("Frank", 26, 30000.0,2);
Voter *v3 = new Voter("Anna", 20, 199600.0,1);
Voter *v4 = new Voter("James", 67, 9600.0,2);
Voter *v5 = new Voter("Jane", 40, 29600.0,3);
//创建候选人
Candidate *c1 = new Candidate("April", 67, 9600.0 );
Candidate *c2 = new Candidate("May", 40, 29600.0);
Candidate *c3 = new Candidate("June", 40, 29600.0);
srand(time(NULL));
PersonSet voters;
voters.add(*v1);
voters.add(*v2);
voters.add(*v3);
voters.add(*v4);
voters.add(*v5);
PersonSet candidates;
candidates.add(*c1);
candidates.add(*c2);
candidates.add(*c3);
int numVoters = voters.size();
voters.reset();
cout << "number of voters = " << numVoters << "\n";
for(int i = 0; i
Voter& voter = static_cast
cout << voter << "\n";
}
voters.reset(); // Set the index zero
cout << "voting = \n";
for(int i = 0; i
Voter& v = static_cast
// choose a candidate
Candidate& chosenCandidate = static_cast
v.Vote(chosenCandidate);
}
/* cout<<"voters.size()="< if(winner->getVotesNum() == 2) makefile 文件 ############################################################################### # Description: # Usage: .SUFFIXES = .c .o .cpp SOURCE = Person.h Person.cpp Voter.h Voter.cpp Candidate.h Candidate.cpp PersonSet.h PersonSet.cpp main.cpp
for(int a=0;a
if((p=&static_cast
}
}
}
*/
cout<<"April:"<
if (voters.size() != Voter::_totalNumVoters)
{
cout <<" Not all voters voted !!!!" << endl ;
}
else
{
cout <<" Success: 100% voted" << endl;
}
Candidate* winner = static_cast
for ( int i=0; i
if ( *winner < *(static_cast
{
winner = static_cast
}
}
{
PersonSet ps;
for(int i = 0 ; i < candidates.size() ; i++)
{
Candidate * p;
if(( p = &static_cast
{
ps.add(*p);
}
}
for(int j=0;j
Voter& v = static_cast
// choose a candidate
Candidate& chosenCandidate = static_cast
v.Vote(chosenCandidate);
}
cout<<"twice Vote:"<
for ( int i=0; i
if ( *winner < *(static_cast
{
winner = static_cast
}
}
cout << " the winner is : " << *winner<
}else{
cout << " the winner is : " << *winner<
delete v1;
delete v2;
delete v3;
delete v4;
delete v5;
delete c1;
delete c2;
delete c3;
return 0;
}
linux环境编译时所用到的文件
#
# Generic Makefile for C/C++ Program
#
# Author:
# Date:
# The makefile searches in
# with extensions specified in
# and finally produces the
# the objectives.
# $ make compile and link the program.
# $ make objs compile only (no linking. Rarely used).
# $ make clean clean the objectives and dependencies.
# $ make cleanall clean the objectives, dependencies and executable.
# $ make rebuild rebuild the program. The same as make clean && make all.
#==============================================================================
CFLAGS = -g
EXE = a.out
.c.o:
gcc -c $(CFLAGS) $<
.cpp.o:
g++ -c $(CFLAGS) $<
OBJECTS = ${