#ifndef GOLF_H_
#define GOLF_H_
const int len = 40;
struct golf
{
<span style="white-space:pre"> </span>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);
#endif
#include<iostream>
#include"golf.h"
//第九章
int main()
{
using namespace std;
golf team[3];
int i;
for (i = 0; i < 3; i++)
{
if (setgolf(team[i]) == 0)
break;
}
for (int j = 0; j < i; j++)
{
showgolf(team[j]);
}
golf ann;
setgolf(ann, "ann bridfree", 5);
showgolf(ann);
handicap(ann, 3);
showgolf(ann);
system("pause");
return 0;
}
#include<iostream>
#include<stdlib.h>
#include<string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
void strcount(string str);
int main()
{
string input;
cout << "Enter line:";
getline(cin, input);
while (input != "")
{
strcount(input);
cout << "Enter next line:";
getline(cin, input);
}
cout << "Bye!"<<endl;
}
void strcount(string str)
{
static int total = 0;
int count = 0;
cout << "\"" << str << "\"contains ";
count=str.size();
total += count;
cout << count << " characters, ";
cout << total << " characters total\n";
}
#include<iostream>
#include<stdlib.h>
#include<cstring>
struct chaff
{
char dross[20];
int slag;
};
const int BUF = 60;
char buf[BUF];
int main()
{
using namespace std;
chaff *pc = new(buf)chaff[2];
strcpy_s(pc[0].dross, "fpoo");
pc[0].slag = 1;
strcpy_s(pc[1].dross, "mmpoo");
pc[1].slag = 2;
for (int i = 0; i < 2; i++)
{
cout << pc[i].dross << ":" << pc[i].slag << endl;
}
system("pause");
return 0;
}
</pre><pre name="code" class="cpp">namespace SALES
{
const int QUARTERS = 4;
struct Sales
{
double sales[QUARTERS];
double average;
double max;
double min;
};
void setSales(Sales &s, const double ar[], int n);
void setSales(Sales &s);
void showSales(const Sales &s);
}
#include<iostream>
#include<stdlib.h>
#include<cstring>
#include"golf.h"
int main()
{
using namespace SALES;
Sales s1;
double salesList[] = { 11.2, 11.3, 11.4, 11.5, 11.6 };
setSales(s1, salesList, sizeof(salesList) / sizeof(double));
showSales(s1);
Sales s2;
setSales(s2);
showSales(s2);
system("pause");
return 0;
}