Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the definitions of the functions class personType and class candidateType,

ID: 3883325 • Letter: W

Question

Write the definitions of the functions class personType and class candidateType, of the programming example Election Results. (anywhere it says "see programming exercise 13)

#include <iostream>

#include <string>

#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 <iostream>

#include <string>

#include <iomanip>

#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;

}

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;

}

ELECTION RESULTS:

#include <iostream>

#include <string>

#include <fstream>

#include "candidateType.h"

#include "orderedArrayListType.h"

using namespace std;

const int NO_OF_CANDIDATES = 6;

void fillNames(ifstream& inFile,

orderedArrayListType<candidateType>& cList);

void processVotes(ifstream& inFile,

orderedArrayListType<candidateType>& cList);

void addVotes(orderedArrayListType<candidateType>& cList);

void printHeading();

void printResults(orderedArrayListType<candidateType>& cList);

int main()

{

orderedArrayListType<candidateType> 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<candidateType>& 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<candidateType>& cList)

{

    cout << "See Programming Exercise 13" << endl;

}

    

void addVotes(orderedArrayListType<candidateType>& 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<candidateType>& cList)

{

    cout << "See Programming Exercise 13" << endl;

}

Explanation / Answer

Hi Friend, You have not posted personType.h and candidateType.h, hence I can not test.

But I have filled all functions. You can take help of these implementation.

You have not specified the meaning of ==, >, < <= >= operators with respect to personType and candidateType class.

Please post all the details of the question.

Please let me know in case of any issue.

###################

#include <iostream>
#include <string>
#include "personType.h"

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;
}

const personType& personType::operator=(const personType& right)
{
firstName = right.firstName;
lastName = right.lastName;

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
{
return (firstName != right.firstName || lastName != right.lastName);
}

bool personType::operator<=(const personType& right) const
{
if(firstName.compare(right.firstName) < 0)
return true;
else if((firstName.compare(right.firstName) == 0)
&& (lastName.compare(right.lastName) <= 0))
return true;
else
return false;
}

bool personType::operator<(const personType& right) const
{
if(firstName.compare(right.firstName) < 0)
return true;
else if((firstName.compare(right.firstName) == 0)
&& (lastName.compare(right.lastName) < 0))
return true;
else
return false;
}

bool personType::operator>=(const personType& right) const
{
if(firstName.compare(right.firstName) > 0)
return true;
else if((firstName.compare(right.firstName) == 0)
&& (lastName.compare(right.lastName) >= 0))
return true;
else
return false;
}

bool personType::operator>(const personType& right) const
{
if(firstName.compare(right.firstName) > 0)
return true;
else if((firstName.compare(right.firstName) == 0)
&& (lastName.compare(right.lastName) > 0))
return true;
else
return false;
}

istream& operator>>(istream& is, personType& pName)
{
is>>pName.firstName>>pName.lastName;
  
return is;
}

ostream& operator<<(ostream& os, const personType& pName)
{
os<<pName.firstName<<" "<<pName.lastName<<endl;
  
return os;
}

###################