代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
学生成绩管理系统
作者:
shilijun11
/ 发布于
2013/10/24
/
808
string.h #ifndef STRING_H_INCLUDED #define STRING_H_INCLUDED char *mystrcpy(char *_psz_dest, const char *_pcsz_source); char *mystrncpy(char *_psz_dest, const char *_pcsz_source, size_t n_size); char *mystrcat(char *_psz_dest, const char *_pcsz_source); char *mystrncat(char *_psz_dest, const char *_pcsz_source, size_t n_size); char *mystrNcat(char *_psz_dest, const char *_pcsz_source, size_t n_size); int mystrcmp(const char *_pcsz_dest, const char *_pcsz_source); int mystrncmp(const char *_pcsz_dest, const char *_pcsz_source, size_t n_size); size_t mystrlen(const char *_pcsz_source); size_t mystrchr(const char *_pcsz_source, char ch); size_t mystrspn(const char *_pcsz_dest, const char *_pcsz_source); size_t my_strspn(const char *_pcsz_dest, const char *_pcsz_source); size_t mystrpbrk(const char *_pcsz_dest, const char *_pcsz_source); char *my_strpbrk(const char *_pcsz_dest, const char *_pcsz_source); void * mymemset(void *p, char ch, size_t n_size); #endif // STRING_H_INCLUDED string.c #include <stdio.h> #include <stdlib.h> #include "string.h" #include "student.h" /*字符串拷贝函数*/ char *mystrcpy(char *_psz_dest, const char *_pcsz_source) { char *psz_temp = _psz_dest; while ((*_psz_dest++ = *_pcsz_source++) != '\0'); return psz_temp; } /*字符串拷贝函数*/ char *mystrncpy(char *_psz_dest, const char *_pcsz_source, size_t n_size) { char *psz_temp = _psz_dest; while (n_size-- && (*_psz_dest++ = *_pcsz_source++) != '\0'); return psz_temp; } /*字符串拼接函数*/ char *mystrcat(char *_psz_dest, const char *_pcsz_source) { char *psz_temp = _psz_dest; while (*_psz_dest != '\0') _psz_dest++; while ((*_psz_dest++ = *_pcsz_source++) != '\0'); return psz_temp; } /*字符串拼接函数*/ char *mystrncat(char *_psz_dest, const char *_pcsz_source, size_t n_size) { char *psz_temp = _psz_dest; while (*_psz_dest != '\0') _psz_dest++; while (n_size-- && (*_psz_dest++ = *_pcsz_source++) != '\0'); return psz_temp; } /*字符串拼接函数*/ char *mystrNcat(char *_psz_dest, const char *_pcsz_source, size_t n_size) { char *psz_temp = _psz_dest; while (n_size) { while (*_psz_dest != '\0') _psz_dest++; while (*_psz_dest++ = *_pcsz_source++) { if (--n_size == 0) { *_psz_dest = '\0'; break; } } } return psz_temp; } /*字符串比较函数*/ int mystrcmp(const char *_pcsz_dest, const char *_pcsz_source) { while (*_pcsz_dest != '\0' && *_pcsz_source != '\0' && *(_pcsz_dest++) == *(_pcsz_source++)) { if (*_pcsz_dest == *_pcsz_source) return 0; return (*_pcsz_dest > *_pcsz_source) ? 1 : -1; } } /*字符串比较函数*/ int mystrncmp(const char *_pcsz_dest, const char *_pcsz_source, size_t n_size) { while (*_pcsz_dest != '\0' && *_pcsz_source != '\0' && *(_pcsz_dest++) == *(_pcsz_source++)) { n_size--; if (*_pcsz_dest == *_pcsz_source) { return 0; } return (*_pcsz_dest > *_pcsz_source) ? 1 : -1; } } /*求字符串的长度*/ size_t mystrlen(const char *_pcsz_source) { size_t n_size = 0; if (*_pcsz_source == '\0') n_size = 0; while (*_pcsz_source != '\0') { _pcsz_source++; n_size++; } return n_size; } /*查找字符串中首次出现字符的位置*/ size_t mystrchr(const char *_pcsz_source, char ch) { size_t n_size = 0; if (*_pcsz_source == '\0') return 0; for (; *_pcsz_source != ch; _pcsz_source++) n_size++; if (*_pcsz_source == '\0') return 0; return n_size; } size_t mystrrchr(const char *_pcsz_source, char ch) { size_t n_size = 0; if (*_pcsz_source == '\0') return 0; const char *p = _pcsz_source + mystrlen(_pcsz_source); do { if (*p == ch) { return n_size; } n_size++; }while (--p >= _pcsz_source); return 0; } size_t mystrRchr(const char *_pcsz_source, char ch) { size_t n_size = 0; if (_pcsz_source == '\0') return 0; const char *pcsz_temp = _pcsz_source + mystrlen(_pcsz_source); do { n_size++; if (*pcsz_temp == ch) { return n_size; } }while (--pcsz_temp >= _pcsz_source); return 0; } /*复制字符串*/ char *mystrdup(const char *_pcsz_source) { char *psz_temp = NULL; if (*_pcsz_source == '\0') return NULL; psz_temp = malloc(mystrlen(_pcsz_source)); if (psz_temp == NULL) { return NULL; } mystrcpy(psz_temp, _pcsz_source); return psz_temp; } /*返回字符串中第一个不在指定字符串中出现的字符下标*/ size_t mystrspn(const char *_pcsz_dest, const char *_pcsz_source) { const char *p; const char *a; size_t n_size = 0; for (p = _pcsz_dest; *p != '\0'; ++p) { for (a = _pcsz_source; *a != '\0'; ++a) { if (*p == *a) break; } if (*a == '\0') return n_size; ++n_size; } return n_size; } size_t my_strspn(const char *_pcsz_dest, const char *_pcsz_source) { const char *p; const char *a; size_t n_size = 0; for (p = _pcsz_dest; *p != '\0'; ++p) { for (a = _pcsz_source; *a != '\0'; ++a) { if (*p == *a) break; } if (*a == '\0') return n_size; ++n_size; } return n_size; } /*在字符串s1中寻找字符串s2中任何一个字符相匹配的第一个字符的位置,空字符NULL不包括在内 返回指向s1中第一个相匹配的字符的指针,如果没有匹配字符则返回空指针NULL。*/ size_t mystrpbrk(const char *_pcsz_dest, const char *_pcsz_source) { const char *p; const char *a; size_t n_size = 0; for (p = _pcsz_dest; *p != '\0'; ++p) { for (a = _pcsz_source; *a != '\0'; ++a) { if (*p == *a) { return n_size; } } ++n_size; } return n_size; } char *my_strpbrk(const char *_pcsz_dest, const char *_pcsz_source) { const char *p; const char *a; for (p = _pcsz_dest; *p != '\0'; ++p) { for (a = _pcsz_source; *a != '\0'; ++a) { if (*p == *a) return p; } } return NULL; } void * mymemset(void *p, char ch, size_t n_size) { char *q = (char*)p; while (n_size--) *q++ = ch; return p; } student.h #ifndef STUDENT_H_INCLUDED #define STUDENT_H_INCLUDED #define NUM_LENGTH 10 #define NAME_LENGTH 20 typedef struct student { char szNum[NUM_LENGTH]; /*学号*/ char szName[NAME_LENGTH]; /*姓名*/ int nCGrade; /*C语言成绩*/ int nEGrade; /*英语成绩*/ int nMGrade; /*数学成绩*/ int nTotal; /*总成绩*/ float fAve; /*平均成绩*/ int nMingci; /*名次*/ }; typedef struct LNode { struct student data; /*数据域*/ struct LNode *next; /*指针域*/ }LNode, *Link; int menu(void); void Add(Link l); void Save(Link l); void Disp(Link l); void Del(Link l); LNode *Locate(Link l, char *_psz_select, char *_psz_name); void show(Link l, char *_psz_select, char *_psz_name); void Qur(Link l); void Modify(Link l); void Insert(Link l); void Tongji(Link l); void sort(Link l); #endif // STUDENT_H_INCLUDED student.c #include <stdio.h> #include <stdlib.h> #include "string.h" #include "student.h" int menu(void) { int select = 0; printf("*************************************\n"); printf("1. 添加学生记录 2. 删除学生记录 \n"); printf("3. 查询学生记录 4. 修过学生记录 \n"); printf("5. 插入学生记录 6. 统计学生连接 \n"); printf("7. 排序学生记录 8. 保存学生记录 \n"); printf("9. 显示学生记录 0. 退出系统 \n"); printf("*************************************\n"); printf("please input your select: "); scanf("%d", &select); return select; } void Add(Link l) { LNode *p, *r, *s; r = l; s = l->next; char szCh[1 + 1]; char szNum[NUM_LENGTH]; char szName[NAME_LENGTH]; int nCGrade = 0; int nEGrade = 0; int nMGrade = 0; int nTotal = 0; float fAve = 0; int nMingci = 0; memset(szCh, 0, sizeof(szCh)); memset(szNum, 0, sizeof(szNum)); memset(szName, 0, sizeof(szName)); while (r->next != NULL) r = r->next; /*将指针移至链表的尾部,添加记录*/ while (1) { while (1) { printf("请输入学号\n"); scanf("%s", szNum); if (mystrcmp(szNum, "0") == 0) { return NULL; } s = l->next; while (s) { if (mystrcmp(s->data.szNum, szNum) == 0) { printf("本学生已在系统中\n"); return ; } s = s->next; } break; } p = (LNode*)malloc(sizeof(LNode)); if (!p) { printf("malloc P 失败\n"); return ; } mystrcpy(p->data.szNum, szNum); printf("请输入姓名: "); scanf("%s", szName); mystrcpy(p->data.szName, szName); printf("请输入C语言成绩: "); scanf("%d", &nCGrade); p->data.nCGrade = nCGrade; printf("请输入英语成绩: "); scanf("%d", &nEGrade); p->data.nEGrade = nEGrade; printf("请输入数学成绩: "); scanf("%d", &nMGrade); p->data.nMGrade = nMGrade; p->data.nTotal = p->data.nCGrade + p->data.nEGrade + p->data.nMGrade; p->data.fAve = (float)((p->data.nTotal) / 3); p->data.nMingci = 0; p->next = NULL; r->next = p; r = p; printf("是否继续输入? (Y | y)\n"); scanf("%s", szCh); if (szCh[0] == 'Y' || szCh[0] == 'y') { continue; } else { return ; } } return ; } void Save(Link l) { FILE *fp; LNode *p; int nCount = 0; fp = fopen("./student.txt", "wb"); if (NULL == fp) { printf("打开文件失败\n"); return ; } p = l->next; while (p) { if (fwrite(p, sizeof(LNode), 1, fp) == 1) { p = p->next; nCount++; } else { break; } } printf("nCount = %d\n", nCount); close(fp); } void Disp(Link l) { LNode *p; p = l->next; if (!p) { printf("没有数据\n"); return ; } while (p) { printf("*************************************\n"); printf("学 号:%s \n", p->data.szNum); printf("姓 名: %s \n", p->data.szName); printf("C语言成绩: %d \n", p->data.nCGrade); printf("数学成绩 : %d \n", p->data.nMGrade); printf("英语成绩 : %d \n", p->data.nEGrade); printf("总成绩 : %d \n", p->data.nTotal); printf("平均成绩 : %lf \n", p->data.fAve); printf("名次 : %d \n", p->data.nMingci); printf("*************************************\n"); p = p->next; } return ; } LNode *Locate(Link l, char *_psz_select, char *_psz_name) { LNode *p; if (mystrcmp(_psz_select, "num") == 0) { p = l->next; while (p) { if (mystrcmp(p->data.szNum, _psz_name) == 0) { return p; } p = p->next; } } else if (mystrcmp(_psz_select, "name") == 0) { p = l->next; while (p) { if (mystrcmp(p->data.szName, _psz_name) == 0) { return p; } p = p->next; } } return NULL; } void show(Link l, char *_psz_select, char *_psz_name) { LNode *p; if (mystrcmp(_psz_select, "num") == 0) { p = l->next; while (p) { if (mystrcmp(p->data.szNum, _psz_name) == 0) { printf("*************************************\n"); printf("学 号:%s \n", p->data.szNum); printf("姓 名: %s \n", p->data.szName); printf("C语言成绩: %d \n", p->data.nCGrade); printf("数学成绩 : %d \n", p->data.nMGrade); printf("英语成绩 : %d \n", p->data.nEGrade); printf("总成绩 : %d \n", p->data.nTotal); printf("平均成绩 : %lf \n", p->data.fAve); printf("名次 : %d \n", p->data.nMingci); printf("*************************************\n"); } p = p->next; } } else if (mystrcmp(_psz_select, "name") == 0) { p = l->next; while (p) { if (mystrcmp(p->data.szName, _psz_name) == 0) { printf("*************************************\n"); printf("学 号:%s \n", p->data.szNum); printf("姓 名: %s \n", p->data.szName); printf("C语言成绩: %d \n", p->data.nCGrade); printf("数学成绩 : %d \n", p->data.nMGrade); printf("英语成绩 : %d \n", p->data.nEGrade); printf("总成绩 : %d \n", p->data.nTotal); printf("平均成绩 : %lf \n", p->data.fAve); printf("名次 : %d \n", p->data.nMingci); printf("*************************************\n"); } p = p->next; } } return NULL; } /*删除分为两种情况,num删除,name删除*/ void Del(Link l) { LNode *p, *r; int select = 0; char szNum[NUM_LENGTH]; char szName[NAME_LENGTH]; memset(szNum, 0, sizeof(szNum)); memset(szName, 0,sizeof(szName)); if (l->next == NULL) { printf("链表为空\n"); return NULL; } printf("以什么方式删除数据?(1.num, 2.name)\n"); scanf("%d", &select); if (select == 1) { p = l->next; printf("请输入学号:\n"); scanf("%s", szNum); while (p) { if (mystrcmp(p->data.szNum, szNum) == 0) { r = l; while (r->next != p) r = r->next; r->next = p->next; free(p); return ; } p = p->next; } printf("没有找到\n"); } else if (select == 2) { p = l->next; printf("请输入姓名:\n"); scanf("%s", szName); while (p) { if (mystrcmp(p->data.szName, szName) == 0) { r = l->next; while (r->next != p) r = r->next; r->next = p->next; free(p); return ; } p = p->next; } printf("没有找到\n"); } return ; } void Qur(Link l) { LNode *p, *r; int select = 0; char szNum[NUM_LENGTH]; char szName[NAME_LENGTH]; memset(szNum, 0, sizeof(szNum)); memset(szName, 0, sizeof(szName)); if (l->next == NULL) { printf("次链表为空\n"); return ; } printf("请输入查询条件(1. num, 2. name)\n"); scanf("%d", &select); if (select == 1) { printf("请输入学号: \n"); scanf("%s", szNum); p = l->next; while (p) { if (mystrcmp(p->data.szNum, szNum) == 0) { printf("*************************************\n"); printf("学 号:%s \n", p->data.szNum); printf("姓 名: %s \n", p->data.szName); printf("C语言成绩: %d \n", p->data.nCGrade); printf("数学成绩 : %d \n", p->data.nMGrade); printf("英语成绩 : %d \n", p->data.nEGrade); printf("总成绩 : %d \n", p->data.nTotal); printf("平均成绩 : %lf \n", p->data.fAve); printf("名次 : %d \n", p->data.nMingci); printf("*************************************\n"); return ; } p = p->next; } printf("没找到\n"); } else if (select == 2) { printf("请输入姓名: "); scanf("%s", szName); p = l->next; while(p) { if (mystrcmp(p->data.szName, szName) == 0) { printf("*************************************\n"); printf("学 号:%s \n", p->data.szNum); printf("姓 名: %s \n", p->data.szName); printf("C语言成绩: %d \n", p->data.nCGrade); printf("数学成绩 : %d \n", p->data.nMGrade); printf("英语成绩 : %d \n", p->data.nEGrade); printf("总成绩 : %d \n", p->data.nTotal); printf("平均成绩 : %lf \n", p->data.fAve); printf("名次 : %d \n", p->data.nMingci); printf("*************************************\n"); return ; } p = p->next; } printf("没找到\n"); } return ; } /*提示学号是唯一的,不能改*/ void Modify(Link l) { LNode *p; char szNum[NUM_LENGTH]; char szName[NAME_LENGTH]; int nCGrade = 0; int nEGrade = 0; int nMGrade = 0; int nTotal = 0; float fAve = 0; int nMingci = 0; memset(szName, 0, sizeof(szName)); memset(szNum, 0, sizeof(szNum)); if (l->next == NULL) { printf("次链表为空\n"); return ; } while (1) { printf("请输入要修改的学生的学号: "); scanf("%s", szNum); p = l->next; while (p) { if (mystrcmp(p->data.szNum, szNum) == 0) { printf("请输入修改的内容\n"); mystrcpy(p->data.szNum, szNum); printf("请输入姓名: "); scanf("%s", szName); mystrcpy(p->data.szName, szName); printf("请输入C语言成绩: "); scanf("%d", &nCGrade); p->data.nCGrade = nCGrade; printf("请输入英语成绩: "); scanf("%d", &nEGrade); p->data.nEGrade = nEGrade; printf("请输入数学成绩: "); scanf("%d", &nMGrade); p->data.nMGrade = nMGrade; p->data.nTotal = p->data.nCGrade + p->data.nEGrade + p->data.nMGrade; p->data.fAve = (float)((p->data.nTotal) / 3); p->data.nMingci = 0; return ; } p = p->next; } printf("没有找到\n"); } return ; } void Insert(Link l) { LNode *p, *r, *s; char szNum1[NUM_LENGTH]; char szNum2[NUM_LENGTH]; char szName[NAME_LENGTH]; int nCGrade = 0; int nEGrade = 0; int nMGrade = 0; int nTotal = 0; float fAve = 0; int nMingci = 0; memset(szNum1, 0, sizeof(szNum1)); memset(szNum2, 0, sizeof(szNum2)); memset(szName, 0, sizeof(szName)); if (l->next == NULL) { printf("次链表为空\n"); return ; } p = l->next; printf("请输入插入的位置(之后)的学号: "); scanf("%s", szNum1); while (p) { if (mystrcmp(p->data.szNum, szNum1) == 0) { break; } p = p->next; } r = l->next; printf("请输入要插入的学生的学号 : "); scanf("%s", szNum2); while (r) { if (mystrcmp(r->data.szNum, szNum2) == 0) { printf("次学生已经在系统中\n"); return ; } r = r->next; } s = (LNode*)malloc(sizeof(LNode)); if (!s) { printf("malloc s 失败\n"); return ; } s->next = NULL; mystrcpy(s->data.szNum, szNum2); printf("请输入姓名: "); scanf("%s", szName); mystrcpy(s->data.szName, szName); printf("请输入C语言成绩: "); scanf("%d", &nCGrade); s->data.nCGrade = nCGrade; printf("请输入英语成绩: "); scanf("%d", &nEGrade); s->data.nEGrade = nEGrade; printf("请输入数学成绩: "); scanf("%d", &nMGrade); s->data.nMGrade = nMGrade; s->data.nTotal = s->data.nCGrade + s->data.nEGrade + s->data.nMGrade; s->data.fAve = (float)((s->data.nTotal) / 3); s->data.nMingci = 0; s->next = p->next; p->next = s; printf("插入成功\n"); return ; } void Tongji(Link l) { LNode *p; LNode *cp, *mp, *ep, *tp; int nCCount = 0; int nMCount = 0; int nECount = 0; p = l->next; if (l->next == NULL) { printf("空链表\n"); return ; } ep = cp = mp = tp = p; while (p) { if (p->data.nCGrade < 60) nCCount++; if (p->data.nEGrade < 60) nMCount++; if (p->data.nMGrade < 60) nECount++; if (p->data.nCGrade >= cp->data.nCGrade) cp = p; if (p->data.nEGrade >= ep->data.nEGrade) ep = p; if (p->data.nMGrade >= mp->data.nMGrade) mp = p; if (p->data.nTotal >= tp->data.nTotal) tp = p; p = p->next; } printf("************************************\n"); printf("C语言不及格的人数为 : %d\n", nCCount); printf("数学成绩不及格的人数为:%d\n", nMCount); printf("英语成绩不及格的人数为: %d\n", nECount); printf("C语言成绩最高的是%s的分数是%d\n", cp->data.szName, cp->data.nCGrade); printf("数学成绩最高的是%s的分数是 %d\n", mp->data.szName, mp->data.nMGrade); printf("英语成绩最高的是%s的分数是 %d\n", ep->data.szName, ep->data.nEGrade); printf("总成绩最高的是%s的分数是 %d\n", tp->data.szName, tp->data.nTotal); printf("************************************\n"); return ; } /*按总成绩成绩排序*/ void sort(Link l) { Link ll; LNode *p, *rr, *s; int i = 0; if (l->next == NULL) { printf("空链表"); return; } ll = (LNode*)malloc(sizeof(LNode)); if (!ll) { printf("malloc ll 失败\n"); return ; } ll->next = NULL; p = l->next; while (p) { s = (LNode*)malloc(sizeof(LNode)); if (!s) { printf("malloc s 失败\n"); return ; } s->data = p->data; s->next = NULL; rr = ll; while (rr->next != NULL && rr->next->data.nTotal > p->data.nTotal) { rr = rr->next; } if (rr->next == NULL) { rr->next = s; } else { s->next = rr->next; rr->next = s; } p = p->next; } l->next = ll->next; p = l->next; while (p != NULL) { i++; p->data.nMingci = i; p = p->next; } Disp(l); return ; } main.c #include <stdio.h> #include <stdlib.h> #include "string.h" #include "student.h" int main() { printf("Hello\n"); Link l; /*定义链表*/ FILE *fp; /*文件指针*/ LNode *p, *r; int nCount = 0; int select = 0; char ch[1 + 1]; l = (LNode*)malloc(sizeof(LNode)); if (!l) { printf("malloc l failed\n"); return 1; } l->next = NULL; r = l; fp = fopen("./student.txt", "ab+"); if (NULL == fp) { printf("open file failed\n"); return 1; } while (!feof(fp)) { p = (LNode*)malloc(sizeof(LNode)); if (!p) { printf("malloc p failed\n"); return 1; } if (fread(p, sizeof(LNode), 1, fp) == 1) { p->next = NULL; r->next = p; r = p; nCount++; } } printf("系统中有学生记录总共%d个\n", nCount); close(fp); Disp(l); //LNode *pp; //show(l, "num", "03"); //pp = Locate(l, "num", "01"); //Disp(pp); while (1) { select = menu(); switch (select) { case 1: Add(l); break; case 2: Del(l); break; case 3: Qur(l); break; case 4: Modify(l); break; case 5: Insert(l); break; case 6: Tongji(l); break; case 7: sort(l); break; case 8: Save(l); break; case 9: Disp(l); break; case 0: return 1; default: printf("输入数字错误\n"); break; } } return 0; }
试试其它关键字
学生成绩管理系统
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
shilijun11
贡献的其它代码
(
2
)
.
android 读取数据库
.
学生成绩管理系统
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3