/***************************************************
*程序名称:学生记录系统
*编译环境:borland c++
*程序作者:松;zhuchangsong@126.com
*完成日期:2009-12-23
*程序说明:简单的学生成绩记录系统
********************************///————include头文件————
#include
#define student_num 10//————命名空间——————
//using namespace std;
typedef struct studentInfo
{
int No;
char name[30];
int score1;
int score2;
int score3;
int total;
double average;
}ps;void input(ps *student,int index){
printf("enter No of student %d:\t",index);
scanf("%d",&(student->No));
printf("enter name of student %d:\t",index);
scanf("%s",&(student->name));
printf("enter score1 of student %d:\t",index);
scanf("%d",&(student->score1));
if((student->score1 > 100) || (student->score1 < 0))
{
printf("error: score must between 0 ~ 100!\n enter score again:");
scanf("%d",&(student->score1));
};
printf("enter score2 of student %d:\t",index);
scanf("%d",&(student->score2));
if((student->score2 > 100) || (student->score2 <0))
{
printf("error: score must between 0 ~ 100!\n enter score again:");
scanf("%d",&(student->score2));
}
printf("enter score3 of student %d:\t",index);
scanf("%d",&(student->score3));
if((student->score3 > 100) || (student->score3 <0))
{
printf("error: score must between 0 ~ 100!\n enter score again:");
scanf("%d",&(student->score3));
}
printf("please enter information of next student:\n");
}double average (ps *student){
double result = (student->score1 + student->score2 + student->score3)/3;
return result;
}int total (ps *student){
int result = (student->score1 + student->score2 + student->score3);
return result;
}
//————main主函数——————
int main( void )
{
int index;
ps student[student_num];
printf("please enter information of %d student:\n",student_num);
for(index = 0; index < student_num; index++){
input(&student[index],index);
student[index].average = average(&student[index]);
student[index].total = total(&student[index]);
}
printf(" No\tname\tscore1\tscore2\tscore3\ttotal\taverage\n");
for(index = 0; index < student_num; index++){
printf("%-5.5d\t%s\t%d\t%d\t%d\t%d\t%.2f\n",student[index].No,student[index].name,student[index].score1,student[index].score2,student[index].score3,student[index].total,student[index].average);
}
return 0;
}
/*
*笔记:
* 1、注意结构体做函数参数时用指针调用,这样可以返回多个值
* 2、注意scanf,printf函数的格式调用
* 3、注意函数的定义、声明和使用方法
*/ 以下是运行结果: **********************************本不想帮你写作业, 不过好久没写过c了,顺便帮你写个玩玩
嘻嘻,人家自己都认为这种东西太简单,只值这几分儿。学生还是自己写作业好!这最基础的东西还是自己先看看书写写看,不动手什么时间也学不会的
才给20分 还要求那么多- -!