源代码如下
此处为头文件golf.h
//headfile golf
#ifndef golf
const int len=40;
struct golf
{
char fullname[len];
int handicap;
};
void setgolf(golf & g,char *name,int hc);
int setgolf(golf & g);
void handicap(golf & g,int hc);
void showgolf(const golf &g);
#endif
函数的声明 fu.cpp
//declare the functions
#include
#include
#include"golf.h"
void setgolf(golf & g,const char *name,int hc)
{
name=g.fullname;
g.handicap=hc;
}
int setgolf(golf & g)
{
std::cin>>g.fullname;
std::cin>>g.handicap;
std::string c;
c=g.fullname;
if(c.empty())
return 0;
else
return 1;
}
void handicap(golf & g,int hc)
{
g.handicap=hc;
}
void showgolf(const golf &g)
{
std::cout<
}
//主函数部分:gl.cpp
#include
#include"golf.h"
int main()
{
golf ann[2];
setgolf(ann[0],"dazhoang",14);
int go=setgolf(ann[1]);
handicap(ann[0],14);
std::cout<<go;
showgolf(ann[0]);
std::cout<<std::endl;
showgolf(ann[1]);
system("pause");
return 0;
}