欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

cpp primer homework c9

程序员文章站 2022-07-13 23:46:24
...
//c9_01
//header
const int Len =10;
struct golf
{
    char fullname[Len];
    int handicap;
};
void setgolf(golf &g, const char*name,int hc);
void setgolf(golf&g);
void handicap(golf &g,int hc);
void showgolf(const golf &g);
//cpp1
#include<iostream>
#include<cstring>
#include"golf.h"
void setgolf(golf &g, const char*name,int hc)
{
    strcpy(g.fullname,name);
    g.handicap=hc;
}
void setgolf(golf&g)
{
    using namespace std;
    cout<<"Please input name:"<<endl;
    cin.get(g.fullname,Len);
    cin.get();
    cout<<"Please input handicap:"<<endl;
    cin>>g.handicap;
    cin.get();
/*
        return 1 ;
    else
        return 0;*/
}
void handicap(golf &g,int hc)
{
    std::cout<<"enter a new handicap:"<<std::endl;
    std::cin>>hc;
    g.handicap=hc;
}
void showgolf(const golf&g)
{
    using std::cout;
    cout<<"#name:  "<<  g.fullname<<std::endl<<"#handicap:"<<g.handicap<<std::endl;
}
//main_func
#include<iostream>
#include<cstring>
#include"golf.h"
int  main(void)
{
    using namespace std;
    golf data[30];
    int count=0;
    for(int i = 0;i<30;i++)
    {
        //static int count=1;
        setgolf(data[i]);
        count++;
      if(strcmp(data[i].fullname,"")==0)
         break;
         //count++;
    }
    std::cout<<"******************************************"<<std::endl;
for(int i=0;i<count-1;i++)

    {
        cout<<"#"<<i+1<<endl;
    showgolf((data[i]));
}
}