C/C++中的结构体(下)

时间:2008-10-04 04:26:00   来源:开云网页版     [字体: ]
下面我们重点对比两个例程,进一部分析关于效率的问题。
//-------------------------------------例程1---------------------------------

#include
#include
using namespace std;

struct test
{
char name[10];
float socre;
};

void print_score(test &pn)
{
cout<}

test get_score()
{
test pn;
cin>>pn.name>>pn.socre;
return pn;
}
void main()
{
test a[2];
int num = sizeof(a)/sizeof(test);
for(int i=0;i{
a[i]=get_score();
}
cin.get();
for(int i=0;i{
print_score(a[i]);
}
cin.get();
} 来源:www.examda.com

//-------------------------------------例程2---------------------------------

#include
#include
using namespace std;

struct test
{
char name[10];
float socre;
};

void print_score(test &pn)
{
cout<}

void get_score(test &pn)
{
cin>>pn.name>>pn.socre;
}
void main()
{
test a[2];
int num = sizeof(a)/sizeof(test);
for(int i=0;i{
get_score(a[i]);
}
cin.get();
for(int i=0;i{
print_score(a[i]);
}
cin.get();
}