C语言期末总成绩的程序
C语言期末总成绩的程序
计算学生C语言期末总成绩一、 项目简介某高校现需一个能计算某班学生C语言期末总成绩的程序。现C语言成绩计算方法如下:总成绩分为两部分,一是理论课成绩,令一部分是实验课成绩。其中理论课成绩=(笔试考试成绩 - 理论课综合训练成绩扣分)*60%,实验课成绩=(机考成绩–上机扣分)*40%,理论课综合训练成绩扣分0~20。要求计算总成绩且按照成绩从高到低排列,并能提示是否挂科(60分为界,小于60为未过)。盘文件输入,有学号、笔试考试成绩、理论课综合训练成绩扣分、机考成绩、上机扣分。并盘文件输出,有学号、总成绩、挂科情况。二、运行示例输入下列五列(第一列是学号、第二列是笔试考试成绩、第三列是理论课综合训练成绩扣分、第四列是机考成绩、第五列是上机扣分)03 80 5 60 021 68 4 76 316 81 0 75 009 64 8 64 515 60 5 67 6
*/
/*这是最简单的,用结构体而非链表,传值直接传结构体而非结构体指针的程序。update version,看看有没时间去改这个程序吧
*这个程序的完工,首先特别鸣谢seed同学的大力支持,他给我解答了关于结构体传递方面的问题。Thanks。
*写这个程序加上调试加起来大概用了2个小时吧。比起去年年底做自己的高级语言程序设计课程设计要快多了。当年真是不堪回首啊。
*要看源代码的话请移步至 http://blog.csdn.net/icelights/archive/2011/06/08/6530798.aspx
*QQ空间的日志,真的不适用于发代码,缩进太蛋疼了。
*/
/*
* main.c
*
* Created on: 2011-6-6
* Author: icelights
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define TotalStu 5 /*学生总数Total student*/
struct Database
{
/*学号Student No.*/
char sn[80];
/*笔试成绩Written test score*/
double wts;
/*理论课综合训练成绩扣分
*Comprehensive training course grades possessed*/
double ctcgp;
/*机考成绩Machine examination results*/
double mer;
/*上机扣分Computer possessed*/
double cp;
/*总成绩Total score*/
double ts;
/*挂科与否Hanged division */
int hd;
};
/*输出文件*/
void output(struct Database Stu[])
{
FILE *fp;
int liv_cnt;
if((fp=fopen("d:\\StuDBA.txt","wt+"))== NULL)
{
puts("Couldn't read the file\n");
}
rewind(fp);
for(liv_cnt = 0; liv_cnt < TotalStu; liv_cnt++)
{
fprintf(fp,"%s %lf %d\n" , Stu[liv_cnt].sn,
Stu[liv_cnt].ts, Stu[liv_cnt].hd);
}
if(fclose(fp))
{
puts("Fail to close the file.\n");
}
}
/*计算成绩&判断挂科*/
void cal(struct Database Stu[])
{
int liv_cnt;
for (liv_cnt = 0; liv_cnt < TotalStu; liv_cnt++)
{
Stu[liv_cnt].ts = (Stu[liv_cnt].wts - Stu[liv_cnt].ctcgp) * 0.6
+ (Stu[liv_cnt].mer - Stu[liv_cnt].cp) * 0.4;
if (Stu[liv_cnt].ts < 60)
{
Stu[liv_cnt].hd = 0;
}
else
{
Stu[liv_cnt].hd = 1;
}
}
output(Stu);
}
/*接受用户输入*/
void input(void)
{ 论文范文http://www.chuibin.com/
struct Database Stu[TotalStu];
int liv_cnt;
puts("Please enter the Student No. Written test score");
puts("Comprehensive training course grades possessed");
puts("Machine examination results and Computer possessed");
for (liv_cnt = 0; liv_cnt < TotalStu; liv_cnt++)
{
scanf("%s%lf%lf%lf%lf",
Stu[liv_cnt].sn, &Stu[liv_cnt].wts, &Stu[liv_cnt].ctcgp,
&Stu[liv_cnt].mer, &Stu[liv_cnt].cp);
}/*end of for (liv_cnt = 0; liv_cnt < TotalStu; liv_cnt++)*/
cal(Stu);
}
/*主函数*/
int main(void)
{ input(); return 0; }