c++primer plus清單13.1,13.2,13.3
首先
#ifndef TABTENN0_H_
#define TABTENN0_H_
#include
using std::string;
class TableTennisPlayer
{
private:
string firstname;
string lastname;
bool hasTable;
public:
TableTennisPlayer(const string &fn = "none “,
const string &ln = “none”,
bool ht = false);
void Name()const;
bool HasTable()const
{
return hasTable;
};
void ResetTable(bool v)
{
hasTable = v;
};
};
#endif
其次
#include
#include"tabtenn0.h”
TableTennisPlayer::TableTennisPlayer
(const string & fn,const string &ln,bool ht):firstname(fn),
lastname(ln),hasTable(ht){}
void TableTennisPlayer::Name()const
{
std::cout << lastname << " , " << firstname;
}
最後
#include “tabtenn0.h”
#include
int main(void )
{
using std::cout;
TableTennisPlayer Player1(“Chuck”, “Blizzard”, “true”);
TableTennisPlayer Player2(“Tara”, “Boomdea”, “false”);
Player1.Name();
if (Player1.HasTable())
cout << “:has a table .\n”;
else
cout << “:has’n a table .\n”;
if (Player2.HasTable())
cout << ":has a table ";
else
cout << ":has’n a table ";
std::cin.get();
return 0;
}