阅读背景:

C++ Primer Plus第六版 第九章 编程练习答案

来源:互联网 

//第一题
//golf.h
const int Len = 40;
struct golf{
	char fullname[Len];
	int handicap;
};
void setgolf(golf &g, const char *name, int hc);
int setgolf(golf &g);
void handicap(golf &g, int hc);
void showgolf(const golf &g);


//golf.cpp
#include <iostream>
#include <cstring>
#include "golf.h"
void setgolf(golf &g, const char *name, int hc)
{
	strcpy(g.fullname, name);
	g.handicap = hc;
}
int setgolf(golf &g)
{
	std::cin.getline(g.fullname, Len);
	std::cin >> g.handicap;
	return g.fullname == NULL ? 0 : 1;
}
void handicap(golf &g, int hc)
{
	g.handicap = hc;
}
void showgolf(const golf &g)
{
	std::cout << g.fullname << std::endl << g.handicap << std::endl;
}


//main.cpp
#include <iostream>
#include "golf.h"
int main()
{
	golf g;
	setgolf(g);
	showgolf(g);
	setgolf(g, "Tree", 6666);
	showgolf(g);
	handicap(g, 2333);
	showgolf(g);
	return 0;
} //第一题
//golf.h
const int Len = 40;
struct go



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: