Hi,
I'm converting this golf program into a prog using a class. I want to use the old structure in the class but am not sure how to use the structure or functions of the class. Here is what I have.
Second file:Code://golff.h for prblm 2 pg 417 c++ primer plus class Score // golf score class { private: const int Len=40; struct golf { char fullname[Len]; int handicap; }; public: void score(golf & g, const char *name, int hc); int setgolf(golf & g); void setgolf(golf & g, const char *name, int hc); void handicap(golf & g, int hc); void showgolf(const golf & g); };
Code:#include <iostream> #include "golfh.cpp" using namespace std; void Score::Score(golf & g, const char *name, int hc)// constructor { strcpy(g.fullname,name); g.handicap=hc; } int Score::setgolf(golf & g) { cout << "Enter golfers name:"; cin.get(g.fullname,Len); if (strlen(g.fullname)==0) { return 0; } else { cout << "Enter player's handicap:"; cin >> g.handicap; cin.get(); return 1; } } void Score::handicap(golf & g, int hc) { g.handicap=hc; } void Score::showgolf(const golf & g) { cout << "Player's name:"<<g.fullname<<endl; cout << "Handicap:"<<g.handicap<<endl; cout << endl; }



LinkBack URL
About LinkBacks


