Voting rules are as follows:
1. Each voter can only vote once. The voter by generating a random number between the first to the last candidates to choose a candidate to vote for.
2. Each candidate holds the record of voters vote for them
3. After the election, the candidate who has the highest votes is elected.
Program design:
The first part:
1. Design a Person class contains the following information
1.1. Fields:
_name: contains the person's Name. The Name can be as long as required.
_age: this person's age
_salary: this person's salary (a real)
_id: this person id. A person id cannot have intention to not intentional of change by any function (current or future). It is assigned by the program at creation time specified when It was founded by (program) and and sorted. When creating the record that is to say, the first person's id is 1; Second person's id is 2 and so on.
_totalPersons: a static variable to hold the total number of
1.2. Function:
The constructor Person (name, age, salary)
Modify the function to change the age: SetAge (newAge);
Modify the function to change salary:
SetSalary (newSalary);
A print function that will print out the person's name and id (for example,, & lt;
2. Design a Voter class will inherit from the Person class and have the following information
2.1. Fields:
_polingStation: the number of the poling station that the voter needs to go and register
_totalNumVoters: a static variable that contains the total number of voters that each candidate has.
2.2. Function:
The constructor Voter (name, age, salary, polingStation)
A modifier to the poling station: SetPolingStation (newPolingStation);
Print () function will Print voters name and polling station id.
Overloaded operator==: the operator returns true if the two voters have the same ID.
A static function Voters () : that returns the number of Voters assigned to all candidates
Function Person& SelectCadidate (PersonSet& Candidates) : randomly selected a candidate
3. Design a kind of Candidate, from the Person class inheritance, and has the following information:
3.1. Field (variable) :
_voterSet: the voterSet contains all voters cast by the candidate (the words as possible). This set should not have a size limit. Use your first homework PersonSet implementation by the container to complete.
_numCandidates: a static variable that contains the total number of candidates which are still in the race for the leadership
/////////////////////////////////a static variable that contains the number of candidates is still in the competition led.
3.2. Function:
Constructor Candidate (name, age, salary)
A function returns a candidate for the vote: int GetVotesNum () returns the vote
AddVoter (Voter& AVoter) add a voter to candidates
Overload & lt; <: print all the names of the vote for the candidate of the voters. If There is no voters, this function will output "There are no voters!!!! "
GetAverageVotersAge () : print the vote for the candidate of the voters, the average age of the
GetAverageVotersSalary () : print the vote for the candidate of the voters, the average salary
Operator overload & lt; (e.g., candidateA & lt; CandidateB) : this operator marks if candidateA lost to b. this is according to the turnout for each candidate.
A static function Candidates () : returns is still in the total number of Candidates is competition;
Experts can show a complete project, or some important pieces of code can also, I would be grateful,
CodePudding user response:
The difficulty is not great, you carefully to find the c + + books, slowly see object-oriented design, should get soon,Mentality smooth reading, this can get very quickly,
CodePudding user response:
I am new to learn, time is one month, many didn't grasp the understanding of basic knowledge, just contact this job really feel day eating gobbledygook, but time is limited, so just come here to ask for help, if I also like you believe in my eyes always contact application the operation difficulty is not big, or very thank you ~ ~CodePudding user response:
Will slowly do, others directly to your code, you'll never learn can't,CodePudding user response: