導航:首頁 > 編程語言 > 學籍管理系統程序

學籍管理系統程序

發布時間:2024-05-21 12:11:58

『壹』 C語言課程設計:學生學籍管理系統。有誰有代碼給我做個參考嗎謝謝了,C語言和C++的都可以。

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

typedef struct stud //學生信息結構
{
long num;
char name[20];
float score;
}Stud;

typedef struct node
{
Stud student;
struct node *next;
}Node;
Node *head=NULL;
void read(void);
void inser(long b);
void print();
void find(long b);
void searchname(char *s);
Node * del(long n);
void sort(int flag);
void menu();

void main()
{
char choose;
int flag=1;

while (flag)
{
menu(); //調用功能菜單函數,顯示菜單項。
printf(" 請選擇:");
choose=getchar();

switch(choose)
{ 1
case '1': read(); //調用建立鏈表的函數;輸出鏈表信息;
print();
printf("\nPress any key Continue ");
//getchar();
getchar();
break;
case '2': //調用按學號查找學生信息的函數;並輸出查找結果信息;
long c;
printf("input the number you want to find:");
scanf("%ld",&c);
find(c);
printf("\nPress any key Continue.");
getchar();
break;
case '3':
//調用按姓名查找學生信息的函數;並輸出查找結果信息;
char s[20];
printf("input the name you want to find:");
scanf("%s",s);
searchname(s);
printf("\n Press any key Continue.");
getchar();
getchar();
break;
case '4':
//調用根據學號刪除某個學生信息的函數;並輸出刪除後的鏈表信息;
Node *h;
long n;
printf("input the number you want to delete:");
scanf("%ld",&n);
h=del(n);
if(h==NULL) printf("No find the student \n");
else print();
printf("\n Press any key Continue.");
getchar();
getchar();
break;
case '5':
//調用插入新的學生信息的函數;並輸出插入後的鏈表信息;
long a;
printf("input the number for the new:\n");
scanf("%ld",&a);
inser(a); 2
print();
printf("\n Press any key Continue.");
getchar();
getchar();
break;
case '6':
//調用按分數降序排序輸出的函數;並輸出排序後的鏈表信息;
sort(1);
print();
sort(0);
printf("\nPress any key Continue.");
getchar();
getchar();
break;
case '0':
//結束程序運行!
flag=0;
printf("\n *** The End! ***\n");
break;
default: printf("\n Wrong Selection !(選擇錯誤,重選)\n");
getchar();
}
}
}

void menu() //綜合作業功能菜單
{
printf(" \n 學 生 信 息 管 理 系 統\n");
printf(" \n 菜 單\n\n");
printf(" \n 1. 建 立 鏈 表 並 顯 示 \n");
printf(" \n 2. 查 找 某 學 號 的 學 生 信 息 \n");
printf(" \n 3. 查 找 某 姓 名 的 學 生 信 息 \n");
printf(" \n 4. 刪 除 某 個 學 號 的 學 生\n");
printf(" \n 5. 插 入 新 的 學 生 信 息 \n");
printf(" \n 6. 按 分 數 降 序 排 序 輸 出 \n");
printf(" \n 0. 退 出\n\n");
}

void read(void)
{
long a;
printf("input the number:");
scanf("%ld",&a);
while(a>0){ 3
inser(a);
printf("input the number:");
scanf("%ld",&a);
}
}
void inser(long b)
{

Node *last,*current,*p;
current=head;
while(current!=NULL&&b>current->student.num){
last=current;
current=current->next;
}

if(current==NULL||b<current->student.num){
printf("input the name,score:");
p=(Node *)malloc(sizeof(Node));
p->student.num=b;
scanf("%s%f",p->student.name,&p->student.score);
p->next=NULL;
if(current==head){
p->next=head;
head=p;
}
else{
p->next=current;
last->next=p;
}
}
else if(b==current->student.num)
printf("error input a different number:");

}

void print()
{
Node *p=head;
printf("學號 姓名 成績:\n");
while(p!=NULL){
printf("%ld %s %f\n",p->student.num,p->student.name,p->student.score);
p=p->next;
} 4
printf("\n");
}
void find(long b)
{
Node *p=head;
while(p!=NULL&&b!=p->student.num)
p=p->next;
if(!p) printf("No found\n");
else {
printf("學號 姓名 成績\n");
printf("%ld %s %f\n",p->student.num,p->student.name,p->student.score);
}

}

void searchname(char *s)
{
Node *p=head;
int flag=0;
printf("學號 姓名 成績:\n");
while(p!=NULL)
{
if(strcmp(p->student.name,s)==0)
{
printf("%ld %s %f\n",p->student.num,p->student.name,p->student.score);
flag=1;
p=p->next;
continue;
}
else p=p->next;
}
if(!flag) printf("No find");
}
Node * del(long n)
{
Node *p=head,*last;
while(p->student.num!=n){
last=p;
p=p->next;
}
if(p==NULL) return p;
else if(p==head) head=p->next;
else last->next=p->next; 5
return head;
}
void sort(int flag)
{
/*flag==1 按分數排序 else 按學號排序*/
Node *p1,*p2,*k;
float t1;
long t2;
char s[20];
for(p1=head;p1->next;p1=p1->next)
{
k=p1;
for(p2=p1->next;p2;p2=p2->next)
if(flag==1&&k->student.score<p2->student.score||!flag&&k->student.num>p2->student.num)
k=p2;
if(k!=p1){
t1=p1->student.score;
p1->student.score=k->student.score;
k->student.score=t1;
t2=p1->student.num;
p1->student.num=k->student.num;
k->student.num=t2;
strcpy(s,p1->student.name);
strcpy(p1->student.name,k->student.name);
strcpy(k->student.name,s);
}
}
}
給你看看

閱讀全文

與學籍管理系統程序相關的資料

熱點內容
學韓語用什麼app 瀏覽:478
110固態硬碟分區win10 瀏覽:317
怎麼恢復系統文件 瀏覽:358
數據線轉換器多少錢 瀏覽:274
美國隊長qq皮膚多少錢 瀏覽:630
win8word文檔在哪 瀏覽:180
甘肅省人事局文件在哪裡 瀏覽:689
spss安裝輸入代碼 瀏覽:546
網路語言知乎 瀏覽:596
iphoneicloud無法顯示 瀏覽:112
ict程序包 瀏覽:729
java有哪些條件語句 瀏覽:345
冒險島120級去哪裡升級 瀏覽:511
手機輸入法聲音文件 瀏覽:876
下劃線哪個app 瀏覽:48
win10h1z1切換桌面 瀏覽:911
js定義集合數組 瀏覽:153
win10企業關閉自動更新 瀏覽:920
js擴展對象 瀏覽:370
受控文件的章印內容怎麼寫 瀏覽:463

友情鏈接