C语言【精选】-多文件模块的学生信息库系统(大程序构成)

问题描述:大程序构成-多文件模块的学生信息库系统

源代码:

student.h:

#include<stdio.h>
#include<string.h>
#define MaxSize 50
struct student{/*学生信息结构定义*/
    int num;
    char name[10];
    int computer,english,math;
    double average;
}; 

student_system:

#include "student.h"
#include "input_output.c"
#include "aver_sort.c"
#include "modify.c"
int Count=0;/*全局变量,记录当前学生总数*/
int main(void)
{
    struct student students[MaxSize];/*定义学生信息结构数组*/
    new_student(students);/*输入学生信息结构数组*/
    average(students);/*计算每个学生的平均成绩*/

    printf("显示输入的学生信息结构数组:\n");
    output_student(students);/*显示输入的学生信息结构数组*/
    sort(students);/*按学生的平均成绩排序*/
    
    printf("显示排序后的学生信息结构数组:\n");
    output_student(students);/*显示排序后的结构数组*/
    modify(students);/*修改指定输入的学生信息*/

    printf("显示修改后的学生信息结构数组:\n");
    output_student(students);/*显示修改后的结构数组*/
    return 0; 
 } 

input_output.c:

extern Count;       /*其他文件模块声明的全局变量,需要声明为外部变量*/

/*新建学生信息*/
void new_student(struct student students[])
{
    int i,n;
    if(Count==MaxSize){
        printf("The array is full!\n");
        return;
    }
    printf("Input the Number of Students:");
    scanf("%d",&n);
    for(i=0;i<n;i++){
        printf("Input the No.%d student's num:",i+1);
        scanf("%d",&students[i].num);
        printf("Input the No.%d student's name:",i+1);
        scanf("%s",students[i].name);
        printf("Input the No.%d student's math score:",i+1);
        scanf("%d",&students[i].math);
        printf("Input the No.%d student's english score:",i+1);
        scanf("%d",&students[i].english);
        printf("Input the No.%d student's computer score:",i+1);
        scanf("%d",&students[i].computer);
        Count++;
    }
 } 
 
 /*输出学生信息*/
 void output_student(struct student students[]) 
 {
    int i;
    if(Count==0){
        printf("Count of students is zero!\n");
        return;
     }
    printf("num\tname\tmath\tenglish\tcomputer\taverage\n ");
    for(i=0;i<=Count;i++){
        printf("%d\t",students[i].num);
        printf("%s\t",students[i].name);
        printf("%d\t",students[i].math);
        printf("%d\t",students[i].english);
        printf("%d\t",students[i].computer);
        printf("%.2f\t\n",students[i].average);
    }
 }

aver_sort.c:

extern Count;       /*其他文件模块声明的全局变量,需要声明为外部变量*/
/*计算个人平均成绩的函数*/
void average(struct student s[]){
    int i;
    for(i=0;i<Count;i++)
        s[i].average=(s[i].math+s[i].english+s[i].computer)/3.0;
} 

/*平均成绩排序的函数*/
void sort(struct student s[])
{
    struct student temp;
    int i,index,j;
    for(i=0;i<Count-1;++i){
        index=i;
        for(j=i+1;j<Count;j++)
            if(s[j].average>s[index].average);
            index=j;
        temp=s[index];
        s[index]=s[i];
        s[i]=temp;
        
    }       
} 

modify.c:

extern Count;       /*其他文件模块声明的全局变量,需要声明为外部变量*/
void modify(struct student*p)
{
    int num,course,score,i;
    printf("Input the number of the students to be update:");
    scanf("%d",&num);
    printf("Choice the course:1-->math;2-->english;3-->computer:");
    scanf("%d",&course);
    printf("Input the new score:");
    scanf("%d",&score);
    
    for(i=0;i<Count;i++,p++)
            if(p->num==num) /*按学号查找*/
            break;
        if(i<Count)     /*找到,修改成绩*/
            switch(course){
                case 1: p-> math=score;break;
                case 2: p-> english=score;break;
                case 3: p-> computer=score;break;
            }
        
}

/*查询学生信息的函数*/
void search_student(struct student students[],int num)
{
    int i,flag=0;
    if(Count==0){
        printf("Count of students is zero!\n");
        return;
    }
    for(i=0;i<Count;i++)
        if(students[i].num==num){
            flag=1;
            break;
        }
    if(flag){
        printf("num\tname\tmath\tenglish\tcomputer\taverage\n ");
        printf("%d \t %s \t %d \t %d \t %d \t %d \t\n",students[i].num,students[i].name,students[i].math,students[i].english,students[i].computer,students[i].average);
    }
    else
    {
        printf("Not found!\n");
     } 
 } 

运行结果:

文件组成
运行结果

程序参数:

  • 输出大小: 154.7060546875 KiB
  • 编译时间: 0.31s
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,724评论 0 3
  • 面向对象主要针对面向过程。 面向过程的基本单元是函数。 什么是对象:EVERYTHING IS OBJECT(万物...
    sinpi阅读 1,088评论 0 4
  • 在日常的C++编程中,使用频率最多的应该是Unicode文件的读写,今天我们用VS2015来制作个属于自己的简单类...
    天花板阅读 1,116评论 0 3
  • 开始喜欢看日剧也是发现,片中的思想都很值得去研究,也不会过多的参杂感情因素来影响心情,而且总是一股正能量袭...
    不是本咩阅读 916评论 0 8
  • 我们有多少人怀念青春时代,不知道有多少奇闻轶事不知道有多少辛酸泪,可是最初的我们还是单纯还是率真,这样才会遇见了一...
    我爱学习_bb12阅读 197评论 0 0