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 #include #include "candidateType.h"

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 #include #include "personType.h"

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 #include #include #include "candidateType.h" #include "orderedArrayListType.h"

using namespace std;

const int NO_OF_CANDIDATES = 6;

void fillNames(ifstream& inFile, orderedArrayListType& cList); void processVotes(ifstream& inFile, orderedArrayListType& cList); void addVotes(orderedArrayListType& cList); void printHeading(); void printResults(orderedArrayListType& cList);

int main() { orderedArrayListType candidateList(NO_OF_CANDIDATES); ifstream inFile; inFile.open("candData.txt"); fillNames(inFile, candidateList); candidateList.selectionSort(); inFile.close(); inFile.open("voteData.txt"); processVotes(inFile, candidateList); addVotes(candidateList); printHeading(); printResults(candidateList);

return 0; }

void fillNames(ifstream& inFile, orderedArrayListType& cList) { string firstN; string lastN; candidateType temp;

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& cList) { cout << "See Programming Exercise 13" << endl; } void addVotes(orderedArrayListType& cList) { candidateType temp; for (int i = 0; i < NO_OF_CANDIDATES; i++) { cList.retrieveAt(i, temp); temp.calculateTotalVotes(); cList.replaceAt(i, temp); } }

void printHeading() { cout << " --------------------Election Results---------" << "-----------" << endl << endl; cout << " Votes" << endl; cout << " Candidate Name Region1 Region2 Region3 " <<"Region4 Total" << endl; cout << "--------------------- ------- ------- " << "------- ------- ------" << endl; }

void printResults(orderedArrayListType& cList) { cout << "See Programming Exercise 13" << endl; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!