C++primer plus第六版课后编程题答案10.3

来源:互联网 发布:淘宝的促销活动有哪些 编辑:程序博客网 时间:2024/05/02 00:44

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 <iostream>#include "golf.h"#include <cctype>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 <iostream>#include "golf.h"using namespace std;void main103(){Golf g1;//不要写成了Golf::Golf 使用文件不用域运算符g1.show();Golf g2("myname1",100);g2.show();cin.get();}


1 0
原创粉丝点击