當前位置:首頁 » 編程語言 » 學生管理c語言版
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

學生管理c語言版

發布時間: 2023-05-25 05:24:57

Ⅰ 用c語言編寫一個學生管理系統。

學生信息管理系統

#include<stdio.h>

#inelude<stdlib.h>

#include<stnng.h

#define BUFLEN 100

#define LEN 15

#define N 100

#strucet record

char codc[LEN+I J;

char name[LEN-1];

int age:

char sex 13l:

char timc[1.KN-I J;

char add[301;

char tcl [l.EN+1 J:

char mail[30]:

}stu[N]:

int k=1.n,m.

void readfilcO;

void seekO;

void modify(;

void insert();

void del();

void display(;

void save();

void menu(;

int main(

While(k)

menu();

system("pause");

一℃himl 0:

}

void help()

{

printf(" nO.歡迎使用系統幫助, );

printf(" 1.進入系統後,先制新學生信息,再查詢: 』);

printf(" 2.按照菜單提示鍵入數字代號

printf(" 3. 增加學生信息後,切記保存按;.n」

printf(" 4. 謝謝您的仗用! ");

}

void n:adlilcO

r

r

char *p-"studcnt.txt'

FILE *fp,

hit i-0;

if ((fp=fopen("studcnt.txt","r" ))`=NULL)

{

printf("Open file %s error' Strike any key to exit! P);

system("pause");

exit(0);

}

while(fscanf(fp,"%s 0os0od0,os 0os %s %s 0os",stu[i].code,stu[i1.name,&stu(i1.age,

stu[i].sex,stuLiJ.time,stuLiJ.add,stu[iJ.tel.stu [iJ.mail)"==8)

{

i++;

i-i;

}

char codc[LEN+1 J;

char name[LEN-1 ];

nit age;

char sex [3I;

char timc[LEN-I J;

char add[30];

char tcl[LEN+I I;

char mail[30J;

)stu[N];

int k=1.n,m;

void readfilcO;

void seek();

void modify();

void insert();

void delO;

void display();

void save();

void menu();

int main()

{

while(k)

menu();

systcm("pause");

return 0:

}

void help()

{

printf(" nO.歡迎仗用系統幫助, ");

printf(" }n1.進入系統後,先刷新學生信息,再查詢: );

printf("in2.按照菜單提示鍵入數字代號加 );

printf("1n,. t}加學生信息後,切記保存按鈕 」

printf("'nd. i$:41您的使用 );

}

void readfile()

{

char *p-"studcnLtxt";

FILE*fp

int i=0;

if ((fp=fopcn("student. tx t","r'' )卜=NULL)

{

printf("Open file %s error' Strike any key to exit!".p);

systcm("pause");

exit(0);

}

i++;

i=i;

}

printf("請選擇菜單編號:』』);

scanf("%d",&num);

switch(num)

{

case 0:help();break;

cast 1:readflic();break;

case 2:seek();break;

case 3:modify();break;

case 4:insert();break;

case 5:del();break:

case 6:display();break;

case 7:savc();break;

case 8:k=0,break:

defaalt:prinf(」請在一8之間選擇 "):

}

}

拓展資料

C語言是一門通用計算機編程語言,應用廣泛。C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。

盡管C語言提供了許多低級處理的功能,但仍然保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。

Ⅱ 學生管理系統C語言

#include<stdio.h>
#define N 30
int Input1(long xuehao[],int score[],int n);
int Sum(int score[],int n);
int No3(long xuehao[],int score[],int n);
int No4(long xuehao[],int score[],int n);
int No5(long xuehao[],int score[],int n);
int No6(int score[],int n);
int Input1(long xuehao[],int score[],int n){
int i;

printf("輸入學號和成績\n");
for(i=0;i<n;i++){
scanf("%ld %d",&xuehao[i],&score[i]);
}
// for(i=0;i<n;i++){
// printf("學號%ld 成績%d\n",xuehao[i],score[i]);
//}
}

int Sum(int score[],int n){
int sum;
float aver;
sum=0; aver=0;
int i;
for(i=0;i<n;i++){
sum=sum+score[i];
}
aver=(float)sum/n;
printf("總分為%d,平均分為%.2f",sum,aver);
}

int No3(long xuehao[],int score[],int n){
int i,j,k,temp1;
long temp2;
for(i=0;i<n-1;i++){
k=i;
for(j=i+1;j<n;j++){
if(score[j]>score[k]){ k=j; }

}
if(k!=i){
/*交換成績*/
temp1=score[k];score[k]=score[i];score[i]=temp1;
/*交換學號*/
temp2=xuehao[k];xuehao[k]=xuehao[i];xuehao[i]=temp2;
}
}
int a;
printf("按成績高低排序\n");
for(a=0;a<n;a++){
printf("學號%ld 成績%d\n",xuehao[a],score[a]);
}

}
int No4(long xuehao[],int score[],int n){

int i,j,k,temp1;
long temp2;
for(i=0;i<n-1;i++){
k=i;
for(j=i+1;j<n;j++){
if(xuehao[j]>xuehao[k]){ k=j; }

}

if(k!=i){
/*交換學號*/
temp1=xuehao[k];xuehao[k]=xuehao[i];xuehao[i]=temp1;
/*交換成績*/
temp2=score[k];score[k]=score[i];score[i]=temp2;
}
}
int a;
printf("按學號排序\n");
for(a=0;a<n;a++){
printf("學號%ld 成績%d\n",xuehao[n-1-a],score[n-1-a]);
}

}

int No5(long xuehao[],int score[],int n){
int i,a;
long x;
No3(xuehao,score,n);
printf("輸入學號\n");
scanf("%ld",&x);
for(i=0;i<n;i++){
if(xuehao[i]==x){
a=i;
break;
}
}
printf("學號%ld 成績%d 排名%d\n ",xuehao[a],score[a],a+1);
}

int No6(int score[],int n){
int i;
int a=0,b=0,c=0,d=0,e=0;
float a1,b1,c1,d1,e1;

for(i=0;i<n;i++){
if(score[i]>=90) {a++; }
else if(score[i]>=80){b++; }
else if(score[i]>=70) {c++; }
else if(score[i]>=60) {d++; }
else {e++; printf("e is%d",e);}
}
a1=(float)a/n*100;b1=(float)b/n*100;c1=(float)c/n*100;d1=(float)d/n*100;e1=(float)e/n*100;
printf("優秀%d %.1f%%\n良好%d %.1f%% \n中等%d %.1f%% \n及格%d %.1f%%\n不及格%d %.1f%%\n",a,a1,b,b1,c,c1,d,d1,e,e1);

// printf("%.2f %.2f %.2f %.2f %.2f\n",a1,b1,c1,d1,e1);

}

int No7(long xuehao[],int score[],int n){
int i;
for(i=0;i<n;i++){
printf("學號%ld 成績%d\n",xuehao[i],score[i]);
}
Sum(score,n);
}

main(){
int score[N];
long xuehao[N];
int n;
printf("1.Input record\n");
printf("2.caculate total and average score of course\n");
printf("3.sort in descending order by score\n");
printf("4.sort in ascending order by score\n");
printf("5.search by number \n");
printf("6.statistic analysis\n");
printf("7.list record\n");
printf("0.exit\n");
int num;
printf("人數(不許超過30!不許超過30!不許超過30)\n");

do{scanf("%d",&n);}while(n<1 || n>30);
if(n>30) printf("wrong!\n");
//printf("輸入選項\n");
//scanf("%d",&num);
int p=1; //控制結束
do{
printf("輸入選項\n");
scanf("%d",&num);
switch(num){
case 1:
Input1(xuehao,score,n);
break;
case 2: Sum(score,n);
break;
case 3: No3(xuehao,score,n);

break;
case 4: No4(xuehao,score,n);
break;
case 5: No5(xuehao,score,n);
break;
case 6: No6(score,n);
break;
case 7: No7(xuehao,score,n);
break;
case 0: p=-1;
break;
}
}while(p!=-1);
return 0;
}

Ⅲ 用c語言編寫學生管理系統

由於插入記錄森吵會把之後的記錄給覆蓋掉
有三條思路給樓主選擇:
1、此鏈侍每次插入一個數據都把所有的學生記錄給讀出來,在結構體數組中做好後,再重新寫回去。(相當費內存,cpu)
2、從文件的末尾開始讀,依次把數據向後移一個,直到喚仿要插入的數據
3、在插入數據之前,先把要覆蓋的數據給讀出來,然後再覆蓋,同上,接著讀下一個數據,接著覆蓋,知道文件結束。

Ⅳ 用C語言實現學生管理系統

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct student {
int id; //學號
char name[20]; //名字
float score[3]; //3門成績
float average; //平均分
struct student *next;
}sinfo,*pinfo;

pinfo head;

void inithead() //初始化頭結點
{
head = NULL;

head = (pinfo)malloc(sizeof(sinfo));
if(head == NULL)
{
printf("memeroy error!\n");
exit(0);
}
head->id = 0;
memset(head->name,0,sizeof(head->name));
head->score[0] = 0;
head->score[1] = 0;
head->score[2] = 0;
head->average = 0;
head->next = NULL;

return ;
}

void getdata() //接受學生數據
{
int i;
pinfo p = head->next;
pinfo s = NULL;

s = (pinfo)malloc(sizeof(sinfo));
if(s == NULL)
{
printf("memeroy error!\n");
exit(0);
}
printf("please input the student infomation like:\n");
printf("id name score(1) score(2) score(3)\n");
scanf("%d %s %f %f %f",&s->id,s->name,&s->score[0],&s->score[1],&s->score[2]);
s->average = (s->score[0] + s->score[1] + s->score[2])/3.0;

if(head->next == NULL)
{
head->next = s;
s->next = NULL;
}else
{
while(p->next != NULL)
{
p = p->next;
}
p->next = s;
s->next = NULL;
}

return ;
}

void deleteinfo()
{
int id;

printf("input the id to delete:\n");
scanf("%d",&id);

pinfo p = head;
pinfo q = head->next;

while(p->next != NULL)
{
if(q->id == id)
{
p->next = q->next;
break;
}
p = p->next;
q = q->next;
}
}

void sortinfo() //排序
{
int i,j;
int count = 0;
pinfo s,k;
pinfo p = head;
pinfo q = head->next;
struct student top;

if(head->next == NULL || q->next == NULL)
{
printf("the list is empty or only have one member\n");
return ;
}
while(p->next != NULL)
{
count++;
p = p->next;
}
p = head;
for(i=0; i<count; i++)
{
for(j=0; j<(count-i); j++)
{
if(q->next == NULL)
{
if(p->average > q->average)
{
k->next->next = q;
q->next = p;
p->next = NULL;
}
break;
}
k = p;
p = p->next;
q = q->next;
if(p->average > q->average && q->next != NULL)
{
s = q->next;
k->next = q;
q->next = p;
p->next = s;
q = s;
}else if(p->average > q->average && q->next == NULL)
{
k->next = q;
q->next = p;
p->next = NULL;
break;
}
}
p = head;
q = head->next;
}

return ;
}

void showinfo() //輸出
{
pinfo p = head;

if(head->next == NULL)
{
printf("the list is empty!\n");
return;
}
printf("the student information list:\n");
printf("id\tname\tscore(1)\tscore(2)\tscore(3)\taverage\n");
while(p->next != NULL)
{
p = p->next;
printf("%d\t%s\t%.2f",p->id,p->name,p->score[0]);
printf("\t\t%.2f\t\t%.2f\t\t%.2f\n",p->score[1],p->score[2],p->average);
}
}

int main()
{
int choice;

inithead();
while(1)
{
do {
choice = 6;
printf("input your choice:\n");
printf("\t1.input student data\n");
printf("\t2.delete student data\n");
printf("\t3.sort student data\n");
printf("\t4.show student data\n");
printf("\t0.quit\n");
scanf("%d",&choice);
getchar();
}while(choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 0);

switch(choice)
{
case 1:
getdata();
break;
case 2:
deleteinfo();
break;
case 3:
sortinfo();
break;
case 4:
showinfo();
break;
case 0:
printf("welcome to come again!\n");
return 0;
}
}
}

正好寫了一個。。。

Ⅳ 學生信息管理系統(C語言版)

#include "stdio.h"
#include "bios.h"
#include "conio.h"
#include "STRING.H"
#include "DOS.h"
#include "process.h"
#include "stdlib.h"
#include "math.h"
#define key_down 80
#define key_up 72
#define key_esc 1
#define key_alt_f 33
#define key_alt_x 45
#define key_enter 28
#define key_alt_c 46
#define key_alt_e 18
#define key_alt_s 31
#define key_alt_d 32
#define key_alt_r 19
#define key_alt_p 25
#define key_alt_o 24
struct student
{
char name[20];
long num;
char age[2];
char sex[4];
char xibie[16];
char jiguan[50];
struct{
float chinese;
float english;
float math;
float total;
float ave;}score;
struct student *next;
};
struct student agent[50];
struct student *head,*this1,*new1,*new2,*stud;
char numstr[40]={' ',' '};
int n=0;
int r=0;
int k=0;
long num;
int get_key();
void box(int startx,int starty,int high,int width);
void new1name(void),listall(void),wfile(void),rfile(void);
struct student *insert(struct student *head ,struct student *stud);
void cjlr(),cjtj(),cjpx(),cxxs(),list(),cxcj();
void del();
int mmm();
int nnn();
void ab();
mmm()
{char aaa[6],bbb[6];
char d; //int r=0;
int i=0;
FILE *fp;
char a[6];
char b[6];
clrscr();
if((fp=fopen("file1","r"))==NULL)
{ window(1,1,80,25);
textbackground(1);
textcolor(0);
clrscr();
window(20,8,60,20);
textbackground(14);
textcolor(0);
clrscr();
gotoxy(8,2);
cprintf("NO UER!");
fclose(fp);
fp=fopen("file1","w");
gotoxy(2,4);
printf("Please input name:");
gets(a);fwrite(a,6,1,fp);
gotoxy(2,8);
printf("Please input key:");
gets(b); fwrite(b,6,1,fp);
fclose(fp);
ab();
}
else
{ window(1,1,80,25);
textbackground(1);
textcolor(0);
clrscr();
window(20,8,60,20);
textbackground(14);
textcolor(0);
clrscr();
gotoxy(8,2);
cprintf("Input Your Name And Password:");
gotoxy(2,8);
cprintf(" PWD:");
gotoxy(2,4);
cprintf("NAME:");
scanf("%s",aaa);

gotoxy(7,8);
while(d=getch())
{
if(d==13)
break;
cprintf("*");
bbb[i]=d;
i++;
}
fp=fopen("file1","r");
fread(a,6,1,fp);
fread(b,6,1,fp);
fclose(fp);
for(i=0;i<=5;i++)
{
if(aaa[i]!=a[i] || bbb[i]!=b[i])
exit(0);

}

}

ab();

}
nnn()
{union REGS inregs ,outregs;
inregs.h.ah=0x2a;
intdos(&inregs,&outregs);
window(60,24,80,25);
textbackground(14);
textcolor(0);
clrscr();
cprintf("Data is 2004-%d-%d.\n",outregs.h.dh,outregs.h.dl);
return 0;
}

void ab()
{int i;
clrscr();
window(1,1,80,25);
textbackground(1);
textcolor(0);
clrscr();
window(20,8,62,20);
textbackground(14);
textcolor(128);
clrscr();
for(i=0;i<=11;i++)
{window(20,8+i,62,9+i);
textbackground(i);
textcolor(128+i*2);
clrscr();
cprintf(" Welcome To Students Management System!");
}
getch();
}
main()
{int i,key,x,y,l;
char *menu[]={"input(F)","print1(O)","del(D)","find(C)","print(P)","save(S)","exit(X)"};
char *red[]={"input","printf1","del","find","print","cpoy","exit"};
char *f[]={"xueji luru","chengji luru","chenji tongji","add student","chengji paixu"};
char *c[]={"student","chengji"};
char buf[16*10*4],buf1[16*4];
struct student *stud;
if(k++==0)
mmm();
window(1,2,80,25);
textbackground(15);
textcolor(0);
clrscr();
textbackground(1);
clrscr();
window(1,1,80,1);
textbackground(15);
textcolor(0);
clrscr();
window(1,1,80,2);
gotoxy(1,1);
for(i=0,l=0;i<7;i++)
{x=wherex();
y=wherey();
cprintf(" %s",menu[i]);
l=strlen(menu[i]);
gotoxy(x,y);
textcolor(RED);
cprintf(" %s",red[i]);
x=x+l+4;
gotoxy(x,y);
textcolor(BLACK);
}
nnn();
if(r++==0)
main();
window(1,2,80,25);
while(1)
{
key=0;
while(bioskey(1)==0);
key=get_key();
if(key==key_alt_x) exit(0) ;
if(key==key_alt_s) wfile();
if(key==key_alt_d) del();
if(key==key_alt_r) rfile();
if(key==key_alt_p) listall();
if(key==key_alt_o) list();
if(key==key_alt_f)
{textbackground(0);
textcolor(15);
gotoxy(4,1);
cprintf("%s",menu[0]);
gettext(4,2,18,12,buf);
window(4,2,18,8);
textbackground(15);
textcolor(0);
clrscr();
window(4,2,19,9);
box(1,1,7,16);
for(i=2;i<7;i++)
{gotoxy(2,i);
cprintf("%s",f[i-2]);}
gettext(2,2,18,3,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,2);
cprintf("%s",f[0]);
y=2;
key=get_key();
while(key!=key_alt_x && key!=key_enter && key!=key_esc)
{if(key==key_up || key==key_down)
{puttext(2,y,18,y+1,buf1);
if(key==key_up)
y=y==2?6:y-1;
if(key==key_down)
y=y==6?2:y+1;
gettext(2,y,18,y+1,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,y);
cprintf("%s",f[y-2]);
}
key=get_key();
}
if(key==key_alt_x) exit(0);
if(key==key_enter)
{switch(y-1)
{case 1 : new1name();break;
case 2 : cjlr();break;
case 3 : cjtj();break;
case 4 : insert(head,stud);break;
case 5 : cjpx();break;
default : break;
}
}
}
else
{
window(1,1,80,1);
puttext(2,2,19,10,buf);
textbackground(15);
textcolor(0);
gotoxy(4,1);
cprintf("%s",menu[0]);

}
if(key==key_alt_c)
{textbackground(0);
textcolor(15);
gotoxy(39,1);
cprintf("%s",menu[3]);
gettext(39,2,50,7,buf1);
window(39,2,49,5);
textbackground(15);
textcolor(0);
clrscr();
window(39,2,49,6);
box(39,1,4,11);
for(i=2;i<4;i++)
{
gotoxy(2,i);
cprintf("%s",c[i-2]);
}
gettext(39,2,49,3,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,2);
cprintf("%s",c[0]);
y=2;
key=get_key();
while(key!=key_alt_x&&key!=key_enter&&key!=key_esc)
{if(key==key_up||key==key_down)
{puttext(39,y,49,y+1,buf1);
if(key==key_up)
y=y==2?3:y-1;
if(key==key_down)
y=y==3?2:y+1;
gettext(39,y,49,y+1,buf1);
textbackground(0);
textcolor(15);
gotoxy(2,y);
cprintf("%s",c[y-2]);
}
key=get_key();
}
if(key==key_alt_x) exit(0);
if(key==key_enter)
{switch(y-1)
{case 1: cxxs();break;
case 2: cxcj();break;

default:break;
}
}
}
else
{window(1,1,80,2);
puttext(39,2,49,7,buf);
textbackground(15);
textcolor(0);
gotoxy(39,1);
cprintf("%s",menu[3]);

}
} }

int get_key()
{ union REGS rg;
rg.h.ah=0;
int86(0x16,&rg,&rg);
return rg.h.ah;
}

void box(int startx,int starty,int high,int width)
{ int i;
gotoxy(startx,starty);
putch(0xda);
for(i=starty+1;i<width;i++)
putch(0xc4);
putch(0xbf);
for(i=starty+1;i<high;i++)
{gotoxy(startx,i);
putch(0xb3);
gotoxy(width,i);putch(0xb3);}
gotoxy(startx+1,width);
putch(0xc0);
for(i=startx+1;i<width;i++)
putch(0xc4);
putch(0xd9);
return;
}

/* void new1name(void)
{ int key;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
cprintf("Are you sure input?");
key=get_key();
while(key!=key_alt_x && key!=key_esc)
{
window(1,2,80,25);
textbackground(BLUE);
clrscr();
new1=new2=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
head=new1;
else
{ this1=head;
while(this1->next!=NULL)
this1=this1->next;
this1->next=new1;
}
this1=new1;
printf("\nRecord%d:",n+1);
printf("\nXing Ming:");
gets(this1->name);
printf("\nXue Hao:");
gets(numstr);
this1->num=atol(numstr);
printf("\nNian Ling:");
gets(this1->age);
printf("\nXing Bie:");
gets(this1->sex);
printf("\nXue Yuan:");
gets(this1->xibie);
printf("\nJi Guan:");
gets(this1->jiguan);
n++;
this1->next=NULL;
printf("Are you sure input :Y/N?");
if(getch()=='n')
main();
else
new1name();
}
} */

void new1name(void)
{ int key;
char a;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
cprintf("Are you sure input?");
key=get_key();
while(key!=key_alt_x && key!=key_esc)
{
window(1,2,80,25);
textbackground(BLUE);
clrscr();
new1=new2=(struct student *)malloc(sizeof(struct student));
if(head==NULL)
head=new1;
else
{ this1=head;
while(this1->next!=NULL)
this1=this1->next;
this1->next=new1;
}
this1=new1;
printf("\nRecord%d:",n+1);
printf("\nXing Ming:");
gets(&a);
gets(this1->name);
printf("\nXue Hao:");
gets(numstr);
this1->num=atol(numstr);
printf("\nNian Ling:");
gets(this1->age);
printf("\nXing Bie:");
gets(this1->sex);
printf("\nXue Yuan:");
gets(this1->xibie);
printf("\nJi Guan:");
gets(this1->jiguan);
n++;
this1->next=NULL;
printf("Are you sure input :Y/N?");
if(getch()=='n')
main();
else
new1name();
}
main();
}
/**/
void listall(void)
{
int i=0;
window(1,2,80,25);
textbackground(1);
textcolor(0);
clrscr();
if(head==NULL)
{cprintf("\nempty list .\n");return;
}
this1=head;

do
{ cprintf("\nrecord number %d\n",++i);
cprintf(" name:%s",this1->name);
cprintf(" number:%ld",this1->num);
cprintf(" age:%s",this1->age);
cprintf(" sex:%s",this1->sex);
cprintf(" xibie:%s",this1->xibie);
cprintf(" jiguan:%s",this1->jiguan);
cprintf(" chinese:%6.2f",this1->score.chinese);
cprintf(" english:%6.2f",this1->score.english);
cprintf(" math:%6.2f",this1->score.math);
cprintf(" total:%6.2f",this1->score.total);
cprintf(" ave:%6.2f\n",this1->score.ave);
this1=this1->next;
//this1->next=NULL;
}while(this1!=NULL);
getch();
main();
}
//*insert
struct student *insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
while((p0->num>p1->num) && (p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(p0->num<=p1->num)
{if(head==p1)
{head=p0;
p0->next=p1;
}
else
{p2->next=p0;
p1->next=p1;
}
}
else
{p1->next=p0;
p0->next=NULL;
}
n=n+1;
return(head);
}
void wfile(void)
{FILE *fptr;
char a[10];
if(n<1)
{printf("\nCan't write empty list.\n");return;}
// char a[10];
cprintf("Please input filename:");
gets(a);
if((fptr=fopen(a,"wb"))==NULL)
printf("\nCant' open file agents.rec\n");
else
{this1=head;
while(this1->next!=NULL)
{fwrite(this1,sizeof(struct student ),1,fptr);
this1=this1->next;
}
// fwrite(this1,sizeof(struct student ),1,fptr);
fclose(fptr);
printf("\nFile of %d records have writen.\n",n);
}
getch();
main();
}
//*rfile
void rfile(void)
{FILE *fptr;
char b[10];
cprintf("Please input filename:");
gets(b);
if((fptr=fopen(b,"rb"))==NULL)
printf("\nCan't open file %s\n",b);
else
{n=0;
head=(struct student *)malloc(sizeof(struct student));
this1=head;
fread(this1,sizeof(struct student),1,fptr);
n++;
while(1)
{if(feof(fptr))
{fclose(fptr);
this1->next=NULL;printf("\nFile read.Total agents is now %d.\n",n);
getch(); main() ;
}else{
this1->next=(struct student *)malloc(sizeof(struct student));
this1=this1->next;
fread(this1,sizeof(struct student),1,fptr);
n++;
}} this1->next=NULL;

//fread(this1,sizeof(struct student),1,fptr);
//n++;
fclose(fptr);
printf("\nFile read.Total agents is now %d.\n",n);
}
getch();
main();
}
//*wfile
/*void wfile(void)
{char a[10];
FILE *fptr;
if(n<1)
{printf("\nCan't write empty list.\n");return;}
cprintf("Please input filename:");
gets(a);
if((fptr=fopen(a,"wb"))==NULL)
{cprintf("\nCant' open file ");puts(a);cprintf("\n");
}
else
{fwrite(agent,sizeof(struct student ),n,fptr);
fclose(fptr);
printf("\nFile of %d records writen.\n",n);
}
getch();
main();
}
//*rfile
void rfile(void)
{FILE *fptr;
char a[10];
cprintf("Please input filename:");
gets(a);
if((fptr=fopen(a,"wb"))==NULL)
{cprintf("\nCan't open file ");puts(a);
}
else
{while(fread(&agent[n],sizeof(agent[n]),1,fptr)==1)
n++;
fclose(fptr);
printf("\nFile read.Total agents is now %d.\n",n);
}
getch();
main();
} */
//*cjlr
void cjlr(void)
{struct student *p1;
long num; char ddd[5];
char ccc[5];
window(1,2,80,25);
textbackground(BLUE);
clrscr();
p1=head;
printf("input the student' number:");
scanf("%ld",&num);
if(head==NULL)
{
printf("\nlist null!\n");
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p1=p1->next;}
if(p1->num==num)
{printf("chinese:");
scanf("%f",&p1->score.chinese);
// gets(ccc);printf("\n");
// p1->score.chinese=atof(ccc);
printf("english:");
scanf("%f",&p1->score.english);
// gets(numstr);
//p1->score.english=atof(numstr);
//getch();
printf("math:");
scanf("%s",ddd);
// gets(ddd);
p1->score.math=atof(ddd);
p1->score.total=p1->score.chinese+p1->score.english+p1->score.math;
p1->score.ave=(p1->score.chinese+p1->score.english+p1->score.math)/3.0;
}
getch();
main();
}
//*cjlr
/*void cjlr(void)
{struct student *p1;
long num; char ddd[4];
window(1,2,80,25);
textbackground(BLUE);
clrscr();
p1=head;
printf("input the student' number:");
scanf("%ld",&num);
if(head==NULL)
{
printf("\nlist null!\n");
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p1=p1->next;}
if(p1->num==num)
{printf("chinese:");
scanf("%f",p1->score.chinese);
//gets(numstr);
//p1->score.chinese=atof(numstr);
//getch();
printf("english:");
scanf("%f",p1->score.english);
//gets(numstr);
//p1->score.english=atof(numstr);
// getch();
printf("math:");
//scanf("%f",p1->score.math);
gets(ddd);
p1->score.math=atof(ddd);
p1->score.ave=(p1->score.chinese+p1->score.english+p1->score.math)/3.0;
getch();
}
getch();
main();
} */
//*del
void del()
{struct student *p1,*p2;
long num;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("input the del student' number:");
scanf("%ld",&num);
if(head==NULL)
{
printf("\nlist null!\n"); exit(1);
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p2=p1;p1=p1->next;
}
if(num==p1->num)
{if(p1==head) head=p1->next;
else
p2->next=p1->next;
printf("the %ld message have del\n",num);
n=n-1;
}
else
printf("No find %ld!\n",num);
getch();
main();
}
//
void cjtj(void)
{struct student *p;
for(p=head;p!=NULL;p=p->next)
{ p->score.total=p->score.chinese+p->score.english+p->score.math;
p->score.ave=p->score.total/3.0;
}
}
//
void cjpx(void)
{
struct student *p,*p1;
int i,j,t;
float temp;
for(i=0;i<n;i++)
{

p=head;
p1=p->next;
if(p->score.total<p1->score.total)
{temp=p->score.total;
p->score.total=p1->score.total;
p1->score.total=temp;
}
}
}
//
void cxxs(void)
{ struct student *p;
char name1[20];
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("shu ru yao cha xun de xue sheng de xing ming:");
gets(name1);
for(p=head;p!=NULL;p=p->next)
{if(strcmp(p->name,name1)==0)

{printf("xingming:%s\n",p->name);
printf("xuehao:%ld\n",p->num);
printf("nianling:%s\n",p->age);
printf("xingbie:%s\n",p->sex);
printf("xibie:%s\n",p->xibie);
printf("jiguan:%s\n",p->jiguan);
}
} getch();
main();
}
/*chaxunchengji*/
void cxcj(void)
{ struct student *p;
char name2[20]; int i;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("shu ru yao cha xu de xue sheng de xingming:");
gets(name2);
for(p=head;p!=NULL;p=p->next)
{if(strcmp(p->name,name2)==0)
{printf("xingming:%s\n",p->name);
printf("chinese:%6.2f\n",p->score.chinese);
printf("english:%6.2f\n",p->score.english);
printf("math:%6.2f\n",p->score.math);
printf("total:%6.2f\n",p->score.total);
printf("ave:%6.2f\n",p->score.ave);
}
}getch();
main();
}

/*dayingmugexueshen*/
void list(void)
{ char name3[20];
int i=0;
window(1,2,80,25);
textbackground(BLUE);
clrscr();
printf("shu ru yao da ying de xue sheng xingming:");
gets(name3);
if(head==NULL)
{ printf("\nempty list.\n");
return;
}
for(this1=head;this1!=NULL;this1=this1->next)
{
if(strcmp(this1->name,name3)==0)
{printf("\nnrecord number %d\n",++i);
printf("xingmming:%s\n",this1->name);
printf("xuehao:%ld\n",this1->num);
printf("nianling:%d\n",this1->age);
printf("xingbie:%s\n",this1->sex);
printf("xueyuan:%s\n",this1->xibie);
printf("jiguan:%s\n",this1->jiguan);
printf("chinese:%6.2f\n",this1->score.chinese);
printf("english:%6.2f\n",this1->score.english);
printf("math:%6.2f\n",this1->score.math);
printf("total:%6.2f\n",this1->score.total);
printf("ave:%6.2f\n",this1->score.ave);
}

} getch();
main();
}

Ⅵ C語言 學生管理系統

#include
#include
#include
#include

#define max 20

typedef struct student //學生
{
char sno[max]; // 學號
char sname[max]; //姓名
char sex[max]; //性別
char age[max]; //年齡
char depart[max]; //系
char classs[max]; //班
char grade[max]; //年級

struct student* next;
} student;

student* head;

int LogOn() //登錄模塊,已實現輸入密碼不回顯,如果中途發現輸錯某幾位,可退格鍵重輸
{
char username[max],password[max];
printf("\n請輸入用戶名:");
scanf("%s",username);
printf("\n請輸入密碼(最多15位):");

//開始以不回顯且支持退格方式獲取輸入密碼
int i=0;
while((i>=0)&&(password[i++]=getch())!=13)//條件i>=0是用於限制退格的范圍
{
if(password[i-1]=='\b')//對退格鍵的處理
{
printf("%c%c%c",'\b','\0','\b');
i=i-2;
}
else
printf("*");
}
password[--i]='\0';

//已獲取密碼。驗證用戶身份
if(!strcmp(username,"zhang")&&!strcmp(password,"8147086"))
{
printf("\n登錄成功!");
return 1;
}
else
return 0;

}

void regist()
{
char ch;
student *s,*ptr; //s用來建新結點,ptr用來暫存頭結點

do
{

s=(student*)malloc(sizeof(student)); // 新建一個學生結點

printf("\n開始注冊..."); //開始注冊
printf("\n請輸入該學生的學號:");
scanf("%s",s->sno);
printf("\n請輸入該學生的姓名:");
scanf("%s",s->sname);
printf("\n請輸入該學生的性別:");
scanf("%s",s->sex);
printf("\n請輸入該學生的年齡:");
scanf("%s",s->age);
printf("\n請輸入該學生的系:");
scanf("%s",s->depart);
printf("\n請輸入該學生所在的班:");
scanf("%s",s->classs);
printf("\n請輸入該學生所在的年級");
scanf("%s",s->grade);

ptr=head;
head=s;//將新結點插入隊頭
s->next=ptr;

fflush(stdin);
printf("\n請問是否繼續注冊?(Y/N)");
scanf("%c",&ch);
}while(ch=='Y'||ch=='y');

return;
}

void ElePrint(char str[]) //輸出單個元素
{
if(str==NULL) exit(0);
printf("%s",str);
for(unsigned int i=0;i<12-strlen(str);i++) printf(" ");//為了對齊輸出,需插入一些空格
return;
}

int LinePrint(student *ptr) //輸出一行
{
if(ptr==NULL) //檢查傳進來的指針
return 0;

printf("\n");
ElePrint(ptr->sno);
ElePrint(ptr->sname);
ElePrint(ptr->age);
ElePrint(ptr->sex);
ElePrint(ptr->depart);
ElePrint(ptr->classs);
ElePrint(ptr->grade);

return 1;
}

void print() //輸出全部學生信息
{
student *ptr=head;
printf("\n學號 姓名 年齡 性別 系 班 年級 ");
while(ptr)
{
LinePrint(ptr);
ptr=ptr->next;
}
printf("\n");
return;
}
void search()//查詢模塊
{
int method;//查詢方式
char no[max],name[max],departm[max],clss[max],grades[max]; //用來接收查詢關鍵字
while(1)
{
printf("\n請選擇查詢方式");
printf("\n1.按學號查詢");
printf("\n2.按姓名查詢");
printf("\n3.按所在系查詢");
printf("\n4.按所在班級查詢");
printf("\n5.按所在年級查詢");
printf("\n6.列印全部學生信息");
printf("\n7.返回主菜單\n");

scanf("%d",&method);

student *p=head,*temp;

switch(method)
{
case 1:
printf("\n請輸入要查詢的學號:");
scanf("%s",no);
while(p)
{
if(!strcmp(p->sno,no))
break;
else
{
temp=p;
p=p->next;
}
}
printf("\n學號 姓名 年齡 性別 系 班 年級 ");
LinePrint(p);
break;
case 2:
printf("\n請輸入要查詢的姓名:");
scanf("%s",name);
printf("\n學號 姓名 年齡 性別 系 班 年級 ");
while(p)
{
if(!strcmp(p->sname,name))
LinePrint(p);
p=p->next;
}
break;
case 3:
printf("\n請輸入學生所在的系:");
scanf("%s",departm);
printf("\n學號 姓名 年齡 性別 系 班 年級 ");
while(p)
{
if(!strcmp(p->depart,departm))
LinePrint(p);
p=p->next;
}
break;
case 4:
printf("\n請輸入學生所在的班:");
scanf("%s",clss);
printf("\n請輸入學生所在的年級:");
scanf("%s",grades);
printf("\n學號 姓名 年齡 性別 系 班 年級 ");
while(p)
{
if(!strcmp(p->classs,clss)&&!strcmp(p->grade,grades))
LinePrint(p);
p=p->next;
}
break;

case 5:
printf("\n請輸入學生所在的年級:");
scanf("%s",grades);
printf("\n學號 姓名 年齡 性別 系 班 年級 ");
while(p)
{
if(!strcmp(p->grade,grades))
LinePrint(p);
p=p->next;
}
break;

case 6:
print();
break;

case 7:
return;
default:
printf("很抱歉,暫無此查詢方式!");
break;
}
}

}

void modify()//修改學生信息
{
char num[max];
student *p=head;
printf("\n請輸入要修改的學生的學號:");
scanf("%s",num);
while(p)
{
if(!strcmp(p->sno,num))
break;
else
p=p->next;
}
if(p==NULL)
{
printf("\n錯誤:沒有此學生的信息!\n");
return;

}
LinePrint(p);

printf("\n請輸入要修改的該學生的信息:");
printf("\n1.姓名");
printf("\n2.性別");
printf("\n3.年齡");
printf("\n4.所在的系");
printf("\n5.所在的班");
printf("\n6.所在的年級");

char name1[max],sex1[max],age1[max],depart1[max],class1[max],grade1[max];
int select;
fflush(stdin);
scanf("%d",&select);
printf("\n請輸入新的信息:");

switch(select)
{
case 1:
scanf("%s",name1);
strcpy(p->sname,name1);
break;
case 2:
scanf("%s",sex1);
strcpy(p->sex,sex1);
break;
case 3:
scanf("%s",age1);
strcpy(p->age,age1);
break;
case 4:
scanf("%s",depart1);
strcpy(p->depart,depart1);
break;
case 5:
scanf("%s",class1);
strcpy(p->classs,class1);
break;
case 6:
scanf("%s",grade1);
strcpy(p->grade,grade1);
break;
default:
printf("\nError!");
break;
}

LinePrint(p);
return;
}

void del()// 刪除某學生的信息
{
student *p=head,*temp=head,*s;
char num1[max];
printf("\n請輸入要刪除的學生的學號:");
scanf("%s",num1);
while(p)//查找該學生所在的結點
{
if(!strcmp(p->sno,num1))
break;
else
{
temp=p;
p=p->next;
}

}//while
if(!p)
{
printf("\n不存在此學生的信息.");
return;
}
LinePrint(p);//輸出該學生的信息
printf("\n請問真的要刪除該學生的信息嗎?(Y/N)");
char ch;
fflush(stdin);
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
{
s=p->next;
temp->next=s;
free(p);
printf("\n已經刪除該學生的信息.");
}
return;
}

void sort() //排序模塊。將學生記錄按學號從小到大排列。用起泡排序演算法實現
{

student *ptr,*s=head,*p;
int count=0,count1;
while(s)//統計鏈表結點個數
{
count++;
s=s->next;
}

for(int i=1;i<count;i++)
{
ptr=head;
p=NULL;
count1=count-i; //用來控制每輪起泡排序的終點,即每次把學號最小的結點移到倒數第i個結點
while(ptr&&ptr->next&&(count1--))
{
if(strcmp(ptr->sno,ptr->next->sno)>0)
{
s=ptr->next;
ptr->next=s->next;
if(p==NULL) //ptr處於隊頭時
head=s;
else
p->next=s;
s->next=ptr;
p=s;
}
else
{
ptr=ptr->next;
if(p==NULL) //ptr處於隊頭時
p=head;
else
p=p->next;
}
}
}
return;
}

void quit()
{
char ch;
printf("\n真的要退出?(Y/N)");
fflush(stdin);
scanf("%c",&ch);
if(ch=='Y'||ch=='y')
exit(0);
return;
}

int main()
{
int option;

printf("\nCopyright@2005 KongXinCai All rights reserved.");
printf("\n歡迎使用學生信息管理系統!\n");

//登錄模塊
int icheck=0;
while(icheck<3)
{
if(LogOn()==0)
icheck++;
else
break;

}
if(icheck==3)
{
printf("\n連續登錄三次不成功,退出!");
exit(0);
}

//系統界面

while(1)
{
printf("\n\n請選擇需要的服務:");
printf("\n1.注冊");
printf("\n2.查詢");
printf("\n3.修改");
printf("\n4.刪除");
printf("\n5.排序");
printf("\n7.求平均");
printf("\n6.退出\n");

scanf("%d",&option);

switch(option)
{
case 1:
regist();
break;
case 2:
search();
break;
case 3:
modify();
break;
case 4:
del();
break;
case 5:
sort();
break;
case 6:
quit();
break;
}

}

return 0;

}

Ⅶ 學生信息管理系統編程(c語言)

挺好的一個題目啊

但我可不願意幫人寫作業

網上很多類似的,你可以參考下:
#include <stdio.h>
#include <string.h> struct student {
char name[30];
float math;
float chinese;
float english;
float average;
};

int MenuChoice(void);
int EnterAccount(void);
void Enter(struct student *fst);
void Amend(struct student *src);
void Delete(struct student *next);
void Print(struct student *out);

main()
{
struct student one[100] = {0}, *look = one;
int menu, t;

while ((menu = MenuChoice()) != 0)

if (menu >= 1 && menu <= 4 && (t = EnterAccount())) {
look = one + t;

switch (menu) {
case 1:
Enter(look);
break;
case 2:
if (strcmp(look->name, ""))
printf("學號:%d\n姓名: %s\n語文成績: %.1f\n數學成績:%.1f\n英語成績: %f\n平均"成績:%.1f\n",
t, look->name, look->chinese, look->math, look->english, look->average);
else
printf("對不起,該學號不存在!\n");
break;
case 3:
Amend(look);
break;
case 4:
Delete(look);
break;
}
}
else if (menu == 5)
Print(one);
else
printf("錯誤的請求!\n");

return 0;
}

int MenuChoice(void)
{
int choice;

printf("請選擇:\n"
"1 - 新建學生信息\n"
"2 - 查找學生信息\n"
"3 - 修改學生信息\n"
"4 - 刪除學生信息\n"
"5 - 列印學生信息\n"
"0 - 退出\n");
scanf("%d", &choice);

return choice;
}

int EnterAccount(void)
{
int ret;

printf("請輸入學號:\n");
scanf("%d", &ret);

if (ret >= 1 && ret <= 100)
return ret -1;

return 0;
}

void Enter(struct student *fst)
{
printf("請輸入學生姓名、語文成績、數學成績、英語成績和平均成績\n");
scanf("%s%f%f%f%f", fst->name, &fst->chinese, &fst->math, &fst->english, &fst->average);
}

void Amend(struct student *src)
{
int t;

printf("請選擇:\n"
"1 - 修改學生姓名\n"
"2 - 修改學生語文成績\n"
"3 - 修改學生數學成績\n"
"4 - 修改學生英語成績\n"
"5 - 修改學生平均成績\n");
scanf("%d", &t);

switch (t) {
case 1:
printf("請輸入學生的新名字\n");
scanf("%s", src->name);
break;
case 2:
printf("請輸入學生新的語文成績\n");
scanf("%f", &src->chinese);
break;
case 3:
printf("請輸入學生新的數學成績\n");
scanf("%f", &src->math);
break;
case 4:
printf("請輸入學生新的英語成績\n");
scanf("%f", &src->english);
break;
case 5:
printf("請輸入學生新的平均成績\n");
scanf("%f", &src->average);
break;
}

}

void Delete(struct student *next)
{
strcpy(next->name, "");
next->math = next->english = next->chinese = next->average = 0.0;
}

void Print(struct student *out)
{
struct student *up;

for (up = out; out < &up[100]; out++)

if (strcmp(out->name, ""))
printf("學號:%d\n姓名: %s\n語文成績: %.1f\n數學成績:%.1f\n英語成績: %.1f\n平均成績:%.1f\n",
out-up + 1, out->name, out->chinese, out->math, out->english, out->average);
}

Ⅷ 用C語言設計一個簡單的學生信息管理程序

#include <iostream>#include <stdio.h>#include <string.h>#include <conio.h>#include <iostream>#include <ctime>using namespace std;#define max 100
///////////////////////////////////////////////////////////////知梁///////////strcut stustruct stu //學生資料結構缺畢體{ char name[10]; char num[20]; //學號 char adress[8]; float x,y,z,score; int number;};
//////////////////////////////////////////搭扮運////////////////////////////////////student.cppint count=0;int temp=0;int Exchang=0; //定義數據修改標志,若修改則為1,否則為0class student //學生類{private: stu data[max]; char start_del;public: void input(char *ch1,char *num,char *ch2,float x,float y,float z); //輸入 void find(char *num); //查找 void del(char *num); //刪除 int check_num(char *num) //確定沒有重復學號 { int m=0; while(m<=count) if(!strcmp(num,data[m++].num)) //判斷是否相同 break; if(m>count) return 0; else return 1; } void taxis(); //總分排序 void show(); void save(); //保存學生資料 void read(); //從文件"student"讀取學生資料};
void student::input(char *ch1,char *num,char *ch2,float x,float y,float z){ strcpy(data[count].name,ch1); strcpy(data[count].num,num); strcpy(data[count].adress,ch2); data[count].x=x; data[count].y=y; data[count].z=z; count++; Exchang=1; //設置已修改數據標志}void student::find(char * num){ int m=0; while(m<=count) if(!strcmp(num,data[m++].num)) break; if(m>count) { cout << "很抱歉,沒有該學號的學生" << endl; start_del='n'; getch(); } else { temp=count; count=m; start_del='y'; cout << "該學生的資料為" <<endl << "序號\t姓名\t學號\t\t地址\t\t\t高數\t英語\t計算機" << endl; show(); count=temp; getch(); }}void student::del(char *num){ char chose; find(num); if(start_del=='y') {
cout << "確實要刪除該學生資料? Y/N" << endl; cin >> chose; if(chose=='y') { int m=0; while(m<count) if(strcmp(num,data[m++].num)==0) //錯在這里 break; temp=count; count=m; if(temp==count) { count=temp-1;printf("2"); cout << "該學生資料已刪除" << endl; Exchang=1; //設置已修改數據標志 } else { while(count<temp) { strcpy(data[count-1].name,data[count].name); strcpy(data[count-1].num,data[count].num); strcpy(data[count-1].adress,data[count].adress); data[count-1].x=data[count].x; data[count-1].y=data[count].y; data[count-1].z=data[count].z; count++;
}printf("1"); count=temp-1; cout << "該學生資料已刪除" << endl; Exchang=1; //設置已修改數據標志 } } else cout << "學生資料未刪除" << endl; getch();
}}void student::taxis(){ int x,y,array[max]; int change; for(x=0;x<count;x++) array[x]=data[x].score=data[x].x+data[x].y+data[x].z; for(x=0;x<count-1;x++) for(y=0;y<count-1-x;y++) if(array[y]<array[y+1]) { change=array[y]; array[y]=array[y+1]; array[y+1]=change; } cout << "總分\t姓名\t學號\t\t地址\t\t高數\t英語\t計算機" << endl; for(x=0;x<count;x++) for(y=0;y<count;y++) if(array[x]==data[y].score) { cout << data[y].score << "\t" << data[y].name << "\t" << data[y].num << "\t" << data[y].adress << "\t" << data[y].x << "\t" << data[y].y << "\t" << data[y].z << endl; } getch(); Exchang=1; //設置已修改數據標志}
void student::show(){ cout << count << "\t" << data[count-1].name << "\t" << data[count-1].num << "\t" << data[count-1].adress << "\t\t" << data[count-1].x << "\t" << data[count-1].y << "\t" << data[count-1].z << endl;}
//////////////////////////////////////////////////////////////////////main.cppvoid main(){ student st; char *ch1,*ch2,chose; char flag[2],num[20],find[20],del[20]; char ch;
float x,y,z; time_t t; time(&t);
while(1) { system("cls"); cout << "------------------------學生管理系統------------------------" <<endl
<< " 1.輸入/添加學生資料 "<<endl << " 2.輸出學生資料" <<endl << " 3.查找 " <<endl << " 4.刪除" <<endl << " 5.總分排序" <<endl << " 6.退出" << endl << endl << " 請選擇你要的服務(1-6)"<< endl; cin >> chose; if(chose=='6') { break; } switch(chose) { case '1': // 輸入學生信息 { do { cout << "請輸入學生姓名:" << endl; ch1=new char[]; ch2=new char[]; cin >> ch1 ; cout << "請輸入學號:" << endl; cin >> num ; while(st.check_num(num)) { cout << "學號重復,請重新輸入" << endl; cin >> num; } cout << "請輸入地址:"<<endl; cin >> ch2 ; cout << "請輸入高數成績:"<<endl; cin >> x; cout << "請輸入英語成績:" <<endl; cin >> y; cout << "請輸入計算機成績:" <<endl; cin >> z; st.input(ch1,num,ch2,x,y,z); printf("\n是否繼續輸入學生信息?(\"y\"繼續)"); scanf("%s", flag); }while(strcmp(flag, "y") == 0); }break; case '2':// 輸出學生資料 { temp=count; count=1; cout << "序號\t姓名\t學號\t\t地址\t\t\t高數\t英語\t計算機" << endl; while(count<=temp) { st.show(); count++; } count--; getch(); }break; case '3': { cout << "請輸入你要查找學生的學號" << endl; cin >> find; st.find(find); }break; case '4': { cout << "請輸入你要刪除的學生學號" << endl; cin >> del; st.del(del); }break; case '5': { st.taxis(); }break;
default: { cout << "輸入錯誤!!!,請重新輸入" << endl; getch(); } } } cout << "感謝你的使用!\n" <<endl; getch();
}

Ⅸ 用c語言編寫學生信息管理系統

我這有伍族個差不多的,要嗎?是我寫的實訓作業
程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int man=0;
int j;
char str[20];
struct student
{
char id[11];
char name[10];
int n1;
int n2;
int n3;
int n4;
int n5;
int n6;
int n7;
int n8;
int n9;
int zong;
int ping;
}student[100],temp;
void read(void)
{
FILE *cj;
int i,k;
man=0;
while(1)
{
printf("請輸入要讀取的文件:\n");
scanf("%s",&str);
if((cj=fopen(str,"r"))==NULL)
{
printf("打唯爛開失敗\n");
}
else
{
break;
}
}
for(i=0;i<500;i++)
{
if(fscanf(cj,"%s %s %d %d %d %d %d %d %d %d %d",&student[i].id,&student[i].name,&student[i].n1,&student[i].n2,&student[i].n3,&student[i].n4,&student[i].n5,&student[i].n6,&student[i].n7,&student[i].n8,&student[i].n9)==-1)
{
break;
}
man=man+1;
}
printf("從%s讀取去了「%d」條記錄\n",str,man);
for(k=0;k<man;k++)
{
student[k].zong=student[k].n1+student[k].n2+student[k].n3+student[k].n4+student[k].n5+student[k].n6+student[k].n7+student[k].n8+student[k].n9;
}
for(i=0;i<man;i++)
{
student[i].ping=student[i].zong/9;
}
fclose(cj);
}
void write(void)
{
FILE *cj;
int i;
char me;
printf("請確認是否保存(是:y,否:任意鍵):\n");
scanf("%s",&me);
if(me=='y')
{
if((cj=fopen(str,"w"))==NULL)
{
printf("保存失敗\n");
}
for(i=0;i<man;i++)
{
fprintf(cj,"%s %s %d %d %d %d %d %d %d %d %d\n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9);
}
printf("存了「%d」條記錄到%s\n",man,str);
fclose(cj);
}
else
return;
}
void save(void)
{
FILE *cj;
int i;
char me;
printf("請輸入新的文件名:\n");
scanf("%s",&str);
printf("請確認是否保存(是:y,否:任意鍵):\n"指橘漏);
scanf("%s",&me);
if(me=='y')
{
if((cj=fopen(str,"w"))==NULL)
{
printf("保存失敗\n");
}
for(i=0;i<man;i++)
{
fprintf(cj,"%s %s %d %d %d %d %d %d %d %d %d\n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9);
}
printf("存了「%d」條記錄到%s\n",man,str);
fclose(cj);
}
else
return;
}
void print(void)
{
int i;
for(i=0;i<72;i++)
printf("*");
printf("\n");
printf(" | 學號 姓名 1 2 3 4 5 6 7 8 9 平均分 總分 | \n");
for(i=0;i<man;i++)
{
printf(" | %10s %-6s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d | \n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9,student[i].ping,student[i].zong);
}
for(i=0;i<72;i++)
printf("*");
printf("\n");
}
void inquiry(void)
{
int i;
char id[10];
while(1)
{
printf("請輸入要查人的學號或名字(輸入-1即返回上一級):\n");
scanf("%s",&id);
if(id[0]=='-'&&id[1]=='1')
{
printf("exit\n");
break;
}
else
{
for(i=0;i<man;i++)
{
if(strcmp(student[i].id,id)==0)
{
j=i;
break;
}
if(strcmp(student[i].name,id)==0)
{
j=i;
break;
}

j=-1;

}
if(j==-1)
{
printf("無此人\n");
}
else
{
printf(" | 學號 姓名 1 2 3 4 5 6 7 8 9 總分 平均分 | \n");
printf(" | %10s %-6s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d | \n",student[j].id,student[j].name,student[j].n1,student[j].n2,student[j].n3,student[j].n4,student[j].n5,student[j].n6,student[j].n7,student[j].n8,student[j].n9,student[i].ping,student[i].zong);
}
}
}
}
void fail(void)
{
int i;
printf("有不及格成績的學生為:\n");
for(i=0;i<man;i++)
{
if(student[i].n1<60||student[i].n2<60||student[i].n3<60||student[i].n4<60||student[i].n5<60||student[i].n6<60||student[i].n7<60||student[i].n8<60||student[i].n9<60)
{
printf(" | %10s %-6s %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d | \n",student[i].id,student[i].name,student[i].n1,student[i].n2,student[i].n3,student[i].n4,student[i].n5,student[i].n6,student[i].n7,student[i].n8,student[i].n9,student[i].ping,student[i].zong);
}
}
}
void compositor(void)
{
int i,k;
char m;
printf("請選擇干什麼排序:\n");
printf("1.成績1\n");
printf("2.成績2\n");
printf("3.成績3\n");
printf("4.成績4\n");
printf("5.成績5\n");
printf("6.成績6\n");
printf("7.成績7\n");
printf("8.成績8\n");
printf("9.成績9\n");
printf("0.總成績或平均成績\n");
scanf("%s",&m);
if(m=='0')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].zong<student[i+1].zong)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='1')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n1<student[i+1].n1)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='2')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n2<student[i+1].n2)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='3')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n3<student[i+1].n3)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='4')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n4<student[i+1].n4)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='5')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n5<student[i+1].n5)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='6')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n6<student[i+1].n6)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='7')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n7<student[i+1].n7)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='8')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n8<student[i+1].n8)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else if(m=='9')
{
for(k=man;k>0;k--)
{
for(i=0;i<k;i++)
{
if(student[i].n9<student[i+1].n9)
{
temp=student[i];
student[i]=student[i+1];
student[i+1]=temp;
}
}
}
}
else
printf("無此功能\n");
}
void raise(void)
{
printf("請輸入添加人的學號:\n");
scanf("%s",&student[man].id);
printf("請輸入添加人的姓名:\n");
scanf("%s",&student[man].name);
printf("請輸入添加人的成績1:\n");
scanf("%d",&student[man].n1);
printf("請輸入添加人的成績2:\n");
scanf("%d",&student[man].n2);
printf("請輸入添加人的成績3:\n");
scanf("%d",&student[man].n3);
printf("請輸入添加人的成績4:\n");
scanf("%d",&student[man].n4);
printf("請輸入添加人的成績5:\n");
scanf("%d",&student[man].n5);
printf("請輸入添加人的成績6:\n");
scanf("%d",&student[man].n6);
printf("請輸入添加人的成績7:\n");
scanf("%d",&student[man].n7);
printf("請輸入添加人的成績8:\n");
scanf("%d",&student[man].n8);
printf("請輸入添加人的成績9:\n");
scanf("%d",&student[man].n9);
student[man].zong=student[man].n1+student[man].n2+student[man].n3+student[man].n4+student[man].n5+student[man].n6+student[man].n7+student[man].n8+student[man].n9;
student[man].ping=student[man].zong/9;
man=man+1;
}
void alter(void)
{
int i;
char id[10];
printf("請輸入要修改人的學號:\n");
scanf("%s",&id);
for(i=0;i<man;i++)
{
if(strcmp(student[i].id,id)==0)
{
j=i;
break;
}

j=-1;

}
if(j==-1)
{
printf("無此人\n");
}
else
{
printf("請輸入要修改為的學號:\n");
scanf("%s",&student[j].id);
printf("請輸入要修改為的姓名:\n");
scanf("%s",&student[j].name);
printf("請輸入要修改為的成績1:\n");
scanf("%d",&student[j].n1);
printf("請輸入要修改為的成績2:\n");
scanf("%d",&student[j].n2);
printf("請輸入要修改為的成績3:\n");
scanf("%d",&student[j].n3);
printf("請輸入要修改為的成績4:\n");
scanf("%d",&student[j].n4);
printf("請輸入要修改為的成績5:\n");
scanf("%d",&student[j].n5);
printf("請輸入要修改為的成績6:\n");
scanf("%d",&student[j].n6);
printf("請輸入要修改為的成績7:\n");
scanf("%d",&student[j].n7);
printf("請輸入要修改為的成績8:\n");
scanf("%d",&student[j].n8);
printf("請輸入要修改為的成績9:\n");
scanf("%d",&student[j].n9);
student[j].zong=student[j].n1+student[j].n2+student[j].n3+student[j].n4+student[j].n5+student[j].n6+student[j].n7+student[j].n8+student[j].n9;
student[j].ping=student[j].zong/9;
}
}
void deletes()
{
int i,k;
char id[10];
printf("請輸入要刪除人的學號:\n");
scanf("%s",&id);
for(i=0;i<man;i++)
{
if(strcmp(student[i].id,id)==0)
{
j=i;
break;
}

j=-1;

}
if(j==-1)
{
printf("無此人\n");
}
else
{
for(k=j;k<man;k++)
{
student[j]=student[j+1];
j=j+1;
}
man=man-1;
}
}
void menu(void)
{
int i;
printf("\n");
for(i=0;i<10;i++)
printf(" ");
for(i=0;i<60;i++)
printf("*");
for(i=0;i<9;i++)
printf(" ");
printf("\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 1.顯示學生成績信息 6.查詢不及格學生信息 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 2.按成績由高到低排序 7.修改學生成績信息 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 3.添加學生成績信息 8.讀取文件 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 4.刪除學生成績信息 9.保存文件 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# 5.查詢學生成績信息 -. 另存為 #\n");
for(i=0;i<10;i++)
printf(" ");
printf("# +.退出 #\n");
for(i=0;i<10;i++)
printf(" ");
for(i=0;i<60;i++)
printf("*");
for(i=0;i<9;i++)
printf(" ");
printf("\n");
}
int main(void)
{
char i;
read();
menu();
while(1)
{
printf("請輸入要選擇的需要功能的序列號(輸入0顯示菜單):\n");
scanf("%s",&i);
if(i=='1')
{
print();
}
else if(i=='2')
{
compositor();
print();
}
else if(i=='3')
{
raise();
print();
}
else if(i=='4')
{
deletes();
print();
}
else if(i=='5')
{
inquiry();
}
else if(i=='6')
{
fail();
}
else if(i=='7')
{
alter();
print();
}
else if(i=='8')
{
read();
}
else if(i=='9')
{
write();
}
else if(i=='0')
{
menu();
}
else if(i=='+')
{
break;
}
else if(i=='-')
{
save();
}
else
{
printf("無此功能,請重新輸入序列號\n");
}
}
return 0;
}
記事本文件:你可以隨意起名,但要放在和程序同目錄
0615438101 顧佳 44 67 72 60 66 65 93 82 67
0615438103 金一宇 60 77 75 75 78 77 97 74 76
0615438104 李陽濤 50 76 66 73 74 80 92 89 74
0615438105 馬凱 66 76 77 66 75 72 95 82 75
0615438106 史超 47 71 65 61 85 72 89 83 70
0615438108 徐磊 60 75 66 80 76 80 92 68 74
0615438109 楊浩 60 81 70 91 83 72 93 72 78
0615438110 於澤 61 75 78 70 87 73 84 92 77
0615438111 張昊 60 71 57 82 72 63 86 38 67
0615438112 張政 60 67 69 80 66 61 87 88 73
0615438114 周艨 61 69 71 38 74 77 76 89 67
0615438131 張楠 86 74 72 90 80 81 97 80 84
0615438132 王凡 29 68 48 35 46 76 88 62 54

Ⅹ 用C語言編寫一個學生管理系統。

概述

  • 單純只用多個數組管理學生成績信息,不使用結構體,該程序最主要的難點是依據學號或總成績對學生信息進行排序,藉助了臨時數組來標記排好序的下標。

  • 運行結果如下:

輸入數據:

貼上代碼(有點多)

#include <stdio.h>

#include <stdlib.h> //exit函數頭文件

#include <string.h> //字元串相關操作頭文件

#define MAX_STUDENT 30 //最大學生數

//函數聲明,本程序共10個子函數,每個函數對應一個操作

void student_scanf(int n);

void student_printf(int n);

int student_find_name(int n);

int student_find_num(int n);

void student_sort_num(int n);

void student_sort_sum(int n);

int student_alter_num(int n);

int student_alter_name(int n);

int student_delete_num(int n);

int student_delete_name(int n);

//全局數組變數,用於存儲學生信息

char names[MAX_STUDENT][50];

int math[MAX_STUDENT];

int english[MAX_STUDENT];

int computer[MAX_STUDENT];

int sum[MAX_STUDENT];

int num[MAX_STUDENT];

//以下變數用於學生信息數組排序,作為臨時數組

int temp_num[MAX_STUDENT];

char temp_names[MAX_STUDENT][50];

int temp_math[MAX_STUDENT];

int temp_english[MAX_STUDENT];

int temp_computer[MAX_STUDENT];

int temp_sum[MAX_STUDENT];

//sort數組存儲排好序的學號或姓名下標

int sort[MAX_STUDENT];

//循環全局變數

int i, j;

//main主函數

int main(void)

{

int choice,n;

while (1)

{

printf("************************************* ");

printf("歡迎使用學生成績管理系統 ");

printf("[1] 輸入所有學生信息 ");

printf("[2] 輸出所有學生成績 ");

printf("[3] 按學號查找某個學生信息 ");

printf("[4] 按姓名查找某個學生信息 ");

printf("[5] 按學號對學生排序 ");

printf("[6] 按總成績對學生排序 ");

printf("[7] 按學號修改某個學生信息 ");

printf("[8] 按姓名修改某個學生信息 ");

printf("[9] 按學號刪除某個學生信息 ");

printf("[10] 按姓名刪除某個學生信息 ");

printf("[0] 退出程序 ");

printf("請輸入您的選擇(0 - 9):");

scanf("%d",&choice);

printf("**************************************) ");

switch (choice)

{

case 1://錄入;

printf("請輸入錄入的學生信息數: ");

scanf("%d",&n);

student_scanf(n);

break;

case 2://輸出;

student_printf(n);

break;

case 3://根據學號查找

student_find_num(n);

break;

case 4://根據姓名查找

student_find_name(n);

break;

case 5://按學號排序

student_sort_num(n);

break;

case 6://按姓名排序

student_sort_sum(n);

break;

case 7://按學號修改

student_alter_num(n);

break;

case 8://按姓名修改

student_alter_name(n);

break;

case 9://按學號刪除

student_delete_num(n);

n--;

break;

case 10://按姓名刪除

student_delete_name(n);

n--;

break;

case 0://退出程序

printf("退出程序 ");

printf("程序結束,謝謝使用! ");

exit(0);

default:

printf("您輸入的菜單有誤。請重新輸入! ");

}

}

return 0;

}

//1.輸入信息

void student_scanf(int n)

{

for (i = 0; i<n; ++i)

{

printf(" 請輸入第%d個學生的信息: ", i + 1);

printf(" 學號:");

scanf("%d", &num[i]);

printf(" 姓名:");

scanf("%s", names[i]);

printf(" 數學成績:");

scanf("%d", &math[i]);

printf(" 英語成績:");

scanf("%d", &english[i]);

printf(" 計算機成績:");

scanf("%d", &computer[i]);

//計算總成績

sum[i] = math[i] + english[i] + computer[i];

}

}

//2.列印信息

void student_printf(int n)

{

printf(" 學號 姓名 數學成績 英語成績 計算機成績 總成績 ");

printf("---------------------------------------------------------- ");

for (i = 0; i<n; ++i)

{

printf("%d %s %d %d %d %d ", num[i], names[i], math[i], english[i], computer[i], sum[i]);

}

printf("------------------------------------------------------- ");

}

//3.按學號查找

int student_find_num(int n)

{

int nums;

int result;

printf("請輸入待查找的學生學號:");

scanf("%d",&nums);

result= -1;

for (i = 0; i<n; ++i)

{

if (nums == num[i])

{

result = i;

break;

}

}

//最後判斷q值

if (result == -1)

{

printf("沒有該學生信息! ");

return 0;

}

else

{

//先列印表頭

printf(" 學號 姓名 數學成績 英語成績 計算機成績 總成績 ");

//再列印數據

printf("%d %s %d %d %d %d ", num[result], names[result], math[result], english[result], computer[result], sum[result]);

printf("列印出查找結果! ");

}

return 1;

}

//4.用姓名查找成績

int student_find_name(int n)

{

char name[200];

int result;

printf("請輸入待查找的學生姓名:");

scanf("%s", name);

result = -1;

for (i = 0; i<n; ++i)

{

if (strcmp(name, names[i]) == 0)

{

result = i;

break;

}

}

if (result == -1)

{//未找到結果

printf("沒有該學生信息! ");

return 0;

}

else//找到結果

{

printf(" 學號 姓名 數學成績 英語成績 計算機成績 總成績 ");

printf("%d %s %d %d %d %d ", num[result], names[result], math[result], english[result], computer[result], sum[result]);

printf("已完成查找! ");

}

return 1;

}

//5.按學號排序

void student_sort_num(int n)

{

int min,max;

for(i=0; i<n; ++i) //復制臨時數組

{

temp_num[i] = num[i];

}

max = 0; //查找學號最大值,將其下標存至sort數組的最後一個值中

for(j=1; j<n; j++)

{

if(temp_num[max]<temp_num[j])

max = j;

}

sort[n-1] = max; //sort數組的最後一個數

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

{

min = i; //查找學號最小值

for(j=0; j<n; ++j)

{

if(temp_num[min]>temp_num[j])

min = j;

}

//sort數組記錄排序的學生信息的下標

sort[i] = min;

temp_num[min] = temp_num[max]; //利用臨時數組將查找過的學生信息的學號設為最大值,排除查找干擾

}

for(i=0; i<n; ++i) //再復制一次臨時數組

{

temp_num[i] = num[i];

strcpy(temp_names[i],names[i]);

temp_math[i] = math[i];

temp_english[i] = english[i];

temp_computer[i] = computer[i];

temp_sum[i] = sum[i];

}

for(i=0; i<n; i++) //按照下標對原數組進行修改

{

num[i] = temp_num[sort[i]];

strcpy(names[i],temp_names[sort[i]]);

math[i] = temp_math[sort[i]];

english[i] = temp_english[sort[i]];

computer[i] = temp_computer[sort[i]];

sum[i] = temp_sum[sort[i]];

}

printf("排序完畢,請按菜單鍵2查看排序結果! ");

return ;

}

//6.按總成績排序

void student_sort_sum(int n)

{

int min,max;

for(i=0; i<n; ++i) //復制臨時數組

{

temp_sum[i] = sum[i];

}

max = 0; //查找總成績最大值,將其下標存至sort數組的最後一個值中

for(j=1; j<n; j++)

{

if(temp_sum[max]<temp_sum[j])

max = j;

}

sort[n-1] = max; //sort數組的最後一個數

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

{

min = i; //查找總成績最小值

for(j=0; j<n; ++j)

{

if(temp_sum[min]>temp_sum[j])

min = j;

}

//sort數組記錄排序的學生信息的下標

sort[i] = min;

temp_sum[min] = temp_sum[max]; //利用臨時數組將查找過的學生信息的總成績設為最大值,排除查找干擾

}

for(i=0; i<n; ++i) //再復制一次臨時數組

{

temp_num[i] = num[i];

strcpy(temp_names[i],names[i]);

temp_math[i] = math[i];

temp_english[i] = english[i];

temp_computer[i] = computer[i];

temp_sum[i] = sum[i];

}

for(i=0; i<n; i++) //按照下標對原數組進行修改

{

num[i] = temp_num[sort[i]];

strcpy(names[i],temp_names[sort[i]]);

math[i] = temp_math[sort[i]];

english[i] = temp_english[sort[i]];

computer[i] = temp_computer[sort[i]];

sum[i] = temp_sum[sort[i]];

}

printf("排序完畢,請按菜單鍵2查看排序結果! ");

return ;

}

//7.按學號修改學生信息

int student_alter_num(int n)

{

int nums;

int result;

printf("請輸入待修改的學生學號:");

scanf("%d",&nums);

result= -1;

for (i = 0; i<n; ++i)

{

if (nums == num[i])

{

result = i;

break;

}

}

//最後判斷q值

if (result == -1)

{

printf("沒有該學生信息! ");

return 0;

}

else //修改信息值

{

printf("請重新輸入該學生信息: ");

printf("學號: ");

scanf("%d",&num[result]);

printf("姓名: ");

scanf("%s",names[result]);

printf("數學成績: ");

scanf("%d",&math[result]);

printf("英語成績: ");

scanf("%d",&english[result]);

printf("計算機成績: ");

scanf("%d",&computer[result]);

sum[result] = math[result] + english[result] + computer[result];

}

return 1;

}

//8.按姓名修改學生信息

int student_alter_name(int n)

{

char name[50];

int result;

printf("請輸入待修改的學生姓名:");

scanf("%s",name);

result= -1;

for (i = 0; i<n; ++i)

{

if (strcmp(name,names[i])==0)

{

result = i;

break;

}

}

//最後判斷q值

if (result == -1)

{

printf("沒有該學生信息! ");

return 0;

}

else //修改信息值

{

printf("請重新輸入該學生信息: ");

printf("學號: ");

scanf("%d",&num[result]);

printf("姓名: ");

scanf("%s",names[result]);

printf("數學成績: ");

scanf("%d",&math[result]);

printf("英語成績: ");

scanf("%d",&english[result]);

printf("計算機成績: ");

scanf("%d",&computer[result]);

sum[result] = math[result] + english[result] + computer[result];

}

return 1;

}

//9.按學號刪除學生信息

int student_delete_num(int n)

{

int nums;

int result;

printf("請輸入待刪除的學生學號:");

scanf("%d",&nums);

result= -1;

for (i = 0; i<n; ++i)

{

if (nums == num[i])

{

result = i;

break;

}

}

//最後判斷q值

if (result == -1)

{

printf("沒有該學生信息! ");

return 0;

}

else //刪除當前學生信息即為將數組從result的位置依次前挪一個位置

{

for(i=result; i<n-1; ++i) //最後在main函數中,要將n的值減1

{

num[i] = num[i+1];

strcpy(names[i],names[i+1]);

math[i] = math[i+1];

english[i] = english[i+1];

computer[i] = computer[i+1];

sum[i] = sum[i+1];

}

}

return 1;

}

//10.按姓名刪除學生信息

int student_delete_name(int n)

{

char name[50];

int result;

printf("請輸入待刪除的學生姓名:");

scanf("%s",name);

result= -1;

for (i = 0; i<n; ++i)

{

if (strcmp(name,names[i])==0)

{

result = i;

break;

}

}

//最後判斷q值

if (result == -1)

{

printf("沒有該學生信息! ");

return 0;

}

else //刪除當前學生信息即為將數組從result的位置依次前挪一個位置

{

for(i=result; i<n-1; ++i) //最後在main函數中,要將n的值減1

{

num[i] = num[i+1];

strcpy(names[i],names[i+1]);

math[i] = math[i+1];

english[i] = english[i+1];

computer[i] = computer[i+1];

sum[i] = sum[i+1];

}

}

return 1;

}