近期很多小夥伴私信我說,臨近期末考試,需要一份課程設計:學生成績管理系統來交作業!
今天,它來了!400行源碼的學生管理系統,隻需要你正确移植到你的電腦上,即可使用,這還不點個關注 收藏嘛!
源碼分享:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char filename[20] = { 0 };
typedef struct Student{
int num;
char name[10];
float chinese;
float math;
float english;
float total;
struct Student* next;
}STU;
int MainInterface() {
int key;
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 歡迎來到學生成績管理系統 |\n");
printf("\t\t\t|===========================================|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 1.錄入學員 |\n");
printf("\t\t\t| 2.查找學員 |\n");
printf("\t\t\t| 3.删除學員 |\n");
printf("\t\t\t| 4.修改成績 |\n");
printf("\t\t\t| 5.打開文件 |\n");
printf("\t\t\t| 0.退出系統 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請選擇:");
scanf("%d", &key);
return key;
}
STU* CreateList(){
STU* p = (STU*)malloc(sizeof(STU));
if (p != NULL)
p->next = NULL;
return p;
}
int NumIsExist(STU* plist, int num) {
plist = plist->next;
while (plist != NULL)
{
if (plist->num == num)
return 1;
plist = plist->next;
}
return 0;
}
void InsertStu(STU* plist){
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在錄入學員信息 |\n");
printf("\t\t\t=============================================\n");
STU* p = plist;
int count = 0;
printf("\t\t\t請問需要添加多少學員:");
scanf("%d",&count);
if (count <= 0)
return;
for (int i = 0; i < count; i ) {
STU* pnew = (STU*)malloc(sizeof(STU));
if (pnew == NULL) return;
printf("\t\t\t請輸入學生學号:");
scanf("%d", &pnew->num);
while (1)
{
if (NumIsExist(plist, pnew->num))
{
printf("\t\t\t學号重複,請重新輸入學号:");
scanf("%d", &pnew->num);
}
else
break;
}
printf("\t\t\t請輸入學生姓名:");
scanf("%s", pnew->name);
printf("\t\t\t請輸入語文成績:");
scanf("%f", &pnew->chinese);
printf("\t\t\t請輸入數學成績:");
scanf("%f", &pnew->math);
printf("\t\t\t請輸入英語成績:");
scanf("%f", &pnew->english);
pnew->total = pnew->chinese pnew->math pnew->english;
pnew->next = NULL;
//頭插法? 尾插法? 任意位置插入?
p = plist;
while (p->next != NULL)
{
if (pnew->num < p->next->num)
{
pnew->next = p->next;
p->next = pnew;
break;
}
p=p->next;
}
p->next = pnew;
}
}
void SerchByNum(STU* plist){
int num = 0;
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在查找學員信息 |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請輸入學員學号:");
scanf("%d", &num);
while (plist != NULL)
{
if (plist->num == num)
{
printf("\t\t\t學号\t姓名\t語文\t數學\t英語\t總分\n");
printf("\t\t\t%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
plist->num, plist->name, plist->chinese,
plist->math, plist->english,plist->total);
printf("\t\t\t");
system("pause");
return;
}
plist = plist->next;
}
printf("\t\t\t沒有找到該學生!!\n");
printf("\t\t\t");
system("pause");
}
void SerchByName(STU* plist){
char name[10] = { 0 };
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在查找學員信息 |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請輸入學員姓名:");
scanf("%s", &name);
int n = 1;
while (plist != NULL)
{
if (strcmp(name, plist->name) == 0)
{
if (n) {
printf("\t\t\t學号\t姓名\t語文\t數學\t英語\t總分\n");
n = 0;
}
printf("\t\t\t%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
plist->num, plist->name, plist->chinese,
plist->math, plist->english, plist->total);
}
plist = plist->next;
}
if (n)
printf("\t\t\t沒有找到該學生!!\n");
printf("\t\t\t");
system("pause");
}
void SerchAllStu(STU* plist) {
plist = plist->next;
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在查找學員信息 |\n");
printf("\t\t\t=============================================\n");
if (plist == NULL)
{
printf("\t\t\t沒有學員信息!\n");
printf("\t\t\t");
system("pause");
return;
}
printf("\t\t\t學号\t姓名\t語文\t數學\t英語\t總分\n");
while (plist != NULL)
{
printf("\t\t\t%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
plist->num, plist->name, plist->chinese,
plist->math, plist->english, plist->total);
plist = plist->next;
}
printf("\t\t\t");
system("pause");
}
void SerchMain(STU* plist) {
int key;
do {
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在查找學員信息 |\n");
printf("\t\t\t|===========================================|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 1.按學号查找 |\n");
printf("\t\t\t| 2.按姓名查找 |\n");
printf("\t\t\t| 3.查看所有項 |\n");
printf("\t\t\t| 0.返回主菜單 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請選擇:");
scanf("%d", &key);
switch (key) {
case 1:SerchByNum(plist); break;
case 2:SerchByName(plist); break;
case 3:SerchAllStu(plist); break;
}
} while (key != 0);
}
void DeleteStu(STU* plist){
int num = 0;
char key = '\0';
STU* pre = plist;
STU* p = plist->next;
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在準備删除信息 |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請輸入需要删除的學号:");
scanf("%d", &num);
while (p != NULL)
{
if (p -> num == num)
{
printf("\t\t\t學号\t姓名\t語文\t數學\t英語\t總分\n");
printf("\t\t\t%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
p->num, p->name, p->chinese,
p->math, p->english, p->total);
printf("\t\t\t是否删除? [Y/N] : ");
getchar();
scanf("%c",&key);
if (key == 'N' || key == 'n')
return;
else if(key == 'Y' || key == 'y')
{
pre->next = p->next;
free(p);
p = NULL;
printf("\t\t\t删除成功!!\n");
printf("\t\t\t");
system("pause");
return;
}
}
pre = pre->next;
p = p->next;
}
printf("\t\t\t沒有找到該學生!!\n");
printf("\t\t\t");
system("pause");
}
void ModifyStu(STU* plist) {
int num = 0;
STU* p = plist->next;
char key = '\0';
system("cls");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 正在準備修改信息 |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請輸入需要修改的學号:");
scanf("%d", &num);
while (p != NULL)
{
if (num == p->num)
{
printf("\t\t\t學号\t姓名\t語文\t數學\t英語\t總分\n");
printf("\t\t\t%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
p->num, p->name, p->chinese,
p->math, p->english, p->total);
printf("\t\t\t是否修改? [Y/N] : ");
getchar();
scanf("%c", &key);
if (key == 'N' || key == 'n')
return;
else if (key == 'Y' || key == 'y')
{
printf("\n\t\t\t==============\n");
printf("\t\t\t1.修改姓名\n\t\t\t2.修改語文\n\t\t\t3.修改數學\n\t\t\t4.修改英語\n\t\t\t0.返回\n");
printf("\t\t\t==============\n");
printf("\t\t\t請選擇:");
getchar();
scanf("%c", &key);
if (key == '1') {
printf("\t\t\t新的姓名:");
scanf("%s", p->name);
}
else if (key == '2') {
printf("\t\t\t新的語文成績:");
scanf("%f", &p->chinese);
}
else if (key == '3') {
printf("\t\t\t新的數學成績:");
scanf("%f", &p->math);
}
else if (key == '4') {
printf("\t\t\t新的英語成績:");
scanf("%f", &p->english);
}
else if (key == '0') return;
printf("\t\t\t修改後的信息如下:\n");
printf("\t\t\t學号\t姓名\t語文\t數學\t英語\t總分\n");
printf("\t\t\t%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
p->num, p->name, p->chinese,
p->math, p->english, p->total);
printf("\t\t\t");
system("pause");
return;
}
}
p = p->next;
}
printf("\t\t\t沒有找到該學員!!\n");
printf("\t\t\t");
system("pause");
}
STU* OpenStuFile() {
char c;
STU* pstu = NULL;
STU* ptem = NULL;
FILE* fp = NULL;
while (1){
system("cls");
printf("\n\n");
printf("\n\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t| 歡迎來到學生成績管理系統 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 【源碼聯系群中老師】 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 【源碼聯系群中老師】 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 【源碼聯系群中老師】 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 【學編程,來頓開】 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t=============================================\n");
printf("\t\t\t請輸入班級(如:3年2班):");
scanf("%s", filename);
fp = fopen(filename, "rb ");
if (fp != NULL) break; //打開成功
printf("\t\t\t文件不存在!是否創建該文件? [Y/N] : ");
getchar();
scanf("%c", &c);
if (c == 'Y' || c == 'y')
{
fp = fopen(filename, "wb ");
if (fp != NULL)
break;
else
continue;
}
else
continue;
}
pstu = CreateList();
while (1)
{
STU* pnew = (STU*)malloc(sizeof(STU));
pnew->next = NULL;
if (fscanf(fp, "%d\t%s\t%f\t%f\t%f\t%f\n",
&pnew->num, pnew->name, &pnew->chinese,
&pnew->math, &pnew->english, &pnew->total) == EOF)
{
free(pnew);
pnew = NULL;
break;
}
//頭插法? 尾插法? 任意位置插入?
ptem = pstu;
while (ptem->next != NULL)
{
if (pnew->num < ptem->next->num)
{
pnew->next = ptem->next;
ptem->next = pnew;
break;
}
ptem = ptem->next;
}
ptem->next = pnew;
}
fclose(fp);
return pstu;
}
void CloseStuFile(STU* plist){
FILE* fp = NULL;
plist = plist->next;
//隻寫方式打開文件
if ((fp = fopen(filename, "wb ")) == NULL)
{
printf("打開文件失敗!");
}
else
{
//遍曆鍊表輸出到文件
while (plist != NULL)
{
fprintf(fp,"%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\n",
plist->num, plist->name, plist->chinese,
plist->math, plist->english, plist->total);
plist = plist->next;
}
}
fclose(fp);
}
int main(){
int key = -1;
STU* pList = NULL;
pList = OpenStuFile(); //初始化鍊表
while (key != 0) {
key = MainInterface();
switch (key) {
case 1: InsertStu(pList); break;
case 2: SerchMain(pList); break;
case 3: DeleteStu(pList); break;
case 4:ModifyStu(pList); break;
case 0:CloseStuFile(pList); break;
}
}
return 0;
}
好了,趕緊去完成你的課程設計吧!不要忘了留下你的關注和點贊喲~
另外,對現在我們的大多數朋友來說還是學編程技術最重要!栽一棵樹最好的時間是十年前,其次是現在。對于準備學習編程的小夥伴,如果你想更好的提升你的編程核心能力(内功)不妨從現在開始!
編程學習書籍分享:
編程學習視頻分享:
整理分享(多年學習的源碼、項目實戰視頻、項目筆記,基礎入門教程)
歡迎轉行和學習編程的夥伴,利用更多的資料學習成長比自己琢磨更快哦!
點擊下方【了解更多】獲取更多學習資料幫助你學習成長哦~
,更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!