典型案例心得体会:谁能帮我设计一个简单的V.C++6.0程序?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/26 05:39:51
这个程序的内容是:

编写一个程序实现以下功能:
定义一个函数input用于输入n个学生的三门课程成绩;
定义一个函数sum用于求每个学生的总成绩;
定义一个函数average用于求各门成绩的平均成绩并输出;
定义一个函数print用于输出每个学生的学号,三门成绩和总成绩。
在主函数中输入学生人数然后依次调用这些函数。

这个程序的要求是:
* 要用V.C++6.0 操作软件来编辑。

// zd_8.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#define N 5 //定义有几个学生

int student[N];
int point_sum=0;

void input()
{
for(int i=0;i<N;i++)
{
printf("input student%d's point:\n",i+1);
scanf("%d",&student[i]);
}
}
void sum()
{
for(int i=0;i<N;i++)
{
point_sum+=student[i];
}
}
void average()
{
int avg=point_sum/N;

printf("the average of %d student's point is %d:\n",N,avg);
}
void print()
{
for(int i=0;i<N;i++)
{
printf("student%d's point is %d\n",i+1,student[i]);
}
printf("the total point is %d:\n",point_sum);
}

int main(int argc, char* argv[])
{

input();
sum();
average();
print();

return 0;
}

输出:
input student1's point:
5
input student2's point:
6
input student3's point:
4
input student4's point:
7
input student5's point:
6
the average of 5 student's point is 5:
student1's point is 5
student2's point is 6
student3's point is 4
student4's point is 7
student5's point is 6
the total point is 28:
Press any key to continue

你可以定义一个二维数组,然后用循环来实现。