Question: Please show the output from this code: #include #include #include #include candidateType.h #include orderedArrayListType.h using namespace std; const int noOfCandidates = 6; void fillNames(ifstream& inFile,
Please show the output from this code:
#include
using namespace std;
const int noOfCandidates = 6;
void fillNames(ifstream& inFile, orderedArrayListType
void printHeading(); void printResults(orderedArrayListType
int main() { orderedArrayListType
return 0; }
void fillNames(ifstream& inFile, orderedArrayListType
for (i = 0; i < noOfCandidates; i++) { inFile >> firstN >> lastN; temp.setName(firstN, lastN); cList.insertAt(i, temp); } }
void processVotes(ifstream& inFile, orderedArrayListType
if (candLocation != -1) { cList.retrieveAt(candLocation, temp); temp.updateVotesByRegion(region, votes); cList.replaceAt(candLocation, temp); } inFile >> firstN >> lastN >> region >> votes; temp.setName(firstN, lastN); temp.setVotes(region, votes); } } void addVotes(orderedArrayListType
void printHeading() { cout << " --------------------Election Results---------" << "-----------" << endl << endl; cout << " Votes" << endl; cout << " Candidate Name Region1 Region2 Region3 " << "Region4 Total"< void printResults(orderedArrayListType #ifndef H_arrayListType #define H_arrayListType #include using namespace std; template template template template template template for (i = 0; i < length; i++) cout << list[i] << " "; cout << endl; } template template if (location < 0 || location >= maxSize) cout << "The position of the item to be inserted " << "is out of range." << endl; else if (length >= maxSize) //list is full cout << "Cannot insert in a full list" << endl; else { for (i = length; i > location; i--) list[i] = list[i - 1]; //move the elements down list[location] = insertItem; //insert the item at the //specified position length++; //increment the length } } //end insertAt template template if (location < 0 || location >= length) cout << "The location of the item to be removed " << "is out of range." << endl; else { for (i = location; i < length - 1; i++) list[i] = list[i+1]; length--; } } //end removeAt template template } //end replaceAt template template for (loc = 0; loc < length; loc++) if ( list[loc] == item) { found = true; break; } if (found) return loc; else return -1; } //end seqSearch template if (length == 0) //list is empty list[length++] = insertItem; //insert the item and //increment the length else if (length == maxSize) cout << "Cannot insert in a full list." << endl; else { loc = seqSearch(insertItem); if (loc == -1) //the item to be inserted //does not exist in the list list[length++] = insertItem; else cout << "the item to be inserted is already in " << "the list. No duplicates are allowed." << endl; } } //end insert template if (length == 0) cout << "Cannot delete from an empty list." << endl; else { loc = seqSearch(removeItem); if (loc != -1) removeAt(loc); else cout << "The tem to be deleted is not in the list." << endl; } } //end remove template maxSize = 100; } else maxSize = size; length = 0; list = new elemType[maxSize]; assert(list != NULL); } template //copy constructor template for (int j = 0; j < length; j++) //copy otherList list [j] = otherList.list[j]; }//end copy constructor template for (int i = 0; i < length; i++) list[i] = otherList.list[i]; } return *this; } #endif candidateType.h #ifndef H_candidateType #define H_candidateType #include const int noOfRegions = 4; class candidateType: public personType { public: const candidateType& operator=(const candidateType&); const candidateType& operator=(const personType&); void updateVotesByRegion(int region, int votes); void setVotes(int region, int votes); void calculateTotalVotes(); int getTotalVotes() const; void printData() const; candidateType(); bool operator==(const candidateType& right) const; bool operator!=(const candidateType& right) const; bool operator<=(const candidateType& right) const; bool operator<(const candidateType& right) const; bool operator>=(const candidateType& right) const; bool operator>(const candidateType& right) const; private: int votesByRegion[noOfRegions]; //array to store the //votes received in //each region int totalVotes; //variable to store the total votes }; #endif candidateTypeImp.cpp #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; } void candidateType::calculateTotalVotes() { int i; totalVotes = 0; for(i = 0; i < noOfRegions; 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 < noOfRegions; i++) cout << setw(8) << votesByRegion[i] << " "; cout << setw(7) << totalVotes << endl; } candidateType::candidateType() { for (int i = 0; i < noOfRegions; 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 { return(firstName != right.firstName && lastName != right.lastName); } bool candidateType::operator<=(const candidateType& right) const { return(lastName <= right.lastName || (lastName == right.lastName && firstName <= right.firstName)); } bool candidateType::operator<(const candidateType& right) const { return(lastName < right.lastName || (lastName == right.lastName && firstName < right.firstName)); } bool candidateType::operator>=(const candidateType& right) const { return(lastName >= right.lastName || (lastName == right.lastName && firstName >= right.firstName)); } bool candidateType::operator>(const candidateType& right) const { return(lastName > right.lastName || (lastName == right.lastName && firstName > right.firstName)); } const candidateType& candidateType::operator= (const candidateType& right) { if (this != &right) // avoid self-assignment { firstName = right.firstName; lastName = right.lastName; for (int i = 0; i < noOfRegions; i++) votesByRegion[i] = right.votesByRegion[i]; totalVotes = right.totalVotes; } return *this; } const candidateType& candidateType::operator= (const personType& right) { firstName = right.getFirstName(); lastName = right.getLastName(); return *this; } orderedArrayListType.h #include using namespace std; const int noOfCandidates = 6; void fillNames(ifstream& inFile, orderedArrayListType void printHeading(); void printResults(orderedArrayListType int main() { orderedArrayListType return 0; } void fillNames(ifstream& inFile, orderedArrayListType for (i = 0; i < noOfCandidates; i++) { inFile >> firstN >> lastN; temp.setName(firstN, lastN); cList.insertAt(i, temp); } } void processVotes(ifstream& inFile, orderedArrayListType if (candLocation != -1) { cList.retrieveAt(candLocation, temp); temp.updateVotesByRegion(region, votes); cList.replaceAt(candLocation, temp); } inFile >> firstN >> lastN >> region >> votes; temp.setName(firstN, lastN); temp.setVotes(region, votes); } } void addVotes(orderedArrayListType void printHeading() { cout << " --------------------Election Results---------" << "-----------" << endl << endl; cout << " Votes" << endl; cout << " Candidate Name Region1 Region2 Region3 " << "Region4 Total"< void printResults(orderedArrayListType personType.h #ifndef personType_H #define personType_H #include using namespace std; class personType { friend istream& operator>>(istream&, personType&); friend ostream& operator<<(ostream&, const personType&); public: void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); bool operator==(const personType& right) const; bool operator!=(const personType& right) const; bool operator<=(const personType& right) const; bool operator<(const personType& right) const; bool operator>=(const personType& right) const; bool operator>(const personType& right) const; protected: string firstName; //variable to store the first name string lastName; //variable to store the last name }; #endif personTypeImp.cpp #include using namespace std; void personType::setName(string first, string last) { firstName = first; lastName = last; } string personType::getFirstName() const { return firstName; } string personType::getLastName() const { return lastName; } //constructor personType::personType(string first, string last) { firstName = first; lastName = last; } bool personType::operator==(const personType& right) const { return(firstName == right.firstName && lastName == right.lastName); } bool personType::operator!=(const personType& right) const { return(firstName != right.firstName && lastName != right.lastName); } bool personType::operator<=(const personType& right) const { return(lastName <= right.lastName || (lastName == right.lastName && firstName <= right.firstName)); } bool personType::operator<(const personType& right) const { return(lastName < right.lastName || (lastName == right.lastName && firstName < right.firstName)); } bool personType::operator>=(const personType& right) const { return(lastName >= right.lastName || (lastName == right.lastName && firstName >= right.firstName)); } bool personType::operator>(const personType& right) const { return(lastName > right.lastName || (lastName == right.lastName && firstName > right.firstName)); } istream& operator>>(istream& isObject, personType& pName) { isObject >> pName.firstName >> pName.lastName; return isObject; } ostream& operator<<(ostream& osObject, const personType& pName) { osObject << pName.firstName << " " << pName.lastName; return osObject; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
