当前位置:文档之家› C语言数据库-学生成绩统计管理系统

C语言数据库-学生成绩统计管理系统

学生成绩统计管理系统C语言数据结构课程作品

指导老师:

学生:

学号:

班级:

一、代码

#include"stdafx.h"

#include

#include

#include

#include

#include

#include

#include

struct grade

{

int score;

struct grade *next;

}; /*定义成绩的结构*/

struct address{

char stu_num[4]; /*学号*/

char hname[10]; /*性别*/

char ename[20]; /*姓名*/

char depart[30]; /*系别*/

char paddress[30]; /*地址*/

char phone[13] /*联系电话*/;

struct grade *head;

struct address *next;

} ;

void loaddata (struct address **had);

void printm (struct address *head);

struct address * seek (struct address *head);

void revise (struct address *hp);

void delate (struct address **head);

void saveda (struct address *tou );

void addnew (struct address **had );

void moveg (int i,struct grade **move);

void gotoxy(int x,int y);

void sortp(struct address **head);

int main ( void )

{

char ch;

int c;

struct address *head=NULL;

loaddata(&head);

do

{

system("cls");

printf(" \n");

printf("学生信息与成绩统计:\n");

printf(" 岳鹏程制作\n"); printf(" ===============================================\n"); printf("‖ Menu: ‖\n"); printf("‖ 1:print all the personal information. ‖\n"); printf("‖ 2:insert some or one person. ‖\n"); printf("‖ 3:revire some information. ‖\n"); printf("‖ 4:delate some information or a person. ‖\n"); printf("‖ 5:exit. ‖\n"); printf(" ===============================================\n"); printf("\tInput :");

do

{

scanf("%d",&c);

getchar( );

}while(c<0||c>6);

switch ( c )

{

case 1:

printm(head);

break;

case 2:

addnew(&head);

break;

case 3:

revise(head);

break;

case 4:

delate(&head);

break;

break;

case 5:

return 0;

default:

break;

}

fflush(stdin);

printf("continue or not: input y or n\n");

ch=getchar( );

saveda(head);

}while(ch=='y'||ch=='Y');

return 0;

}

void loaddata (struct address **had )

{

FILE *afhead;

FILE *gfhead;

struct address *p1,*hp1=NULL,*head=NULL;

struct grade *p2 , *hp2 = NULL;

int i=0;

int j=6;

if( !(afhead = fopen("d:\\information.dat","rb")))

{

return;

}

if( !(gfhead = fopen("d:\\grade.dat" , "rb")) )

{

return;

}

while (!feof(afhead))

{

p1 = (struct address *)malloc(sizeof(struct address));

fread(p1,sizeof(struct address),1,afhead);

if(feof(afhead))

{

if(!p1)

free(p1);

break;

}

if(i==0)

{

p1->next = NULL;

p1->head = NULL;

head = p1;

hp1 = p1;

i++;

} /*使头指针指向第一个创建的节点*/ else

{

p1->next = NULL;

p1->head = NULL;

hp1->next = p1;

hp1 = hp1->next;

}

}

*had = head;

p1 = *had;

/*成绩是后进先出*/

while (!feof(gfhead))

{

do

{

p2=(struct grade *)malloc(sizeof(struct grade));

fread(p2,sizeof(struct grade),1,gfhead);

p2->next = hp2;

hp2 = p2;

j --;

}while( j > 0 );

if( !feof(gfhead) && p1 != NULL)

{

p1 -> head = hp2;

p1 = p1 -> next;

}

}

fclose(afhead);

fclose(gfhead);

}

void printm (struct address *head)

{

int i=0 , j;

float iscore;

struct grade *ghd=NULL;

struct address *hd=NULL;

hd = head;

system("cls");

if (hd==NULL)

{

printf("\t\t=== No sourse in the file! ===");

return ;

}

while (hd != NULL)

{

gotoxy(1,i+1);

printf("==========================================================\n" );

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

{

gotoxy(1,i+1+j);

printf("‖");

gotoxy(58,i+1+j);

printf("‖");

}

gotoxy(1,i+6);

printf("\n==========================================================\ n");

gotoxy(5,i+2); printf("Nummber: %s" , hd->stu_num);

gotoxy(30,i+2); printf("Name-spelling: %s" , hd->ename );

gotoxy(5,i+3); printf("Sex:%s" , hd->hname );

gotoxy(30,i+3); printf("Department: %s", hd->depart);

gotoxy(5,i+4); printf("Address: %s" , hd->paddress);

gotoxy(5,i+5); printf("Phone nummber: %s\n", hd->phone);

printf("\n==========================================================\ n");

printf("\tHis\\Her score is : \n");

ghd=hd->head;

printf("name 地理生物物理英语数学语文\n"); printf("%s ",hd->ename);

while ( ghd != NULL )

{

printf(" %d\t" , ghd->score);

iscore += ghd -> score;

ghd = ghd->next;

}

printf(" \n ");

hd = hd->next;

i = i + 10;

}

}

void delate (struct address **head)

{

char cinput[20];

struct address *PRE,*TARGE;

TARGE = (*head);

if(!TARGE)

{

printf("========= No any information!!");

return;

}

fflush(stdin);

printf(" Input the name or student nummber you want to delate:\t"); scanf(" %s" , cinput);

while(stricmp(cinput, TARGE->stu_num) && stricmp(cinput ,TARGE->ename) && TARGE != NULL)

{

PRE = TARGE;

TARGE=TARGE->next;

}

if (TARGE == NULL)

{

printf("==== No this information! ====\n");

return ;

}

if(TARGE == (*head) )

{

(*head) = (*head) -> next;

return ;

}

else

{

PRE->next = TARGE->next;

}

if(!TARGE)

free(TARGE);

}

//*************修改信息

void revise (struct address *head)

{

int ch;

char cinput[20];

char choice;

struct address *TARGE = NULL;

struct grade *move;

do {

system("cls");

printf(" Input the name or student nummber you want to delate:\t"); fflush(stdin);

scanf(" %s" , cinput);

TARGE = head;

while(stricmp( cinput, TARGE->stu_num) &&

stricmp(cinput ,TARGE->ename) && TARGE != NULL)

{

TARGE = TARGE->next;

}

if (TARGE == NULL) return;

printf("input the command:\n1->revise the sex;\t\t" );

printf("2->revise the ename;\n3->revise the student nummber;\t\t");

printf("4->revise the depart;\n5->revise the address;\t\t"); printf("6->revise the phone\n7->revise the geography;\t\t");

printf("8-.revise the biology\n9->revise the physics;\t\t"); printf("10->revise the english;\n11->revise the maths ;\t\t"); printf("12->to revise the chinese.\n");

fflush( stdin);

do{

scanf("%d",&ch);

}while(ch>12||ch<0);

switch(ch)

{

case 1 :

printf("enter the your sex male or female :\n"); scanf("%s" , TARGE->hname);

break;

case 2 :

printf("enter the name in Spell:\n");

scanf("%s" , TARGE->ename);

break;

case 3 :

printf("enter the Student nummer:\n");

scanf("%s" , &TARGE->stu_num);

break;

case 4 :

printf("input your Department:\n");

scanf("%s" , TARGE->depart);

break;

case 5 :

printf("input your present Address:\n");

scanf("%s" , TARGE->paddress);

break;

case 6 :

printf("input your mobie nummer:\n");

scanf("%s" , TARGE->phone);

break;

case 7 :

printf("input your geography score\n");

scanf("%d" , &(move->score));

break;

case 8 :

moveg (8, &move);

printf("input your biology score\n");

scanf("%d" , &(move->score));

break;

case 9 :

moveg (9, &move);

printf("input your physics score:\n");

scanf("%d" , &(move->score));

break;

case 10:

moveg (10, &move);

printf("input your english score:\n");

scanf("%d" , &(move->score));

break;

case 11:

moveg (11, &move);

printf("input your maths score:\n");

scanf("%d" , &(move->score));

break;

case 12:

moveg (12, &move);

printf("input your chinese score:\n");

scanf("%d" , &(move->score));

move=move->next;

break;

default : ;

}

fflush(stdin);

printf("if you want to revise other detail formation input y\n"); scanf("%c" , &choice);

}while(choice == 'y' || choice == 'Y');

}

void moveg (int i,struct grade **move)

{

for(i = i - 7; i > 0; i--)

{

( *move ) = ( *move ) -> next;

}

}

//*******************删除原来的记录并保存现在的 ok!

void saveda (struct address *tou)

{

FILE *afhead , *gfhead;

struct grade *gcu;

struct address *tail = tou;

if((afhead = fopen("d:\\information.dat" , "wb")) == NULL) {

printf("file error!\n");

return;

}

if ((gfhead = fopen("d:\\grade.dat","wb")) == NULL)

{

printf("file error!\n");

return;

} /*打开保存数据的文件*/

while (tail != NULL)

{

fwrite(tail , sizeof(struct address) , 1 , afhead);

gcu = tail -> head;

while (gcu != NULL)

{

fwrite(gcu , sizeof(struct grade) , 1 , gfhead);

gcu = gcu -> next;

}

tail = tail -> next;

}

fclose(afhead);

fclose(gfhead);

}

void addnew (struct address **head )

{

struct address *phead = NULL , *pTempNode = NULL;

struct grade *gh = NULL;

pTempNode=(struct address *)malloc(sizeof(struct address));

printf("input num (<10000): ");

scanf("%s" , &pTempNode->stu_num);

printf("input your sex male or female: ");

printf("input name in spelling: ");

scanf("%s" , pTempNode->ename);

printf("input your department: ");

scanf("%s" , pTempNode->depart);

printf("input your address: ");

scanf("%s" , pTempNode->paddress);

printf("input your phone nummber: ");

scanf("%s" , pTempNode->phone);

pTempNode -> next = NULL;

pTempNode -> head = NULL;

fflush(stdin);

printf("input chinese:");

pTempNode->head = (struct grade *)malloc(sizeof(struct grade)); scanf("%d" , &pTempNode->head->score);

gh = pTempNode->head;

printf("input maths score: ");

gh -> next = (struct grade *)malloc(sizeof(struct grade));

gh = gh -> next;

scanf("%d" , &gh -> score);

printf("input English score: ");

gh->next = (struct grade *)malloc(sizeof(struct grade));

gh = gh -> next;

scanf("%d" ,&gh->score);

printf("input physics score: ");

gh->next = (struct grade *)malloc(sizeof(struct grade));

gh = gh->next ;

scanf("%d" , &gh->score);

printf("input bilolgy score: ");

gh->next = (struct grade *)malloc(sizeof(struct grade));

gh = gh->next ;

scanf("%d" ,&gh->score);

printf("input geography score: ");

gh->next = (struct grade *)malloc(sizeof(struct grade));

gh->next->next = NULL ;

if((*head) == NULL)

{

(*head) = pTempNode;

}

else

{

phead = (*head);

while(phead != NULL && phead->next != NULL)

{

phead = phead->next;

}

phead->next = pTempNode;

}

printf("you have add a new person!");

}

二、设计思路

“任意增删”实现主要是靠链表。

“学生”是一种支持链表的结构体。

全局有一个“学生”的链表。

然后每个“学生”object下面又有各自的一个“科目”的链表。(printf打印菜单文字内容,scanf获取输入等)。

相关主题
文本预览
相关文档 最新文档