简单的成绩录入系统程序及分析以及思考
这是一年前写的笔记,那个时候还没有用博客记录学习的点滴,然后就用word写了这个文档。为了防止丢失,以及自己回忆下,就贴出来吧。
本程序是在教材的基础之上找到的疑惑部分,程序是基础教材的思想自己编写的,关于使用函数模块来使程序更加的简洁且便于维护都是自己的对知识的运用实践,本程序更能体现对指针的理解,对于二维数组指针的使用是一个很好的练习。
本程序的功能是对以一个班,3个学生,4门课为例进行 实现一系列的基本操作,例如录入所有学生各科成绩、求所有学生总成绩的平均值、输出指定学生的所有科目成绩、输出成绩不及格学生的各科成绩等,分别运用函数模块实现,使得程序清晰,利于理解。
第一种是成绩录入的程序在main主函数中直接完成,第二种是将成绩录入部分用一个函数inputscore来完成,之后在主函数main当中调用此函数。
第一种程序:
#include<stdio.h>
int main()
{
/* function declaration */
void average(float *p,int n); //n represents the sum of the numble of all subjects
void search(float (*p)[4],int n); //n represents No.n student
void search_fail(float (*p)[4],int n); //n represents the numble of students
float score[3][4];
/* input the scores */
float (*point)[4]=score;
int i,j;
printf("Please input each student's scores\n");
for(i=0;i<3;i++)
{
printf("Please input No.%d student's scores:",i+1);
for(j=0;j<4;j++)
{
scanf("%f",*(point+i)+j);
}
printf("\n");
}
/* function call part */
average(*score,12); //average(score[0],12);
search(score,2); //output the scores of No.2 student
search_fail(score,3); //output the scores of students who fail to pass the examination
return 0;
}
/* function defenition */
void average(float *p,int n)
{
float *(p_end)=p+n,sum=0,aver;
for(;p<p_end;p++)
sum+=*p;
aver=sum/n;
printf("Average=%5.2f\n",aver);
}
void search(float (*p)[4],int n)
{
int i;
printf("The scores of No.%d student:\n",n);
for(i=0;i<4;i++)
printf("%5.2f ",*(*(p+n-1)+i));
printf("\n");
}
void search_fail(float (*p)[4],int n)
{
int i,j,flag;
for(i=0;i<3;i++)
{
flag=0;
for(j=0;j<4;j++)
{
if(*(*(p+i)+j)<60) flag=1;
}
if(flag==1)
{
printf("No.%d students fails, her/his scores are \n",i+1);
for(j=0;j<4;j++)
printf("%5.2f ",*(*(p+i)+j));
}
printf("\n");
}
}
第二种程序:
#include<stdio.h>
int main()
{
/* function declaration */
void inputscore(float (*p)[4],int n); //n represents the numble of students
void average(float *p,int n); //n represents the sum of the numble of all subjects
void search(float (*p)[4],int n); //n represents No.n student
void search_fail(float (*p)[4],int n); //n represents the numble of students
float score[3][4];
/* input the scores */
/* function call part */
inputscore(score,3); //input the scores of all students
average(*score,12); //average(score[0],12);
search(score,2); //output the scores of No.2 student
search_fail(score,3); //output the scores of students who fail to pass the examination
return 0;
}
/* function defenition */
void inputscore(float (*point)[4],int n)
{
int i,j;
printf("Please input each student's scores\n");
for(i=0;i<n;i++)
{
printf("Please input No.%d student's scores:",i+1);
for(j=0;j<4;j++)
{
scanf("%f",*(point+i)+j);
}
printf("\n");
}
}
void average(float *p,int n)
{
float *(p_end)=p+n,sum=0,aver;
for(;p<p_end;p++)
sum+=*p;
aver=sum/n;
printf("Average=%5.2f\n",aver);
}
void search(float (*p)[4],int n)
{
int i;
printf("The scores of No.%d student:\n",n);
for(i=0;i<4;i++)
printf("%5.2f ",*(*(p+n-1)+i));
printf("\n");
}
void search_fail(float (*p)[4],int n)
{
int i,j,flag;
for(i=0;i<3;i++)
{
flag=0;
for(j=0;j<4;j++)
{
if(*(*(p+i)+j)<60) flag=1;
}
if(flag==1)
{
printf("No.%d students fails, her/his scores are \n",i+1);
for(j=0;j<4;j++)
printf("%5.2f ",*(*(p+i)+j));
}
printf("\n");
}
}
红色字体部分为有点疑问的地方,为什么红色部分上下两条语句不能调换,这个不经意的问题花费了我不少时间,原来的程序是printf在前,int i,j;在后,但程序总是编译出错,费了好大功能才改成现在的程序那样,正常编译,链接,执行。
其次,定义行指针时,最好是在定义时候就赋值,例如:float (*p)[4]=score;就是将二维数组的序号为0的行赋值给行指针变量p;当然也可以先定义,等所有定义完成后,在赋值。注意是所有定义部分完成后在赋值,不能定义一条,接着下个语句赋值,其次在定义其他部分,这样会出现错误。例如,下面程序是会在编译时出现错误的:
#include<stdio.h>
int main()
{
/********************************************************************************************************************************
The aim of the program is to get the average of all stuents'grades, and to output the grades of all subjects of a student, and
finally to output the grades of the students whoes some grades below 60,that is he or she fails to pass the examination.
********************************************************************************************************************************/
void average(float *p,int n); //function declaration, and n represents the numble of all subjects of all students
void search(float (*p)[4],int n); //function declaration; output the No.n student's grades, and n represents NO.n
void search_fail(float (*p)[4],int n); //function declaration; output the student's grades who fails to pass the exam
float score[3][4]; //3 students and 4 subjects
float (*point)[4];
point=score;
int i,j;
printf("please input the student's scores:\n");
for(i=0;i<3;i++)
{
printf("the No.%d student's scores: ",i+1);
for(j=0;j<4;j++)
scanf("%f",*(point+i)+j);
printf("\n");
}
average(*score,12); //function call
search(score,3); //function call; output the third student's scores of each subject
search_fail(score,4); //function call
return 0;
}
void average(float *p,int n) //function definitation
{
float sum=0,aver,*p_end=p+n;
for(;p<p_end;p++)
sum+=*p;
aver=sum/n;
printf("average=%5.2f\n",aver);
}
void search(float (*p)[4],int n)
{
int i;
printf("the scores of No.%d are\n",n);
for(i=0;i<4;i++)
printf("%5.2f ",*(*(p+n-1)+i));
printf("\n");
}
void search_fail(float (*p)[4],int n)
{
int i,j,flag;
for(i=0;i<3;i++)
{
flag=0;
for(j=0;j<4;j++)
if(*(*(p+i)+j)<60)
flag=1;
if(flag==1)
{
printf("No.%d fails, his or her scores are\n",i+1);
for(j=0;j<4;j++)
printf("%5.2f ",*(*(p+i)+j));
printf("\n");
}
}
}
编译:
E:\Visual c++\exercise_1\eg-10_input system\workspace_majorization9\project_majorization9\majorization9.c(14) : error C2143: syntax error : missing ';' before 'type'
错误之处就在红色部分。下面给出正确程序:
#include<stdio.h>
int main()
{
/********************************************************************************************************************************
The aim of the program is to get the average of all stuents'grades, and to output the grades of all subjects of a student, and
finally to output the grades of the students whoes some grades below 60,that is he or she fails to pass the examination.
********************************************************************************************************************************/
void average(float *p,int n); //function declaration, and n represents the numble of all subjects of all students
void search(float (*p)[4],int n); //function declaration; output the No.n student's grades, and n represents NO.n
void search_fail(float (*p)[4],int n); //function declaration; output the student's grades who fails to pass the exam
float score[3][4]; //3 students and 4 subjects
float (*point)[4];
int i,j;
point=score;
printf("please input the student's scores:\n");
for(i=0;i<3;i++)
{
printf("the No.%d student's scores: ",i+1);
for(j=0;j<4;j++)
scanf("%f",*(point+i)+j);
printf("\n");
}
average(*score,12); //function call
search(score,3); //function call; output the third student's scores of each subject
search_fail(score,4); //function call
return 0;
}
void average(float *p,int n) //function definitation
{
float sum=0,aver,*p_end=p+n;
for(;p<p_end;p++)
sum+=*p;
aver=sum/n;
printf("average=%5.2f\n",aver);
}
void search(float (*p)[4],int n)
{
int i;
printf("the scores of No.%d are\n",n);
for(i=0;i<4;i++)
printf("%5.2f ",*(*(p+n-1)+i));
printf("\n");
}
void search_fail(float (*p)[4],int n)
{
int i,j,flag;
for(i=0;i<3;i++)
{
flag=0;
for(j=0;j<4;j++)
if(*(*(p+i)+j)<60)
flag=1;
if(flag==1)
{
printf("No.%d fails, his or her scores are\n",i+1);
for(j=0;j<4;j++)
printf("%5.2f ",*(*(p+i)+j));
printf("\n");
}
}
}
除此之外,我们可以很容易的发现,第二个程序是第一个的优化,使用函数来完成主函数需要的每一个功能,很整洁,便于阅读与维护。
总结:使用文档以及笔记记录自己对于程序的理解以及疑惑,并且不断实践演练,这是一个不错的习惯,个人一定会坚持下去。为了下一个目标积蓄力量。目标:编写一个应用程序以及各行业的管理系统软件。优化是使其更加的人性化,实用性强。
简单的成绩录入系统程序及分析以及思考相关推荐
- PHP开发一个简单的成绩录入系统
预览界面 源码: <!DOCTYPE html> <html> <head><meta charset="UTF-8"><me ...
- python简单成绩录入,python实现简单成绩录入系统
学了一个多月的python,做了一个小程序:python实现简单成绩录入系统,实验一下 menu部分 from tkinter import*#这是一个python模块,python3中都有 impo ...
- THU: 成绩录入系统的bug
各位老师,您好! 本学期课程网上录入成绩的时间马上就要截止,请注意! 1. 录入成绩系统开通时间:2010年1月8日(周五)8:30 - 1月27日(周三)16:00 2. 登录方式:在教学门户htt ...
- java录入学生信息_java实现学生成绩录入系统
本文为大家分享了java实现学生成绩录入系统,供大家参考,具体内容如下 1.学生类,包括学生的姓名和各科成绩 public class Score { public String name; publ ...
- 第十五章 文正学院成绩录入系统
这是13年上半年给文正学院做的一个成绩录入系统,只需要实现成绩录入的功能,嫁接到文正教务系统中.实现的功能如图所示. 王川 2014/5/30
- html做成绩查询,一个简单的成绩查询系统
一个简单的成绩查询系统 作者:未知 文章来源:www.jspcn.net 发布日期:2005年01月19日 作者:Javazealot 先建一个数据库(std.mdb):其中有两个表 1.pw( ...
- 利用C语言结构体实现学生成绩录入系统
利用C语言结构体实现学生成绩录入系统 ##功能介绍 密码功能嵌入于主函数中,初始密码为:123456(可根据需要修改) 输入1可以调用add函数对学生的基本信息以及成绩进行输入 输入2则调用print ...
- c语言设计体育打分程序,校运会成绩录入系统部分C语言源代码设计
部分代码实例 界面 图4-1 分数统计系统程序主界面4.2模块(或子程序)1(标识符)源码 正文宋体小四号,正文段落和标题都是1.5倍行距,正文段落首行缩进2字符 这段程序的作用是检验输入的信息是否满 ...
- win服务器系统程序原因分析
朋友的服务器有一天系统程序突然就终止了,what?什么情况?而且还发出了系统异常的邮件,赶紧去看了是什么原因, 发现是服务器的硬盘坏了,检查了一下,发现日志文件占用的内存太多了,东西太多把硬盘硬盘撑坏 ...
最新文章
- SeqGAN——对抗思想与增强学习的碰撞
- 2021年自然语言处理(NLP)算法学习路线!
- 容器编排技术 -- Kubernetes kubectl create secret tls 命令详解
- CAPS BHCA
- js检查数据类型的方法
- python 生成空白矩阵_3个用于数据科学的顶级Python库
- 凸优化第八章几何问题 作业题
- Qt官方示例Demo介绍
- 远程接入--为什么选择异速联
- 湖南大学应用经济学考研考情与难度、参考书及上岸前辈备考经验
- 运营15年的飞扬军事论坛宣布停止运营 关闭服务器
- vmware虚拟机序列号
- Adobe Premiere Pro CS6打开报错(Oxc000007b)解决办法
- 2022-2027年中国婴幼儿米粉市场竞争态势及行业投资前景预测报告
- 整理了4大类22种图表,不用担心用错统计图表,分析不出东西了
- 阴阳师真八歧大蛇最低配置攻略,蛇黑切
- 面试题:打印螺旋数字
- linux+4t分区+扩容lvm,Linux中利用LVM实现分区动态扩容
- mac如何更改iTerm的默认窗口大小
- 关于Django框架和Flask框架的区别。
热门文章
- WINCE--VS2005不能连接连线调试
- 问题1:程序员要做一辈子?
- ASP.NET存取图片到数据库
- pythonvbb转换txt_Caltech行人数据集转化VOC数据集
- e站app改内置hosts_e-Mobile安卓下载-e
- 调整html css表格位置,调整表格中的列宽(CSS / HTML)
- 软件开发人员标准薪金 人月_软件产品测试周期
- java 流换行符_【求大神】如何读取含换行符的缓冲流文件
- html怎么插入外部js,如何插入js,引用外部js,js在页面中的位置
- 路由器管理页面html,196.168.1.1登陆页面网址