當前位置:編程學習大全網 - 編程語言 - 用C語言編寫學生成績管理系統(簡單的,不用像計院壹樣專業) 懸賞100哦

用C語言編寫學生成績管理系統(簡單的,不用像計院壹樣專業) 懸賞100哦

#include <stdio.h>

#include <stdlib.h>

void order();

void average();

void inquirexh();

int x, y, z;

struct Student

{

long xuehao;

char xingming[30];

float shuxue;

float yuwen;

float yingyu;

float zongcj;

};

struct Student student[200],stu;

struct Student *p=student;

int main()

{

char l;

FILE *fout;

printf("請問要輸入幾個學生的成績: \n");

scanf("%d", x);

if ((fout = fopen("d:\stud.txt", "wb")) == NULL)

{

printf("不能打開文件! \n");

exit(0);

}

for (y = 0; y < x; y++, p++)

{

printf("學號: \n");

scanf("%ld", &p->xuehao);

fwrite(&p->xuehao, sizeof(long), 1, fout);

printf("姓名 \n");

scanf("%s", &p->xingming);

fwrite(&p->xingming, sizeof(char), 1, fout);

printf("數學 \n");

scanf("%f", &p->shuxue);

fwrite(&p->shuxue, sizeof(float), 1, fout);

printf("語文 \n");

scanf("%f", &p->yuwen);

fwrite(&p->yuwen, sizeof(float), 1, fout);

printf("英語 \n");

scanf("%f", &p->yingyu);

fwrite(&p->yingyu, sizeof(float), 1, fout);

p->zongcj = p->shuxue + p->yuwen + p->yingyu;

fwrite(&p->zongcj, sizeof(float), 1, fout);

}

abc:printf

("請問要進行什麽運算 \n1.排序 \n2.輸出全班同學的平均成績 \n3.通過學號查詢某同學成績 \n");

scanf("%d", z);

switch (z)

{

case 1:

order();

break;

case 2:

average();

break;

case 3:

inquirexh();

break;

}

printf

("是否繼續 y(yes)or n(no)");

scanf("%d", &l);

if (l == y)

goto abc;

else

printf("謝謝使用!請關閉窗口!");

}

void order()

{

int i, j, k, g;

char h;

loop:printf

("請問進行什麽排序 \n1.按學號排序 \n2.按總成績排序 \n3.按數學成績排序 \n4.按語文成績排序 \n5.按英語成績排序 \n");

scanf("%d", &g);

switch (g)

{

case 1:

for (i = 0; i < x - 1; i++)

{

for (j = 0; j < x - i - 1; j++, p++)

{

if ((p->xuehao) > ((p + 1)->xuehao))

{

stu = student[j] ;

student[j] = student[j+1];

student[j+1] = stu;

}

}

}

break;

case 2:

for (i = 0; i < x - 1; i++)

{

for (j = 0; j < x - i - 1; j++, p++)

{

if ((p->zongcj) > ((p + 1)->zongcj))

{

stu = student[j] ;

student[j] = student[j+1];

student[j+1] = stu;

}

}

}

break;

case 3:

for (i = 0; i < x - 1; i++)

{

for (j = 0; j < x - i - 1; j++, p++)

{

if ((p->shuxue) > ((p + 1)->shuxue))

{

stu = student[j] ;

student[j] = student[j+1];

student[j+1] = stu;

}

}

}

break;

case 4:

for (i = 0; i < x - 1; i++)

{

for (j = 0; j < x - i - 1; j++, p++)

{

if ((p->yuwen) > ((p + 1)->yuwen))

{

stu = student[j] ;

student[j] = student[j+1];

student[j+1] = stu;

}

}

}

break;

case 5:

for (i = 0; i < x - 1; i++)

{

for (j = 0; j < x - i - 1; j++, p++)

{

if ((p->yingyu) > ((p + 1)->yingyu))

{

stu = student[j] ;

student[j] = student[j+1];

student[j+1] = stu;

}

}

}

break;

}

printf

("學號\t姓名\t數學\t語文\t英語\t總成績\n");

for (k = 0; k < x; k++, p++)

{

printf("%ld\t", p->xuehao);

printf("%s\t", p->xingming);

printf("%5.1f\t", p->shuxue);

printf("%5.1f\t", p->yuwen);

printf("%5.1f\t", p->yingyu);

printf("%5.1f\n", p->zongcj);

}

printf("是否繼續排序 y(yes)or n(no)");

scanf("%s", &h);

if (h == y)

goto loop;

else

printf("謝謝使用 \n");

}

void average()

{

int i, j, k, a = 0, b = 0, c = 0;

for (i = 0; i < x; i++, p++)

{

a = a + p->shuxue;

}

a = a / x;

printf("全班同學數學平均成績 \n", a);

for (i = 0; i < x; i++, p++)

{

b = b + p->yuwen;

}

b = b / x;

printf("全班同學語文平均成績 \n", a);

for (i = 0; i < x; i++, p++)

{

c = c + p->yingyu;

}

c = c / x;

printf("全班同學英語平均成績 \n", a);

}

void inquirexh()

{

int i, j, k;

char e;

def:printf

("請輸入要查詢的同學的學號 \n");

scanf("%ld", &k);

for (i = 0; i < x; i++, p++)

{

if (p->xuehao == k)

printf

("學號%ld姓名%s數學%f語文%f英語%f總成績%f",

p->xuehao, p->xingming, p->shuxue, p->yuwen, p->yingyu,

p->zongcj);

}

printf("是否繼續查詢?y(yes)or n(no)");

scanf("%s", &e);

if (e == y)

goto def;

else

printf("謝謝使用 \n");

}

  • 上一篇:四川哪個地方的方言爆搞笑?
  • 下一篇:大學生程序員必備的十款工具
  • copyright 2024編程學習大全網