golf.h
#ifndef _GOLF_H_
#define GOLF_H_
class Golf{
const static int LEN=40;
private:
char fillname[LEN];
int handicap;
public:
Golf(const char *name,int hc);
Golf();
void sethandicap(int hc){handicap=hc;};
void show();
};
#endif
golf.cpp
#include
#include “golf.h”
#include
using namespace std;
Golf::Golf(const char *name,int hc)
{
strcpy(fillname,name);
//fillname=name;
handicap=hc;
cout<<”one golf success!”<<endl;
}
Golf::Golf()
{
cout<<”\nPlease enter the name:”;
cin.getline(fillname,LEN);
cin.sync();
cout<<”\nPlease enter the handicap:”;
cin>>handicap;
cout<<”\nEnter end”<<endl;
}
void Golf::show()
{
cout<<”\nshow on!”<<endl;
cout<<”name:”<<fillname<<” hc:”<<handicap<<endl;
cout<<”show end!”<<endl;
}
main103.cpp
#include
#include “golf.h”
using namespace std;
void main103()
{
Golf g1;//不要写成了Golf::Golf 使用文件不用域运算符
g1.show();
Golf g2(“myname1”,100);
g2.show();
cin.get();
}
—————————————————————————————————————————————————— //写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。 转载请注明出处:https://www.royalchen.com/ author:royalchen Email:royalchen@royalchen.com ———————————————————————————————————————————————————
- 本文作者: royalchen
- 本文链接: http://www.royalchen.com/2016/02/24/cprimerplus第六版课后编程题答案103/
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!