#include<iostream>
#include<cctype>
using namespace std;
const int SIZE = 10;
struct GOLF
{
char name[SIZE];
float grade;
};
void init_array(GOLF *str);
void print_array_name(GOLF str);
void print_array_grade(GOLF str);
void average(GOLF *str, int number);
int main(void)
{
GOLF *p = new GOLF[SIZE];
char ch;
int i = 0;
int m = 0;
cout << "please a char Y/y continue and now you can input " << SIZE-i << " data:";
while(cin>>ch && ('Y' == ch || ch =='y')&&i < SIZE)
{
cout << "Enter a name and the grade:";
init_array(&p[i]);
++i;
cout <<"You can input " << SIZE - i << " data:" << "Continue: (Y or n)" ;
}
m = i;
average(p, m);
m = 0;
while (m < i)
{
print_array_name(p[m]);
++m;
}
cout << endl;
m = 0;
while (m < i)
{
print_array_grade(p[m]);
++m;
}
delete[] p;
cin.get();
cin.get();
return 0;
}
void init_array(GOLF *str)
{
cin >> str->name >> str->grade;
}
void print_array_name(GOLF str)
{
cout << str.name << "\t";
}
void print_array_grade(GOLF str)
{
cout << str.grade << "\t";
}
void average(GOLF *str, int number)
{
float num = 0;
for (int i = 0;i < number;++i)
num += str[i].grade;
cout << number << " number" << endl;
cout << "avarage = " << num / number << endl;
}