Difference: CodeClass (2 vs. 3)

Revision 32018-03-01 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Classes

Added:
>
>

Candidate Class

%CODE{"c++"}% #include 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 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 h("Bernie Sanders","Democrat",46); Candidate j("Trump","Republican",42); Candidate g("Gary Johnson","Libertarian",8);

h.print(); j.print(); g.print(); cout << endl; h.setPolls(12); j.setPolls(11); g.setPolls(77);

h.print(); j.print(); g.print();

}

 
Added:
>
>
%ENDCODE%
 

Class with a Member Function

%CODE{"c++"}%
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback