学生管理系统的几种实现方法(一位数组,二维数组,指针,结构体)

一位数组:

#include <stdio.h>
#include<string.h>
#define N 5
void luru(float s[],int n);
void shuchu(float s[],int n);
void chaxun(float s[],int n);
void paixu(float a[],int n);
int mimayanzheng();
void caidan();

 

 


void main(){
    int x,y,k;
    float a[N];
    x=mimayanzheng();
    if(x==1){
        caidan();
        for(k=0;k!=5;k=y){
            printf("请输入选择:");
            scanf("%d",&y);
            switch(y){
                case 1 :luru(a,N);break;
                case 2 :shuchu(a,N);break;
                case 3 :chaxun(a,N);break;
                case 4 :paixu(a,N);break;
                case 5 :break;
            }
        }
    }

   

}
int mimayanzheng(){
    int i,flat;
    char m[7]="abc123",x[10];
    printf("请输入密码:");
    for(i=0;i<3;i++){
        flat=0;
        scanf("%s",&x);
        if(!strcmp(m,x)){
            flat=1;
            break;
        }
        else if(i<2)
            printf("请重新输入密码:");
    }
    return flat;
}

void caidan(){
    printf("+===============================+\n");
    printf("+====学=生=成=绩=管=理=系=统====+\n");
    printf("+===============================+\n");
    printf("+===========1、  录入===========+\n");
    printf("+===========2、  输出===========+\n");
    printf("+===========3、  查询===========+\n");
    printf("+===========4、  排序===========+\n");
    printf("+===========5、  退出===========+\n");
    printf("+===============================+\n");
}


void luru(float s[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("请输入第%d个同学的成绩:",i+1);
        scanf("%f",&s[i]);
    }
}

void shuchu(float s[],int n){
    int i;
    for(i=0;i<n;i++)
    printf("第%d个的同学成绩是:%f \n",i+1,s[i]);
}

void chaxun(float s[],int n){
    int i,flat;
    float x;
    printf("请输入要查询的成绩:");
    scanf("%f",&x);
    for(i=0,flat=0;i<n;i++)
        if(x==s[i])
            flat =1;
    if(flat==1)
        for(i=0;i<N;i++){
            if(s[i]==x)
                printf("有此同学成绩,为第%d个同学的成绩\n",i+1);
            continue;
        }
    else
        printf("没有此同学成绩\n");
}

void paixu(float a[],int n){
    int i,j,k;
    float temp;
    for(j=0;j<n-1;j++){
        k=j;
        for(i=j+1;i<n;i++)
            if(a[i]<a[k])
                k=i;
            if(k!=j){
            temp=a[k];
            a[k]=a[j];
            a[j]=temp;
            }
    }
    printf("从小到大的排序是:");
    for(i=0;i<N;i++)
        printf("%f ",a[i]);
    printf("\n");
}
 
 
 
 
 
二维数组:

#include <stdio.h>
#include<string.h>
#define a 2
#define b 3

void luru(float s[][b]);
void shuchu(float s[][b]);
void chaxun(float s[][b]);
void paixu(float m[][b]);
int mimayanzheng();
void caidan();

 

 


void main(){
    int x,y,k;
    float z[a][b];
    x=mimayanzheng();
    if(x==1){
        caidan();
        for(k=0;k!=5;k=y){
            printf("请输入选择:");
            scanf("%d",&y);
            switch(y){
                case 1 :luru(z);break;
                case 2 :shuchu(z);break;
                case 3 :chaxun(z);break;
                case 4 :paixu(z);break;
                case 5 :break;
            }
        }
    }

   

}
int mimayanzheng(){
    int i,flat;
    char m[7]="abc123",x[10];
    printf("请输入密码:");
    for(i=0;i<3;i++){
        flat=0;
        scanf("%s",&x);
        if(!strcmp(m,x)){
            flat=1;
            break;
        }
        else if(i<2)
            printf("请重新输入密码:");
    }
    return flat;
}

void caidan(){
    printf("+===============================+\n");
    printf("+====学=生=成=绩=管=理=系=统====+\n");
    printf("+===============================+\n");
    printf("+===========1、  录入===========+\n");
    printf("+===========2、  输出===========+\n");
    printf("+===========3、  查询===========+\n");
    printf("+===========4、  排序===========+\n");
    printf("+===========5、  退出===========+\n");
    printf("+===============================+\n");
}


void luru(float s[a][b]){
    int i,j;
    for(j=0;j<a;j++){
        for(i=0;i<b;i++){
            printf("请输入第%d个同学的第%d科成绩:",j+1,i+1);
            scanf("%f",&s[j][i]);
        }
    }
}

void shuchu(float s[a][b]){
    int i,j;
    for(j=0;j<a;j++){
        for(i=0;i<b;i++){
            printf("第%d个同学的第%d科成绩是%f:\n",j+1,i+1,s[j][i]);
        }
    }
}

void chaxun(float s[a][b]){
    int i,j,flat;
    float x;
    printf("请输入要查询的成绩:");
    scanf("%f",&x);
    for(j=0;j<a;j++){
        for(i=0,flat=0;i<b;i++)
            if(x==s[j][i])
                flat =1;
    if(flat==1){
        for(j=0;j<a;j++){
            for(i=0;i<b;i++){
                if(s[j][i]==x)
                    printf("有此同学成绩,为第%d个同学的第%d科成绩\n",j+1,i+1);
            continue;
        }
        }
    }
    else
        printf("没有此同学成绩\n");
    }
}

void paixu(float m[a][b]){
    int i,j,k,p;
    float temp;
    for(p=0;p<a;p++){
            for(j=0;j<b-1;j++){
                k=j;
                for(i=j+1;i<b;i++)
                    if(m[p][i]<m[p][k])
                        k=i;
                    if(k!=j){
                        temp=m[p][k];
                        m[p][k]=m[p][j];
                        m[p][j]=temp;
                    }
            }
    }
    printf("从小到大的排序是:\n");
    for(j=0;j<a;j++){
        for(i=0;i<b;i++)
            printf("%f ",m[j][i]);
        printf("\n");
    }
    printf("\n");
}
 

 

 

指针:

#include <stdio.h>
#include<string.h>
#define N 5
void luru(double *s,int n);
void shuchu(double *s,int n);
void chaxun(double *s,int n);
void paixu(double *a,int n);
int mimayanzheng();
void caidan();

 

 


void main(){
    int x,y,k;
    double b[N];
    double *a;
    a=b;
    x=mimayanzheng();
    if(x==1){
        caidan();
        for(k=0;k!=5;k=y){
            printf("请输入选择:");
            scanf("%d",&y);
            switch(y){
                case 1 :luru(a,N);break;
                case 2 :shuchu(a,N);break;
                case 3 :chaxun(a,N);break;
                case 4 :paixu(a,N);break;
                case 5 :break;
            }
        }
    }

   

}
int mimayanzheng(){
    int i,flat;
    char m[7]="abc123",x[10];
    printf("请输入密码:");
    for(i=0;i<3;i++){
        flat=0;
        scanf("%s",&x);
        if(!strcmp(m,x)){
            flat=1;
            break;
        }
        else if(i<2)
            printf("请重新输入密码:");
    }
    return flat;
}

void caidan(){
    printf("+===============================+\n");
    printf("+====学=生=成=绩=管=理=系=统====+\n");
    printf("+===============================+\n");
    printf("+===========1、  录入===========+\n");
    printf("+===========2、  输出===========+\n");
    printf("+===========3、  查询===========+\n");
    printf("+===========4、  排序===========+\n");
    printf("+===========5、  退出===========+\n");
    printf("+===============================+\n");
}


void luru(double * s,int n){
    int i;
    double k;
    for(i=0;i<n;i++){
        printf("请输入第%d个同学的成绩:",i+1);
        scanf("%lf",&k);
        * (s+i)=k;
    }
}

void shuchu(double *s,int n){
    int i;
    for(i=0;i<n;i++)
    printf("第%d个的同学成绩是:%lf \n",i+1,*(s+i));
}

void chaxun(double *s,int n){
    int i,flat;
    double x;
    printf("请输入要查询的成绩:");
    scanf("%f",&x);
    for(i=0,flat=0;i<n;i++)
        if(x==*(s+i))
            flat =1;
    if(flat==1)
        for(i=0;i<n;i++){
            if(*(s+i)==x)
                printf("有此同学成绩,为第%d个同学的成绩\n",i+1);
            continue;
        }
    else
        printf("没有此同学成绩\n");
}

void paixu(double *a,int n){
    int i,j,k;
    double temp;
    for(j=0;j<n-1;j++){
        k=j;
        for(i=j+1;i<n;i++)
            if(*(a+i)<*(a+k))
                k=i;
            if(k!=j){
            temp=*(a+k);
            *(a+k)=*(a+j);
            *(a+j)=temp;
            }
    }
    printf("从小到大的排序是:");
    for(i=0;i<N;i++)
        printf("%f ",*(a+i));
    printf("\n");
}
 
 
 
 
 
 
 
 
 
 
结构体:

#include <stdio.h>
#include<string.h>
#define N 5
void luru(struct xitong student[],int n);
void shuchu(struct xitong student[],int n);
void chaxun(struct xitong student[],int n);
void paixu(struct xitong student[],int n);
int mimayanzheng();
void caidan();
struct xitong{
    char xingming[10];
    int xuehao;
    float yuwen;
    float shuxue;
    float yingyu;
};

 

 


void main(){
    int x,y,k;
    struct xitong student [N];
    x=mimayanzheng();
    if(x==1){
        caidan();
        for(k=0;k!=5;k=y){
            printf("请输入选择:");
            scanf("%d",&y);
            switch(y){
                case 1 :luru(student,N);break;
                case 2 :shuchu(student,N);break;
                case 3 :chaxun(student,N);break;
                //case 4 :paixu(student,N);break;
                case 5 :break;
            }
        }
    }

   

}
int mimayanzheng(){
    int i,flat;
    char m[7]="abc123",x[10];
    printf("请输入密码:");
    for(i=0;i<3;i++){
        flat=0;
        scanf("%s",&x);
        if(!strcmp(m,x)){
            flat=1;
            break;
        }
        else if(i<2)
            printf("请重新输入密码:");
    }
    return flat;
}

void caidan(){
    printf("+===============================+\n");
    printf("+====学=生=成=绩=管=理=系=统====+\n");
    printf("+===============================+\n");
    printf("+===========1、  录入===========+\n");
    printf("+===========2、  输出===========+\n");
    printf("+===========3、  查询===========+\n");
    printf("+===========4、  排序===========+\n");
    printf("+===========5、  退出===========+\n");
    printf("+===============================+\n");
}


void luru(struct xitong student[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("请输入第%d个同学的信息(姓名,学号,语文,数学,英语):",i+1);
        scanf("%s %d %f %f %f",&student[i].xingming,&student[i].xuehao,&student[i].yuwen,&student[i].shuxue,&student[i].yingyu);
    }
}

void shuchu(struct xitong student[],int n){
    int i;
    for(i=0;i<n;i++)
    printf("第%d个的同学信息是: \n姓名:%s\n学号:%d\n语文:%f\n数学:%f\n英语:%f\n",i+1,student[i].xingming,student[i].xuehao,student[i].yuwen,student[i].shuxue,student[i].yingyu);
}

void chaxun(struct xitong student[],int n){
    int i,flat;
    float x;
    printf("请输入要查询的成绩:");
    scanf("%f",&x);
    for(i=0,flat=0;i<n;i++)
        if(x==student[i].yuwen||x==student[i].shuxue||x==student[i].yingyu)
            flat =1;
    if(flat==1)
        for(i=0;i<N;i++){
            if(x==student[i].yuwen||x==student[i].shuxue||x==student[i].yingyu)
                printf("有此同学成绩,为%s同学的成绩\n",student[i].xingming);
            continue;
        }
    else
        printf("没有此同学成绩\n");
}

你可能感兴趣的:(学生管理系统的几种实现方法(一位数组,二维数组,指针,结构体))