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]));
}
}
上一篇: C9移植rk3399 视频显示核心代码
下一篇: 蓝桥杯 16省赛 C9 四平方和(剪枝)