Chinaunix首页 | 论坛 | 博客
  • 博客访问: 441842
  • 博文数量: 142
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2005-06-03 21:00
文章分类

全部博文(142)

文章存档

2011年(3)

2010年(32)

2009年(107)

我的朋友

分类: C/C++

2009-10-28 19:23:28

【程序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
 
 
阅读(719) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~