Question: Why is my code not compiling correctly? Please show a screenshot of code running properly. In the Programming Example Election Results, the class candidateType contains
Why is my code not compiling correctly? Please show a screenshot of code running properly.
In the Programming Example Election Results, the class candidateType contains the function calculateTotalVotes. After processing the voting data, this function calculates the total number of votes received by a candidate. The function updateVotesByRegion (of the class candidateType) updates only the number of votes for a particular region. Modify the definition of this function so that it also updates the total number of votes received by the candidate. By doing so, the function addVotes in the main program is no longer needed. Modify and run your program with the modified definition of the function updateVotesByRegion.
CODE:
#include
#include
using namespace std;
void candidateType::setVotes(int region, int votes) { votesByRegion[region - 1] = votes; }
void candidateType::updateVotesByRegion(int region, int votes) { votesByRegion[region - 1] = votesByRegion[region - 1] + votes; calculateTotalVotes(); }
void candidateType::calculateTotalVotes() { totalVotes = 0;
for (int i = 0; i < NO_OF_REGIONS; i++) totalVotes += votesByRegion[i]; }
int candidateType::getTotalVotes() const { return totalVotes; }
void candidateType::printData() const { cout << left << setw(10) << firstName << " " << setw(10) << lastName << " ";
cout << right;
for (int i = 0; i < NO_OF_REGIONS; i++) cout << setw(7) << votesByRegion[i] << " "; cout << setw(7) << totalVotes << endl; }
candidateType::candidateType() { for (int i = 0; i < NO_OF_REGIONS; i++) votesByRegion[i] = 0;
totalVotes = 0; }
bool candidateType::operator==(const candidateType& right) const { return(firstName == right.firstName && lastName == right.lastName); }
bool candidateType::operator!=(const candidateType& right) const { cout << "See Programming Exercise 13." << endl; return false; }
bool candidateType::operator<=(const candidateType& right) const { cout << "See Programming Exercise 13." << endl; return false; }
bool candidateType::operator<(const candidateType& right) const { cout << "See Programming Exercise 13." << endl; return false; }
bool candidateType::operator>=(const candidateType& right) const { cout << "See Programming Exercise 13." << endl; return false; }
bool candidateType::operator>(const candidateType& right) const { cout << "See Programming Exercise 13." << endl; return false; }
const candidateType& candidateType::operator=(const candidateType& right) { cout << "See Programming Exercise 13." << endl; return *this; }
const candidateType& candidateType::operator=(const personType& right) { cout << "See Programming Exercise 13." << endl;
return *this; }
#include
using namespace std;
void personType::setName(string first, string last) { cout << "See Programming Exercise 13" << endl; }
string personType::getFirstName() const { cout << "See Programming Exercise 13" << endl; return ""; }
string personType::getLastName() const { cout << "See Programming Exercise 13" << endl; return ""; }
//constructor personType::personType(string first, string last) { cout << "See Programming Exercise 13" << endl; }
const personType& personType::operator=(const personType& right) { cout << "See Programming Exercise 13" << endl;
return *this; }
//overload the operator == bool personType::operator==(const personType& right) const { return (firstName == right.firstName && lastName == right.lastName); }
bool personType::operator!=(const personType& right) const { cout << "See Programming Exercise 13" << endl; return false; }
bool personType::operator<=(const personType& right) const { cout << "See Programming Exercise 13" << endl; return false; }
bool personType::operator<(const personType& right) const { cout << "See Programming Exercise 13" << endl; return false; }
bool personType::operator>=(const personType& right) const { cout << "See Programming Exercise 13" << endl; return false; }
bool personType::operator>(const personType& right) const { cout << "See Programming Exercise 13" << endl; return false; }
istream& operator>>(istream& is, personType& pName) { is>>pName.firstName>>pName.lastName; return is; }
ostream& operator<<(ostream& os, const personType& pName) { cout << "See Programming Exercise 13" << endl; return os; }
#include
using namespace std;
const int NO_OF_CANDIDATES = 6;
void fillNames(ifstream& inFile, orderedArrayListType
int main() { orderedArrayListType
return 0; }
void fillNames(ifstream& inFile, orderedArrayListType
for (int i = 0; i < NO_OF_CANDIDATES; i++) { inFile >> firstN >> lastN; temp.setName(firstN, lastN); cList.insertAt(i, temp); } }
void processVotes(ifstream& inFile, orderedArrayListType
void printHeading() { cout << " --------------------Election Results---------" << "-----------" << endl << endl; cout << " Votes" << endl; cout << " Candidate Name Region1 Region2 Region3 " <<"Region4 Total" << endl; cout << "--------------------- ------- ------- " << "------- ------- ------" << endl; }
void printResults(orderedArrayListType
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
