level 5
十九海生
楼主
C++ prime plus 6th edition
第九章 编程练习第一题: 如何把golf.h golf.cpp 以及main.cpp这三个文件用C4DROID来链接编译。。?![[泪]](/static/emoticons/u6cea.png)
头文件:
//golf.h -- for pe9-1.cpp
const int Len = 40;
struct golf
{
char fullname[Len];
int handicap;
};
// non-interactive version:
// function sets golf structure to provided name, handicap
// using values passed as arguments to the function
void setgolf(golf & g, const char * name, int hc);
// interactive version:
// function solicits name and handicap from user
// and sets the members of g to the values entered
// returns 1 if name is entered, 0 if name is empty string
int setgolf(golf & g);
// function resets handicap to new value
void handicap(golf & g, int hc);
// function displays contents of golf structure
void showgolf(const golf & g);
函数定义:
//golf.cpp
#include <iostream>
#include "golf.h"
#include <cstring>
void setgolf(golf & g, const char * name, int hc)
{
strcpy(g.fullname,name);
g.handicap = hc;
}
int setgolf(golf & g)
{
using namespace std;
cout << "请输入名字:";
if (cin.getline(g.fullname,40))
{
cin.get();
cout << "\n请输入难度级别:";
cin >> g.handicap;
return (1);
}
else
return (0);
}
void handicap(golf & g, int hc)
{
g.handicap = hc;
}
void showgolf(const golf & g)
{
using namespace std;
cout << "name: " << g.fullname << endl;
cout << "handicap: " << g.handicap << endl;
}
一个main函数:
//main.cpp
#include <iostream>
#include "golf.h"
int main()
{
using namespace std;
golf ann;
setgolf(ann, "Birdfree", 24);
showgolf(ann);
golf a[5];
for (int i = 0;i < 5; i++)
{
setgolf(a[i]);
}
for (auto & e : a)
showgolf(e);
return 0;
}
2014年09月16日 12点09分
1
第九章 编程练习第一题: 如何把golf.h golf.cpp 以及main.cpp这三个文件用C4DROID来链接编译。。?
头文件:
//golf.h -- for pe9-1.cpp
const int Len = 40;
struct golf
{
char fullname[Len];
int handicap;
};
// non-interactive version:
// function sets golf structure to provided name, handicap
// using values passed as arguments to the function
void setgolf(golf & g, const char * name, int hc);
// interactive version:
// function solicits name and handicap from user
// and sets the members of g to the values entered
// returns 1 if name is entered, 0 if name is empty string
int setgolf(golf & g);
// function resets handicap to new value
void handicap(golf & g, int hc);
// function displays contents of golf structure
void showgolf(const golf & g);
函数定义:
//golf.cpp
#include <iostream>
#include "golf.h"
#include <cstring>
void setgolf(golf & g, const char * name, int hc)
{
strcpy(g.fullname,name);
g.handicap = hc;
}
int setgolf(golf & g)
{
using namespace std;
cout << "请输入名字:";
if (cin.getline(g.fullname,40))
{
cin.get();
cout << "\n请输入难度级别:";
cin >> g.handicap;
return (1);
}
else
return (0);
}
void handicap(golf & g, int hc)
{
g.handicap = hc;
}
void showgolf(const golf & g)
{
using namespace std;
cout << "name: " << g.fullname << endl;
cout << "handicap: " << g.handicap << endl;
}
一个main函数:
//main.cpp
#include <iostream>
#include "golf.h"
int main()
{
using namespace std;
golf ann;
setgolf(ann, "Birdfree", 24);
showgolf(ann);
golf a[5];
for (int i = 0;i < 5; i++)
{
setgolf(a[i]);
}
for (auto & e : a)
showgolf(e);
return 0;
}

