最近很多小夥伴私信喊我,有沒有【學生成績管理系統】的源碼呀?
of course!作爲編程百寶箱,區區源碼只是我的冰山一角~
直接呈上代碼:
#define _CRT_SECURE_NO_DEPRECATE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<windows.h>
struct stu{
int id[10]; //學號
char name[20]; //姓名
int score; //分數
};
struct STU
{
//int data;
struct stu data;
struct STU* next;
};
//創建結構體表頭
struct STU* creatlist()//創建鏈表
{
struct STU* head = (struct STU*)malloc(sizeof(struct STU));
head->next = NULL;
return head;
}
//創建結點
struct STU* createNode(struct stu data)
{
struct STU* newNode = (struct STU*)malloc(sizeof(struct STU));
newNode->data = data;
newNode->next = NULL;
return newNode;
}
//插入結點
void insertNodeByhead(struct STU* head, struct stu data)
{
struct STU* newNode = createNode(data);
newNode->data = data;
head->next = newNode;
}
//指定位置刪除
void deleteNode(struct STU* head, char* name)
{
struct STU* posNode = head->next;
struct STU* posFrontNode = head;
if (posNode == NULL)
{
printf("數據爲空,無法刪除!\n");
return;
}
while (strcmp(posNode->data.name, name))
{
posFrontNode = posNode;
posNode = posFrontNode->next;
if (posNode == NULL)
{
printf("未找到指定位置,無法刪除!\n");
return;
}
}
posFrontNode->next = posNode->next;
free(posNode);
}
//查找
struct STU* searchData(struct STU* head, char *name)
{
struct STU* p = head->next;
if (p == NULL)
return NULL;
while (strcmp(p->data.name, name))
{
p = p->next;
}
return p;
}
//文件讀操作
void readFile(struct STU* head, char *fileName)
{
FILE *fp;
struct stu data;
fp = fopen(fileName, "r");
if (fp == NULL)
{
fp = fopen(fileName, "w+");
}
while (fscanf(fp, "%d\t%s\t%d\n", &data.id, data.name, &data.score) != EOF)
{
insertNodeByhead(head, data);
}
fclose(fp);
}
//文件寫操作
void writeFile(struct STU* head, char *FileName)
{
FILE *fp;
fp = fopen(FileName, "w");
struct STU* p = head->next;
while (p)
{
fprintf(fp, "%d\t%s\t%d\n", p->data.id, p->data.name, p->data.score);
p = p->next;
}
fclose(fp);
}
//打印鏈表
void printlist(struct STU* head)
{
struct STU* p = head->next;
printf("學號\t姓名\t分數\n");
while (p)
{
printf("%d\t%s\t%d\n", p->data.id, p->data.name, p->data.score);
p = p->next;
}
printf("\n");
}
void menu()
{
system("cls");//清屏
system("color b");//修改字體顏色
printf("\n\n\n\n");
printf("\t************************************\n");
printf("\t| 歡迎來到學生信息管理系統 |\n");
printf("\t|**********************************|\n");
printf("\t|** 1:錄入學生信息 **|\n");
printf("\t|** 2:顯示學生信息 **|\n");
printf("\t|** 3:增加學生信息 **|\n");
printf("\t|** 4:刪除學生信息 **|\n");
printf("\t|** 5:查詢學生信息 **|\n");
printf("\t|** 6:修改學生信息 **|\n");
printf("\t|** 7:退出學生系統 **|\n");
printf("\t************************************\n");
printf("\n \t請輸入您要進行的操作(1~~7):");
}
struct STU* List = creatlist();
void keydown()
{
int n = 0;
struct stu data;
struct STU*p = NULL;
scanf("%d", &n);
switch (n)
{
//增加一個學生信息
case 1:
printf("******錄入學生信息******\n");
printf("請輸入你要添加的學生學號,姓名,分數:");
fflush(stdin);//清空緩衝區
scanf("%d\t%s\t%d\n", &data.id, data.name, &data.score);
insertNodeByhead(List, data);
break;
case 2:
printf("******顯示學生信息******\n");
printlist(List);
break;
case 3:
printf("******增加學生信息******\n");
printf("請輸入你要添加的學生學號,姓名,分數:");
fflush(stdin);//清空緩衝區
scanf("%d\t%s\t%d\n", &data.id, data.name, &data.score);
insertNodeByhead(List, data);
break;
case 4:
printf("******刪除學生信息******\n");
printf("請輸刪除的學生姓名:");
scanf("%s", data.name);
deleteNode(List, data.name);
break;
case 5:
printf("******查詢學生信息******\n");
printf("請輸入要查找的學生姓名:");
scanf("%s", data.name);
p = searchData(List, data.name);
if (p == NULL)
{
printf("未找到相關信息,無法刪除!\n");
system("pause");
}
else
{
printf("學號\t姓名\t分數\n");
printf("%d\t%s\t%d\n", p->data.id, p->data.name, p->data.score);
}
break;
case 6:
printf("******修改學生信息******\n");
printf("請輸入要修改的學生姓名:");
scanf("%s", data.name);
break;
case 7:
printf("已經安安全退出!");
system("pause");//防止閃屏
exit(7);
break;
default:
printf("輸入有誤,請重新入!");
system("pause");//防止閃屏
break;
}
writeFile(List, "1.txt");
}
int main()
{
readFile(List, "1.txt");
while (1)
{
menu();
keydown();
}
return 0;
}
文章福利:
還有其他源碼哦!
如果你想要更多資料資料!
可以來我的C語言/C++編程學習交流俱樂部!
有(源碼,零基礎教程,項目實戰教學視頻),【點擊領取】!
你想要的我都有,不想要的我也有!
還有其他源碼哦!你想要的我都有,不想要的我也有!