//golf.h
#ifndef GOLF_H_
#define GOLF_H_
const int length=20;
struct golf
{
char fullname[length];
int handicap;
};
void setgolf(golf &,const char*,int);
int setgolf(golf &);
void handicap(golf &,int);
void showgolf(const golf &);
#endif
//golf.cpp
#include
#include
#include"golf.h"
static int i;
void setgolf(golf & g,const char* name,int hc)
{
for(i=0;i<strlen(name);i++)
g.fullname[i]=name[i];
g.handicap=hc;
}
int setgolf(golf & g)
{
std::cout<<"Enter your name:";
std::cin.getline(g.fullname,length);
if(g.fullname[0])
{
std::cout<<"Enter your num:";
if(std::cin>>g.handicap)
{
std::cin.get();
return 1;
}
else
return 0;
}
else
return 0;
}
void handicap(golf & g,int hc)
{
g.handicap=hc;
}
void showgolf(const golf & g)
{
using namespace std;
cout<<"FULLNAME ";
for(i=0;i<strlen(g.fullname);i++)
cout<<g.fullname[i];
cout<<endl<<"HANDICAP "<<g.handicap<<endl;
}
//execute_golf
#include"golf.h"
const int size=10;
/*void setgolf(golf &,const char*,int);
int setgolf(golf &);
void handicap(golf &,int);
void showgolf(const golf &);*/
int main()
{
int i;
golf pc=new golf[size];
for(i = 0;i < size;i++)
{
if(!setgolf((pc+i)))
break;
}
for(int j=0;j<i;j++)
showgolf(*(pc+j));
}