golf.cpp

来自「我学习C++ Primer Plus过程中写下的课后作业的编程代码」· C++ 代码 · 共 43 行

CPP
43
字号
// golf.cpp -- contains functions called in header.cpp
#include "header.h"
#include <iostream>
#include <cstring>
using namespace std;

void setgolf (golf & g, const char * name, int hc)
{
	strcpy(g.fullname,name);
	g.handicap = hc;
}

int setgolf( golf &g)
{
	using namespace std;
	cout<<"Please input the name: "<<endl;
	cin.getline(g.fullname,Len);
	if('\0' == g.fullname[0])			//如果fullname为空字符串返回0
		return 0;
	cout<<"Please input the handicap of "<<g.fullname<<": \n";
	while( !(cin>>g.handicap) )
	{
		cin.clear();                     
		while(cin.get() != '\n')		//去掉输入流中其它的字符
			continue;
		cout<<"Please input a integer for handicap."<<endl;
	}
	while(cin.get() != '\n')			//去掉输入流中其它的字符
		continue;
	return 1;							//输入结束返回1
}

void handicap (golf & g,int hc)
{
	g.handicap = hc;
}

void showgolf (const golf &g)
{
	cout<<"name:     "<<g.fullname<<endl;
	cout<<"handicap: "<<g.handicap<<endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?