【程序71】
题目:编写input()和output()函数输入,输出5个学生的数据记录。
1.程序分析:
2.程序源代码:
// example71.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#define N 5
struct student {
char num[6];
char name[8];
int score;
} stu[N];
//
void input(struct student stu[])
{
int iStudent;
for(iStudent = 0; iStudent < N; iStudent++) {
printf("\nplease input the %d student information\n",iStudent+1);
printf("num: ");
scanf("%s", stu[iStudent].num);
printf("name: ");
scanf("%s", stu[iStudent].name);
printf("score: ");
scanf("%d",&stu[iStudent].score);
}
printf("\n");
}
void output(struct student stu[])
{
int iStudent;
printf("\nNo. Name Sco\n");
for(iStudent = 0; iStudent < N; iStudent++) {
printf("%-10s%-10s%-10d\n",stu[iStudent].num,stu[iStudent].name,stu[iStudent].score);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
struct student stu[5];
input(stu);
output(stu);
getchar();
getchar();
return 0;
}
result in VS2005:
please input the 1 student information
num: 11111
name: aaaaaaa
score: 99
please input the 2 student information
num: 22222
name: bbbbbbb
score: 90
please input the 3 student information
num: 33333
name: ccccccc
score: 88
please input the 4 student information
num: 44444
name: ddddddd
score: 80
please input the 5 student information
num: 55555
name: eeeeeee
score: 99
No. Name Sco
11111 aaaaaaa 99
22222 bbbbbbb 90
33333 ccccccc 88
44444 ddddddd 80
55555 eeeeeee 99
阅读(747) | 评论(0) | 转发(0) |