Tags:
create new tag
view all tags

Candidate Example

#include <string>
using namespace std;

class Candidate
{
    private:
        string name;
        string party;
        int polls;
    public:
        Candidate();
        Candidate(string aName, string aParty, int aPoll);
        void setPolls(int polls);

        string getName();
        string getParty();
        int getPolls();
        void print();
};

//#include "candidate.h"
#include <iostream>
using namespace std;

Candidate :: Candidate() {
    name = "";
    party = "";
    polls = 0;
}
Candidate :: Candidate(string aName, string aParty, int aPoll) {
    name = aName;
    party = aParty;
    polls = aPoll;
}

string Candidate :: getName() {
    return name;
}
int Candidate :: getPolls() {
    return polls;
}
void Candidate :: setPolls(int pollNum) {
    polls = pollNum;
}
void Candidate :: print(){
    cout << "Name : " << name << ", ";
    cout << "Party : " << party << ", ";
    cout << "Polls : " << polls << "%" << endl;
}

int main() {
    Candidate s("Bernie Sanders","Democrat",46);
    Candidate t("Donald Trump","Republican",42);
    Candidate j("Gary Johnson","Libertarian",8);

    s.print();
    t.print();
    j.print();
    
    cout << endl;
    s.setPolls(12);
    t.setPolls(11);
    j.setPolls(77);

    s.print();
    t.print();
    j.print();

}
Topic revision: r1 - 2018-03-22 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback