java创建链表成绩管理系统_成绩管理系统 链表版
1.[代碼][C/C++]代碼
/*********************************************************
*程序描述:學(xué)生成績(jī)管理系統(tǒng)
*運(yùn)行環(huán)境:Windows 7 SP1 X64
*開(kāi)發(fā)環(huán)境:CodeBlocks with Win7
*作者:耗子、
*時(shí)間:2015.03
**********************************************************/
#include
#include
#include
#include
const int TRUE = 1;
const int FALSE = 0;
const char BACK[] = "back";
typedef struct Student //鏈表元素
{
char name[100], number[100];
double chinese, math, english;
struct Student* next;
}LNode, *Student;
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓聲明函數(shù)↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
Student initLinkList();//初始化
void insLinkList(Student* pHead, char name[],//插入元素
char number[], double chinese,
double math, double english);
int delLinkList(Student* pHead, char number[]);//刪除元素
int listLength(Student* pHead);//獲取鏈表長(zhǎng)度
int findLinkList(Student* pHead, char number[]);//查找元素,返回位置
int modLinkList(Student* pHead, char number[],//修改元素
double chinese, double math,
double english);
void outPutLinkList(Student* pHead);//輸出所有信息
double scoreLegal(char score[]);//判斷分?jǐn)?shù)合法
int nameLegal(char name[]);//判斷姓名合法
int numberLegal(char number[]);//判斷學(xué)號(hào)合法
int emptyLinkList(Student* pHead);//判斷鏈表是否為空
void swapNode(Student p, Student q);//負(fù)責(zé)交換
void putMain();//輸出主UI
void putSort();//輸出排序UI
int isBack(char str[]);//判斷返回
void error(char []);//錯(cuò)誤警告
void welcome();//歡迎
void bay();//再見(jiàn)
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑聲明函數(shù)↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓主函數(shù)↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
int main()
{
system("color 0A");
system("mode con cols=80 lines=25");
Student pHead;
Student q, p;
char name[100], number[100], chinese[100], math[100],
english[100];
int op, n; //op是選擇的選項(xiàng)
double cn, ma, eng;
int i, j, sum;
pHead = initLinkList();
welcome();
while (1)
{
begin:
q = pHead;
putMain();
op = (getch() - '0' );
if (op == -1)
continue;
switch (op)
{
case 0://退出
{
bay();
return 0;
}
case 1://添加信息
{
for (;;)
{
printf ("\n\t\t\t叫什么?");
gets(name);
if (isBack(name))
goto begin;
if (nameLegal(name) == 0)
continue;
else
break;
}
number:
for (;;)
{
printf ("\t\t\t學(xué)號(hào)呢?");
gets(number);
if (isBack(number))
goto begin;
if (numberLegal(number) == 0)
continue;
else
break;
}
while (q != NULL)
{
if (strcmp(q->number, number) == 0)
{
error("學(xué)號(hào)重復(fù)了噻~");
goto number;
}
else
q = q->next;
}
for (;;)
{
printf ("\t\t\t語(yǔ)文多少分?\n\t\t\t");
gets(chinese);
if (isBack(chinese))
goto begin;
cn = scoreLegal(chinese);
if (cn == -1)
continue;
else
break;
}
for (;;)
{
printf ("\t\t\t數(shù)學(xué)呢?\n\t\t\t");
gets(math);
if (isBack(math))
goto begin;
ma = scoreLegal(math);
if (ma == -1)
continue;
else
break;
}
for (;;)
{
printf ("\t\t\tEnglish:\n\t\t\t");
gets(english);
if (isBack(english))
goto begin;
eng = scoreLegal(english);
if (eng == -1)
continue;
else
break;
}
insLinkList(pHead, name, number,
cn, ma, eng);
printf ("\n\t\t\t學(xué)生信息添加完畢\a");
getch();
break;
}
case 2://刪除信息
{
for(;;)
{
if (emptyLinkList(pHead))
break;
printf ("\t\t\t要?jiǎng)h除的學(xué)生的學(xué)號(hào):");
gets(number);
if (isBack(number))
goto begin;
if (numberLegal(number) == 0)
continue;
if (delLinkList(pHead, number) == 1)
{
printf ("\t\t\t刪除成功!");
getch();
break;
}
else
error ("沒(méi)有找到該學(xué)生!");
continue;
}
break;
}
case 3://查找信息
{
if (emptyLinkList(pHead))
break;
printf ("\n\t\t\t要查找誰(shuí)的信息?");
gets(number);
if (isBack(number))
goto begin;
if (numberLegal(number) == 0)
continue;
findLinkList(pHead, number);
break;
}
case 4://修改信息
{
if (emptyLinkList(pHead))
break;
for (;;)
{
printf ("\n\t\t\t要修改哪個(gè)的信息?");
gets(number);
if (isBack(number))
goto begin;
if (numberLegal(number) == 0)
continue;
else
break;
}
for (;;)
{
if (strcmp(q->number, number) == 0)
break;
else
q = q->next;
if (q == NULL)
{
error("沒(méi)有找到該學(xué)生!");
getch();
goto begin;
}
}
for (;;)
{
printf ("\t\t\t語(yǔ)文多少分?\n\t\t\t");
gets(chinese);
if (isBack(chinese))
goto begin;
cn = scoreLegal(chinese);
if (cn == -1)
continue;
else
break;
}
for (;;)
{
printf ("\t\t\t數(shù)學(xué)呢?\n\t\t\t");
gets(math);
if (isBack(math))
goto begin;
ma = scoreLegal(math);
if (ma == -1)
continue;
else
break;
}
for (;;)
{
printf ("\t\t\tEnglish:\n\t\t\t");
gets(english);
if (isBack(english))
goto begin;
eng = scoreLegal(english);
if (eng == -1)
continue;
else
break;
}
modLinkList(pHead, number, cn, ma, eng);
break;
}
case 5://輸出信息
{
if (emptyLinkList(pHead))
break;
q = pHead;
p = pHead;
sum = listLength(pHead);
putSort();
op = (getch() - '0');
switch (op)
{
case 0://退出
goto begin;
case 1://學(xué)號(hào)
{
for (i = 0; i < sum - 1; i++)
{
for (j = 0; j < sum - i - 1; j++)
{
if (strcmp(p->number, q->number) > 0)
swapNode(p, q);
q = q->next;
}
p = p->next;
q = p->next;
}
break;
}
case 2://語(yǔ)文
{
for (i = 0; i < sum - 1; i++)
{
for (j = 0; j < sum - i - 1; j++)
{
if (q->chinese < p->chinese)
swapNode(p, q);
q = q->next;
}
p = p->next;
q = p->next;
}
break;
}
case 3://數(shù)學(xué)
{
for (i = 0; i < sum - 1; i++)
{
for (j = 0; j < sum - i - 1; j++)
{
if (q->math < p->math)
swapNode(p, q);
q = q->next;
}
p = p->next;
q = p->next;
}
break;
}
case 4://英語(yǔ)
{
for (i = 0; i < sum - 1; i++)
{
for (j = 0; j < sum - i - 1; j++)
{
if (q->english < p->english)
swapNode(p, q);
q = q->next;
}
p = p->next;
q = p->next;
}
break;
}
case 5://總分
{
for (i = 0; i < sum - 1; i++)
{
for (j = 0; j < sum - i - 1; j++)
{
if ((q->chinese + q->math + q->english)
< (p->chinese + p->math + p->english))
swapNode(p, q);
q = q->next;
}
p = p->next;
q = p->next;
}
break;
}
default:
break;
}
if (op >= 1 && op <= 5)
outPutLinkList(pHead);
break;
default:
break;
}
}
}
return 0;
}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑主函數(shù)↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓鏈表操作↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
Student initLinkList() //初始化
{
Student pHead;
pHead = (Student)malloc(sizeof(LNode));
pHead->next = NULL;
return pHead;
}
void insLinkList(Student* pHead, char name[], //插入元素
char number[], double chinese,
double math, double english)
{
Student p = pHead;
Student pNew = (Student)malloc(sizeof(LNode));
while (p->next != NULL)
p = p->next;
strcpy(pNew->name, name);
strcpy(pNew->number, number);
pNew->chinese = chinese;
pNew->math = math;
pNew->english = english;
pNew->next = NULL;
p->next = pNew;
return ;
}
int delLinkList(Student* pHead, char number[]) //刪除元素
{
Student p = pHead, q;
while (p->next != NULL)
{
if (strcmp(p->next->number, number) == 0)
{
q = p->next->next;
free(p->next);
p->next = q;
free(q);
return TRUE;
}
p = p->next;
}
return FALSE;
}
int listLength(Student* pHead) //獲得鏈表長(zhǎng)度
{
int n = 0;
Student p = pHead;
while (p != NULL)
{
p = p->next;
n++;
}
return n;
}
int findLinkList(Student* pHead, char number[]) //查找元素
{
Student p = pHead;
p = p->next;
double sum;
while (p != NULL)
{
if (strcmp(p->number, number) == 0)
{
system ("CLS");
sum = p->chinese + p->math + p->english;
printf ("\n\n\t\t\t***********************\n\t\t\t* 該學(xué)生成 績(jī)?nèi)缦卤?*\n");
printf ("\t\t\t***********************\n");
printf ("\t\t\t* %s *\n", p->number);
printf ("\t\t\t***********************\n");
printf ("\t\t\t* 姓名:%-8s *\n", p->name);
printf ("\t\t\t* 語(yǔ)文:%-6.2f *\n", p->chinese);
printf ("\t\t\t* 數(shù)學(xué):%-6.2f *\n", p->math);
printf ("\t\t\t* 英語(yǔ):%-6.2f *\n", p->english);
printf ("\t\t\t* 平均:%-7.2f *\n", sum / 3);
printf ("\t\t\t* 總分:%-7.2f *\n", sum);
printf ("\t\t\t***********************\n");
getch();
return TRUE;
}
p = p->next;
}
error("沒(méi)有該學(xué)生的信息~");
return FALSE;
}
int modLinkList(Student* pHead, char number[], //修改元素
double chinese, double math,
double english)
{
Student p = pHead;
p = p->next;
while (p != NULL)
{
if (strcmp(p->number, number) == 0)
{
p->chinese = chinese;
p->math = math;
p->english = english;
return TRUE;
}
p = p->next;
}
return FALSE;
}
void outPutLinkList(Student* pHead) //輸出所有元素
{
if (emptyLinkList(pHead))
return ;
system ("CLS");
Student p = pHead;
p = p->next;
printf ("\n\n\t\t\t 所有學(xué)生成績(jī)?nèi)缦耚n");
printf ("\n *******************************************************************\n");
printf (" * 學(xué) 號(hào) * 姓 名 * 語(yǔ) 文 * 數(shù) 學(xué) * 英 語(yǔ) * 總 分 *");
printf ("\n *******************************************************************\n");
while (p != NULL)
{
printf (" * %s *", p->number);
printf (" %-8s *", p->name);
printf (" % 6.2f * %6.2f * %6.2f *", p->chinese, p->math, p->english);
printf (" %6.2f *\n", p->chinese + p->math + p->english);
p = p->next;
}
printf (" *******************************************************************\n");
getch();
return ;
}
int emptyLinkList(Student* pHead) //鏈表為否為空
{
Student p = pHead;
if (p->next == NULL)
{
error("沒(méi)有任何學(xué)生信息!");
return TRUE;
}
return FALSE;
}
void swapNode(Student p, Student q) //交換節(jié)點(diǎn)內(nèi)容
{
Student temp = initLinkList();
strcpy(temp->name, p->name);
strcpy(p->name, q->name);
strcpy(q->name, temp->name);
strcpy(temp->number, p->number);
strcpy(p->number, q->number);
strcpy(q->number, temp->number);
temp->chinese = p->chinese;
p->chinese = q->chinese;
q->chinese = temp->chinese;
temp->math = p->math;
p->math = q->math;
q->math = temp->math;
temp->english = p->english;
p->english = q->english;
q->english = temp->english;
free(temp);
}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑鏈表操作↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓函數(shù)定義↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
int isBack(char ch[]) //判斷返回
{
if(strcmp(ch, BACK) == 0)
return TRUE;
return FALSE;
}
int numberLegal(char number[]) //判斷學(xué)號(hào)
{
int i;
if (strlen(number) != 11)//位數(shù)判斷
{
error("學(xué)號(hào)應(yīng)為十一位純數(shù)字");
return FALSE;
}
for (i = 0; i < 11; i++)
if ( ! isdigit(number[i]))//是否是數(shù)字
{
error("學(xué)號(hào)應(yīng)為十一位純數(shù)字");
return FALSE;
}
if (number[0] == 0)//學(xué)號(hào)首位
{
error("學(xué)號(hào)第一位不能為0");
return FALSE;
}
return TRUE;
}
int nameLegal(char name[]) //判斷姓名
{
int i, n = strlen(name);
if (n <= 3)
{
error("科普:所謂姓名,一姓一名,最少得倆字兒");
return FALSE;
}
for (i = 0; i < n; i++)
if (name[i] >= 0)
{
error("既然是中國(guó)人,名字當(dāng)然也是中國(guó)字了啊");
return FALSE;
}
if (strlen(name) > 8)
{
error ("名字太長(zhǎng)的話(huà),請(qǐng)用縮寫(xiě)");
return FALSE;
}
return TRUE;
}
double scoreLegal(char score[]) //判斷分?jǐn)?shù)
{
int n = strlen(score);
int i, d = 0, g = 0;
double q = 1, h = 0.1;
double sum = 0;
for (i = 0; i < n; i++)
if (score[i] != '.' && (isdigit(score[i]) == 0))
{
error("分?jǐn)?shù)由數(shù)字和小數(shù)點(diǎn)組成。。。");
return -1;
}
for (i = 0; i < n; i++)
if (score[i] == '.')
{
d = i;
g++;
if (g == 2)
{
error("小數(shù)點(diǎn)好多啊");
return -1;
}
}
if (score[0] == '.' || score[n - 1] == '.')
{
error("小數(shù)點(diǎn)不能出現(xiàn)在這么詭異的位置");
return -1;
}
if (g == 1)
i = d - 1;
else
i = n - 1;
for ( ; i != -1; i--)
{
sum = sum + (score[i] - '0') * q;
q *= 10;
}
if (g == 1)
{
for (i = d + 1; i < n; i++)
{
sum = sum + (score[i] - '0') * h;
h *= 0.1;
}
}
if (sum > 100.000000)
{
error("分?jǐn)?shù)略大啊~");
return -1;
}
return sum;
}
void error(char ch[]) //提示錯(cuò)誤
{
system ("color 0C");
printf ("\n\n\t\t\t");
puts(ch);
printf ("\n");
printf ("\a");
getch();
system ("color 0A");
}
void welcome() //歡迎
{
system("title 學(xué)生成績(jī)管理系統(tǒng)V1.0 By-耗子、");
printf ("\n\n\n\n\t\t\t\t");
printf ("\n\t\t********************************************");
printf ("\n\t\t* 學(xué)生成績(jī)管理系統(tǒng)V1.0 *");
printf ("\n\t\t* *");
printf ("\n\t\t* 歡迎使用 *");
printf ("\n\t\t* *");
printf ("\n\t\t* 耗子、 *");
printf ("\n\t\t********************************************");
getch();
}
void putMain() //主UI
{
system ("CLS");
system("title 學(xué)生成績(jī)管理系統(tǒng)V1.0 By-耗子、");
printf ("\n\n");
printf ("\t\t\t 學(xué)生成績(jī)管理系統(tǒng)V1.0\n");
printf ("\t\t\t************************\n");
printf ("\t\t\t* 1、添加信息 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 2、刪除信息 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 3、查找信息 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 4、修改信息 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 5、顯示信息 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 0、退出系統(tǒng) *\n");
printf ("\t\t\t************************\n");
printf ("\t\t\t請(qǐng)選擇:(0~5)");
}
void putSort() //排序UI
{
system("title 請(qǐng)選擇排序方式 By-耗子、");
system("CLS");
printf ("\n\n");
printf ("\t\t\t 請(qǐng)選擇排序方式 \n");
printf ("\t\t\t************************\n");
printf ("\t\t\t* 1、學(xué)號(hào)排序 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 2、語(yǔ)文成績(jī) *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 3、數(shù)學(xué)成績(jī) *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 4、英語(yǔ)成績(jī) *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 5、總分排序 *\n");
printf ("\t\t\t* *\n");
printf ("\t\t\t* 0、系統(tǒng)菜單 *\n");
printf ("\t\t\t************************\n");
printf ("\t\t\t請(qǐng)選擇:(0~5)");
}
void bay() //退出
{
system("title 謝謝使用 By-耗子、");
system ("CLS");
printf ("\n\n\n\n\t\t\t\t");
printf ("\n\t\t********************************************");
printf ("\n\t\t* *");
printf ("\n\t\t* *");
printf ("\n\t\t* 謝謝使用 *");
printf ("\n\t\t* *");
printf ("\n\t\t* *");
printf ("\n\t\t********************************************");
printf ("\n\n\n\t\n\t\t -By.耗子\n");
getch();
}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑函數(shù)定義↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
總結(jié)
以上是生活随笔為你收集整理的java创建链表成绩管理系统_成绩管理系统 链表版的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: code block怎样实现图形界面_微
- 下一篇: iterm php,iTerm2笔记