python制作个人信息管理系统_python实现简易学生信息管理系统

本文实例为大家分享了python实现学生信息管理系统的具体代码,供大家参考,具体内容如下

简易学生信息管理系统主要功能有

1 录入学生信息

2 查找学生信息

3 删除学生信息

4 修改学生信息

5 排序

6 统计学生总人数

7 显示所有学生信息

0 退出系统

系统运行效果

2019919150100720.jpg?201981915118

主菜单的代码方法:

# Author: dry

# 开发时间:2019/9/11

# 开发工具:PyCharm

import re # 导入正则表达式模块

import os # 导入操作系统模块

filename = "student.txt" # 学生信息保存文件

def menu():

# 输出菜单

print('''

---------------学生信息管理系统------------

==================功能菜单================

1 录入学生信息

2 查找学生信息

3 删除学生信息

4 修改学生信息

5 排序

6 统计学生总人数

7 显示所有学生信息

0 退出系统

=======================================

说明:通过数字选择菜单

=======================================

''')

系统主方法:

def main():

ctrl = True # 标记是否退出系统

while (ctrl):

menu() # 显示菜单

option = input("请选择:") # 选择菜单项

option_str = re.sub("\D", "", option) # 提取数字

if option_str in ['0', '1', '2', '3', '4', '5', '6', '7']:

option_int = int(option_str)

if option_int == 0: # 退出系统

print('您已退出学生成绩管理系统!')

ctrl = False

elif option_int == 1: # 录入学生成绩信息

insert()

elif option_int == 2: # 查找学生成绩信息

search()

elif option_int == 3: # 删除学生成绩信息

delete()

elif option_int == 4: # 修改学生成绩信息

modify()

elif option_int == 5: # 排序

sort()

elif option_int == 6: # 统计学生总数

total()

elif option_int == 7: # 显示所有学生信息

show()

录入学生信息方法:

'''录入学生信息'''

def insert():

studentList = [] # 保存学生信息的列表

mark = True # 是否继续添加

while mark:

id = input("请输入学生ID(如1001):")

if not id:

break

name = input("请输入名字:")

if not name:

break

try:

english = int(input("请输入英语成绩:"))

python = int(input("请输入python成绩:"))

c = int(input("请输入C语言成绩:"))

except:

print("输入无效,不是整型数值,请重新输入信息")

continue

# 将输入的学生信息保存到字典

student = {"id": id, "name": name, "english": english, "python": python, "c": c}

studentList.append(student) # 将学生字典添加到列表中

inputList = input("是否继续添加?(y/n):")

if inputList == 'y': # 继续添加

mark = True

else:

mark = False

save(studentList) # 将学生信息保存到文件

print("学生信息录入完毕!!!")

保存学生信息方法:

'''将学生信息保存到文件'''

def save(student):

try:

student_txt = open(filename, 'a') # 以追加模式打开

except Exception as e:

student_txt = open(filename, 'w') # 文件不存在,创建文件并打开

for info in student:

student_txt.write(str(info) + "\n") # 执行存储,添加换行符

student_txt.close() # 关闭文件

查询学生信息方法:

'''查询学生信息'''

def search():

mark = True

student_query = []

while mark:

id = ""

name = ""

if os.path.exists(filename):

mode = input("按ID查询输入1:按姓名查询输入2:")

if mode == "1":

id = input("请输入学生ID:")

elif mode == "2":

name = input("请输入学生姓名:")

else:

print("您输入有误,请重新输入!")

search()

with open(filename, "r") as file:

student = file.readlines()

for list in student:

d = dict(eval(list))

if id is not "":

if d['id'] == id:

student_query.append(d)

elif name is not "":

if d['name'] == name:

student_query.append(d)

show_student(student_query)

student_query.clear()

inputMark = input("是否继续查询?(y/n):")

if inputMark == "y":

mark = True

else:

mark = False

else:

print("暂未保存数据信息...")

return

显示学生信息方法

'''将保存在列表中的学生信息显示出来'''

def show_student(studentList):

if not studentList:

print("无效的数据")

return

format_title = "{:^6}{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:10}"

print(format_title.format("ID", "名字", "英语成绩", "python成绩", "C语言成绩", "总成绩"))

format_data = "{:^6}{:^12}\t{:^10}\t{:^10}\t{:^10}\t{:10}"

for info in studentList:

print(format_data.format(info.get("id"), info.get("name"), str(info.get("english")), str(info.get("python")),

str(info.get("c")),

str(info.get("english") + info.get("python") + info.get("c")).center(12)))

删除学生信息方法:

'''删除学生信息'''

def delete():

mark = True # 标记是否循环

while mark:

studentId = input("请输入要删除的学生ID:")

if studentId is not "": # 判断要删除的学生ID是否存在

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

else:

student_old = []

ifdel = False # 标记是否删除

if student_old: # 如果存在学生信息

with open(filename, 'w') as wfile:

d = {} # 定义空字典

for list in student_old:

d = dict(eval(list)) # 字符串转字典

if d['id'] != studentId:

wfile.write(str(d) + "\n") # 将一条信息写入文件

else:

ifdel = True # 标记已经删除

if ifdel:

print("ID为%s的学生信息已经被删除..." % studentId)

else:

print("没有找到ID为%s的学生信息..." % studentId)

else:

print("不存在学生信息")

break

show() # 显示全部学生信息

inputMark = input("是否继续删除?(y/n):")

if inputMark == "y":

mark = True # 继续删除

else:

mark = False # 退出删除学生信息操作

修改学生信息方法:

'''修改学生信息'''

def modify():

show() # 显示全部学生信息

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

else:

return

studentid = input("请输入要修改的学生ID:")

with open(filename, 'w') as wfile:

for student in student_old:

d = dict(eval(student))

if d['id'] == studentid:

print("找到了这名学生,可以修改他的信息")

while True: # 输入要修改的信息

try:

d["name"] = input("请输入姓名:")

d["english"] = int(input("请输入英语成绩:"))

d["python"] = int(input("请输入python成绩:"))

d['c'] = int(input("请输入C语言成绩:"))

except:

print("您输入有误,请重新输入!")

else:

break

student = str(d) # 将字典转为字符串

wfile.write(student + "\n") # 将修改信息写入到文件

print("修改成功")

else:

wfile.write(student) # 将未修改的信息写入文件

mark = input("是否继续修改其他学生信息?(y/n):")

if mark == "y":

modify()

学生信息排序方法:

'''排序'''

def sort():

show()

if os.path.exists(filename):

with open(filename, 'r') as file:

student_old = file.readlines()

student_new = []

for list in student_old:

d = dict(eval(list))

student_new.append(d)

else:

return

ascORdesc = input("请选择(0升序;1降序)")

if ascORdesc == "0":

ascORdescBool = False # 标记变量,为False时表示升序,为True时表示降序

elif ascORdesc == "1":

ascORdescBool = True

else:

print("您输入的信息有误,请重新输入!")

sort()

mode = input("请选择排序方式(1按英语成绩排序;2按python成绩排序;3按C语言成绩排序;0按总成绩排序):")

if mode == "1": # 按英语成绩排序

student_new.sort(key=lambda x: x["english"], reverse=ascORdescBool)

elif mode == "2": # 按python成绩排序

student_new.sort(key=lambda x: x["python"], reverse=ascORdescBool)

elif mode == "3": # 按C语言成绩排序

student_new.sort(key=lambda x: x["c"], reverse=ascORdescBool)

elif mode == "0": # 按总成绩排序

student_new.sort(key=lambda x: x["english"] + x["python"] + x["c"], reverse=ascORdescBool)

else:

print("您的输入有误,请重新输入!")

sort()

show_student(student_new) # 显示排序结果

统计学生总数方法:

'''统计学生总数'''

def total():

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

if student_old:

print("一共有%d名学生!" % len(student_old))

else:

print("还没有录入学生信息")

else:

print("暂未保存数据信息")

显示所有学生信息方法:

'''显示所有学生信息'''

def show():

student_new = []

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

for list in student_old:

student_new.append(eval(list))

if student_new:

show_student(student_new)

else:

print("暂未保存数据信息")

开始函数:

if __name__ == '__main__':

main()

完整代码如下:

# Author: dry

# 开发时间:2019/9/11

# 开发工具:PyCharm

import re # 导入正则表达式模块

import os # 导入操作系统模块

filename = "student.txt" # 学生信息保存文件

def menu():

# 输出菜单

print('''

---------------学生信息管理系统------------

==================功能菜单================

1 录入学生信息

2 查找学生信息

3 删除学生信息

4 修改学生信息

5 排序

6 统计学生总人数

7 显示所有学生信息

0 退出系统

=======================================

说明:通过数字选择菜单

=======================================

''')

def main():

ctrl = True # 标记是否退出系统

while (ctrl):

menu() # 显示菜单

option = input("请选择:") # 选择菜单项

option_str = re.sub("\D", "", option) # 提取数字

if option_str in ['0', '1', '2', '3', '4', '5', '6', '7']:

option_int = int(option_str)

if option_int == 0: # 退出系统

print('您已退出学生成绩管理系统!')

ctrl = False

elif option_int == 1: # 录入学生成绩信息

insert()

elif option_int == 2: # 查找学生成绩信息

search()

elif option_int == 3: # 删除学生成绩信息

delete()

elif option_int == 4: # 修改学生成绩信息

modify()

elif option_int == 5: # 排序

sort()

elif option_int == 6: # 统计学生总数

total()

elif option_int == 7: # 显示所有学生信息

show()

'''录入学生信息'''

def insert():

studentList = [] # 保存学生信息的列表

mark = True # 是否继续添加

while mark:

id = input("请输入学生ID(如1001):")

if not id:

break

name = input("请输入名字:")

if not name:

break

try:

english = int(input("请输入英语成绩:"))

python = int(input("请输入python成绩:"))

c = int(input("请输入C语言成绩:"))

except:

print("输入无效,不是整形数值,请重新输入信息")

continue

# 将输入的学生信息保存到字典

student = {"id": id, "name": name, "english": english, "python": python, "c": c}

studentList.append(student) # 将学生字典添加到列表中

inputList = input("是否继续添加?(y/n):")

if inputList == 'y': # 继续添加

mark = True

else:

mark = False

save(studentList) # 将学生信息保存到文件

print("学生信息录入完毕!!!")

'''将学生信息保存到文件'''

def save(student):

try:

student_txt = open(filename, 'a') # 以追加模式打开

except Exception as e:

student_txt = open(filename, 'w') # 文件不存在,创建文件并打开

for info in student:

student_txt.write(str(info) + "\n") # 执行存储,添加换行符

student_txt.close() # 关闭文件

'''查询学生信息'''

def search():

mark = True

student_query = []

while mark:

id = ""

name = ""

if os.path.exists(filename):

mode = input("按ID查询输入1:按姓名查询输入2:")

if mode == "1":

id = input("请输入学生ID:")

elif mode == "2":

name = input("请输入学生姓名:")

else:

print("您输入有误,请重新输入!")

search()

with open(filename, "r") as file:

student = file.readlines()

for list in student:

d = dict(eval(list))

if id is not "":

if d['id'] == id:

student_query.append(d)

elif name is not "":

if d['name'] == name:

student_query.append(d)

show_student(student_query)

student_query.clear()

inputMark = input("是否继续查询?(y/n):")

if inputMark == "y":

mark = True

else:

mark = False

else:

print("暂未保存数据信息...")

return

'''将保存在列表中的学生信息显示出来'''

def show_student(studentList):

if not studentList:

print("无效的数据")

return

format_title = "{:^6}{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:10}"

print(format_title.format("ID", "名字", "英语成绩", "python成绩", "C语言成绩", "总成绩"))

format_data = "{:^6}{:^12}\t{:^10}\t{:^10}\t{:^10}\t{:10}"

for info in studentList:

print(format_data.format(info.get("id"), info.get("name"), str(info.get("english")), str(info.get("python")),

str(info.get("c")),

str(info.get("english") + info.get("python") + info.get("c")).center(12)))

'''删除学生信息'''

def delete():

mark = True # 标记是否循环

while mark:

studentId = input("请输入要删除的学生ID:")

if studentId is not "": # 判断要删除的学生ID是否存在

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

else:

student_old = []

ifdel = False # 标记是否删除

if student_old: # 如果存在学生信息

with open(filename, 'w') as wfile:

d = {} # 定义空字典

for list in student_old:

d = dict(eval(list)) # 字符串转字典

if d['id'] != studentId:

wfile.write(str(d) + "\n") # 将一条信息写入文件

else:

ifdel = True # 标记已经删除

if ifdel:

print("ID为%s的学生信息已经被删除..." % studentId)

else:

print("没有找到ID为%s的学生信息..." % studentId)

else:

print("不存在学生信息")

break

show() # 显示全部学生信息

inputMark = input("是否继续删除?(y/n):")

if inputMark == "y":

mark = True # 继续删除

else:

mark = False # 退出删除学生信息操作

'''修改学生信息'''

def modify():

show() # 显示全部学生信息

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

else:

return

studentid = input("请输入要修改的学生ID:")

with open(filename, 'w') as wfile:

for student in student_old:

d = dict(eval(student))

if d['id'] == studentid:

print("找到了这名学生,可以修改他的信息")

while True: # 输入要修改的信息

try:

d["name"] = input("请输入姓名:")

d["english"] = int(input("请输入英语成绩:"))

d["python"] = int(input("请输入python成绩:"))

d['c'] = int(input("请输入C语言成绩:"))

except:

print("您输入有误,请重新输入!")

else:

break

student = str(d) # 将字典转为字符串

wfile.write(student + "\n") # 将修改信息写入到文件

print("修改成功")

else:

wfile.write(student) # 将未修改的信息写入文件

mark = input("是否继续修改其他学生信息?(y/n):")

if mark == "y":

modify()

'''排序'''

def sort():

show()

if os.path.exists(filename):

with open(filename, 'r') as file:

student_old = file.readlines()

student_new = []

for list in student_old:

d = dict(eval(list))

student_new.append(d)

else:

return

ascORdesc = input("请选择(0升序;1降序)")

if ascORdesc == "0":

ascORdescBool = False # 标记变量,为False时表示升序,为True时表示降序

elif ascORdesc == "1":

ascORdescBool = True

else:

print("您输入的信息有误,请重新输入!")

sort()

mode = input("请选择排序方式(1按英语成绩排序;2按python成绩排序;3按C语言成绩排序;0按总成绩排序):")

if mode == "1": # 按英语成绩排序

student_new.sort(key=lambda x: x["english"], reverse=ascORdescBool)

elif mode == "2": # 按python成绩排序

student_new.sort(key=lambda x: x["python"], reverse=ascORdescBool)

elif mode == "3": # 按C语言成绩排序

student_new.sort(key=lambda x: x["c"], reverse=ascORdescBool)

elif mode == "0": # 按总成绩排序

student_new.sort(key=lambda x: x["english"] + x["python"] + x["c"], reverse=ascORdescBool)

else:

print("您的输入有误,请重新输入!")

sort()

show_student(student_new) # 显示排序结果

'''统计学生总数'''

def total():

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

if student_old:

print("一共有%d名学生!" % len(student_old))

else:

print("还没有录入学生信息")

else:

print("暂未保存数据信息")

'''显示所有学生信息'''

def show():

student_new = []

if os.path.exists(filename):

with open(filename, 'r') as rfile:

student_old = rfile.readlines()

for list in student_old:

student_new.append(eval(list))

if student_new:

show_student(student_new)

else:

print("暂未保存数据信息")

if __name__ == '__main__':

main()

关于管理系统的更多内容请点击《管理系统专题》进行学习

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

学生信息管理系统# include # include # include #include #include using namespace std; struct Student1 { char *num;//学号 char *subnum;//课程编号 char *subname;//课程编号 char *grade;//学分 char *score1;//平时成绩 char *score2;//实验成绩 char *score3;//卷面成绩 float m;//综合成绩 float n;//实得学分 Student1 *next; };//学号 姓名 性别 宿舍号码 电话号码 struct Student2 { char *num;//学号 char *name;//姓名 char *sex;//性别 char *roomnum;//宿舍号码 char *tel;//电话号码 Student2 * next; }; struct InfList { Student2* head; int size; }; struct CourseList { Student1 * head; int size; }; InfList create2()//创建一个空链表 { InfList list; list.head=0; list.size=0; return list; } CourseList create1()//创建一个空链表 { CourseList list; list.head = 0; list.size = 0; return list; } void deleteAll1(Student1 * p)//cc { delete []p->num; delete []p->grade; delete []p->subnum; delete []p->subname; } void deleteAll(Student2* p1)//in { delete []p1->name; delete []p1->num; delete []p1->roomnum; delete []p1->sex; delete []p1->tel; } void removeAll1 (CourseList & list) { Student1 *p1; while(list.head != NULL) { p1 = list.head; list.head = list.head->next; delete p1; } list.size = 0; } void removeAll (InfList & list) { Student2 *p1; while(list.head != NULL) { p1 = list.head; list.head = list.head->next; delete p1; } list.size = 0; } double getM(char* a,char *b,char *c)//计算综合成绩 { double m; double a1=atof(a); double b1=atof(b); double c1=atof(c); if(!strcmp(b,"-1")) { m=a1*(0.3)+c1*(0.7); return m; } else { m=a1*(0.15)+b1*(0.15)+c1*(0.7); return m; } } double getN(char *a,double b)//计算实得学分 { double n; double a1=atof(a); switch(int(b)/10) { case 10: case 9:n=a1*1;return n;break; case 8:n=a1*(0.8);return n;break; case 7:n=a1*(0.75);return n;break; case 6:n=a1*(0.6);return n;break; default:n=0;return n; } } CourseList LoadData1 (CourseList & list) //将成绩数据读入数组中,动态变量管理 { list=create1(); ::ifstream infile("b.txt",ios::in|ios::nocreate);//打开成绩文件 if(!infile) { cout<<"不能打开文件:b.txt"<>buff; if(infile.eof()) break; p1->num=new char[strlen(buff)+1]; strcpy(p1->num,buff); infile>>buff; p1->subnum=new char[strlen(buff)+1]; strcpy(p1->subnum,buff); infile>>buff; p1->subname=new char[strlen(buff)+1]; strcpy(p1->subname,buff); infile>>buff; p1->grade=new char[strlen(buff)+1]; strcpy(p1->grade,buff); infile>>buff; p1->score1=new char[strlen(buff)+1]; strcpy(p1->score1,buff); infile>>buff; p1->score2=new char[strlen(buff)+1]; strcpy(p1->score2,buff); infile>>buff; p1->score3=new char[strlen(buff)+1]; strcpy(p1->score3,buff); p1->m=getM(p1->score1,p1->score2,p1->score3); p1->n=getN(p1->grade,p1->m); p1->next=NULL; if (list.head==0) list.head=p1; else p2->next=p1; p2=p1; n++; } list.size=n; infile.close(); return list; } InfList LoadData (InfList & list) //将基本信息数据读入数组中,动态变量管理 { list=create2(); ::ifstream infile("a.txt",ios::in|ios::nocreate);//打开信息文件 if(!infile) { cout<<"不能打开文件:a.txt"<>buff; if(infile.eof()) break; p1->num=new char[strlen(buff)+1]; strcpy(p1->num,buff); infile>>buff; p1->name=new char[strlen(buff)+1]; strcpy(p1->name,buff); infile>>buff; p1->sex=new char[strlen(buff)+1]; strcpy(p1->sex,buff); infile>>buff; p1->roomnum=new char[strlen(buff)+1]; strcpy(p1->roomnum,buff); infile>>buff; p1->tel=new char[strlen(buff)+1]; strcpy(p1->tel,buff); p1->next=NULL; if (list.head==0) list.head=p1; else p2->next=p1; p2=p1; n++; } list.size=n; return list; infile.close(); } char * getChar(const char * sen) { cout<<sen<>c; while(!cin.good()) { cin.clear(); cin.getline(buffer, 80); cout<>c; } return c; } int getInt( const char * msg) { cout<<msg<>n; while(!cin.good()) { cin.clear(); cin.getline(buffer, 80); cout<>n; } return n; } void print(CourseList &list;)//输出所有数据 { system("cls");//清屏 LoadData1(list); cout<<setiosflags(ios::left); cout<<"学生成绩录入:"<<endl<<'\n'; Student1 *p = list.head; cout<<"学号"<<setw(10)<<"课程编号"<<setw(10)<<"课程名称"<<setw(9)<<"学分"; cout<<setw(8)<<"平时成绩"<<setw(10)<<"实验成绩"<<setw(10)<<"卷面成绩"; cout<<setw(10)<<"综合成绩"<<setw(10)<<"实得学分"<<endl; while (p!= NULL) { cout<<setw(3)<num<<setw(10)<subnum<<setw(12)<subname<<setw(9)<grade; cout<<setw(8)<score1<<setw(10)<score2<<setw(10)<score3; cout<<setw(10)<m<<setw(10)<n<next; } cout<<"size(学生个数)="<<list.size/3<<endl; cout<next; deleteAll1(p1); } removeAll1(list); } void Numprint(InfList & list) { LoadData(list); char num[20]; int m=0; strcpy(num,getChar("请输入学号:")); cout<num,num)) { cout<<"学号"<<setw(8)<<"宿舍号"<<setw(8)<<"姓名"<<setw(8)<<"性别"<<setw(8)<<"电话号"<<endl; cout<<setw(4)<num<<setw(8)<roomnum<<setw(8)<name<<setw(8)<sex<<setw(8)<tel<next; } if(m==0) { cout<<"未找到学生学号"<<num<<endl; cout<<endl; if(getInt("是否继续查询:(1/0)")==1) Numprint(list); cout<<endl; return; } cout<<endl; if(getInt("是否继续查询:(1/0)")==1) Numprint(list); cout<next; deleteAll(p1); } removeAll(list); } void Nameprint(InfList & list) { LoadData (list); char name [20]; int m=0; strcpy(name,getChar("输入姓名:")); Student2 * p = list.head; for(int i = 0; p != NULL; i++) { if (!strcmp(p->name,name)) { cout<<"学号"<<setw(8)<<"宿舍号"<<setw(8)<<"姓名"<<setw(8)<<"性别"<<setw(8)<<"电话号"<<endl; cout<<setw(4)<num<<setw(8)<roomnum<<setw(8)<name<<setw(8)<sex<<setw(8)<tel<next; } if(m==0) { cout<<"未找到学生"<<name<<'\n'; cout<<endl; if(getInt("是否继续查询:(1/0)")==1) Nameprint(list); cout<<endl; return; } cout<<endl; if(getInt("是否继续查询:(1/0)")==1) Nameprint(list); cout<next; deleteAll(p1); } removeAll(list); } void Rnumprint(InfList & list) { LoadData (list); char rnum [20]; int m=0; strcpy(rnum,getChar("输入宿舍号:")); Student2 * p = list.head; for(int i = 0; p != NULL; i++) { if (!strcmp(p->roomnum,rnum)) { cout<<"学号"<<setw(8)<<"宿舍号"<<setw(8)<<"姓名"<<setw(8)<<"性别"<<setw(8)<<"电话号"<<endl; cout<<setw(4)<num<<setw(8)<roomnum<<setw(8)<name<<setw(8)<sex<<setw(8)<tel<next; } if(m==0) { cout<<"未找到宿舍号"<<rnum<<'\n'; cout<<endl; if(getInt("是否继续查询:(1/0)")==1) Rnumprint( list); cout<<endl;return; } cout<<endl; if(getInt("是否继续查询:(1/0)")==1) Rnumprint(list); cout<next; deleteAll(p1); } removeAll(list); } void NumPrint(CourseList & list) { LoadData1(list); char num[20]; int s=0; double sum=0; strcpy(num,getChar("请输入学号:")); cout<num,num)) { if(s==0) { cout<<' '<<"学号"<<setw(10)<<"课程编号"<<setw(9)<<"课程名称"<<setw(10)<<"综合成绩"<<setw(10)<<"实得学分"<<endl; } cout<<setw(4)<num<<setw(10)<subnum<<setw(10)<subname<<setw(10)<m<<setw(10)<n<n; } p=p->next; } cout<<"共修:"<<s<<"科,"<<"实得总学分为:"<<sum<<endl; if(s==0) { cout<<"未找到学生学号"<<num<<endl; if(getInt("是否继续查询:(1/0)")==1) NumPrint(list); cout<<endl; return; } cout<<endl; if(getInt("是否继续查询:(1/0)")==1) NumPrint(list); cout<next; deleteAll1(p1); } removeAll1(list); } int Gochoice () { system("cls"); cout<<" \n\n"; cout<<" 学 生 基 本 信 息 查 询"; cout<<"\n\n \n\n"; cout<< "输入命令编号:\n\n"; cout<<" 1. 学号查询\n"<<endl; cout<<" 2. 姓名查询\n"<<endl; cout<<" 3. 宿舍号查询\n"<<endl; cout<<" 0. 返回菜单\n"<<endl; return getInt("选择命令:"); } void GetAll() { CourseList list; print(list); } void LookInf()//查询学生信息 { int choice; InfList list1; while((choice = Gochoice()) != 0) { switch(choice) { case 1: Numprint(list1); break; case 2: Nameprint(list1); break; case 3: Rnumprint(list1); break; default:cout<<"输入命令不存在\n"; } } } void LookGrade()//查询成绩 { CourseList list; NumPrint(list); } void Remove1 (InfList &list;, const int index)//删除a.txt中的数据 { system("cls"); cout<<setiosflags(ios::left); if (list.size == 0 || index list.size) return ; if (index == 0) { list.size--; Student2 *p = list.head; list.head = list.head->next; cout<<"删除文件a.txt中:"<<endl; cout<<' '<<"学号"<<setw(10)<<"姓名"<<setw(10)<<"性别"<<setw(10)<<"宿舍号"<<setw(10)<<"电话"<<endl; cout<<setw(4)<num<<setw(10)<name<<setw(10)<sex<<setw(10)<roomnum<<setw(10)<tel<<endl<<'\n'; delete p; return ; } Student2 *p1 = list.head, *p2 = p1; for(int i = 0; i next; } list.size--; p1->next = p2->next; cout<<"删除文件a.txt中:"<<endl; cout<<"学号"<<setw(8)<<"姓名"<<setw(10)<<"性别"<<setw(10)<<"宿舍号"<<setw(10)<<"电话"<<endl; cout<<setw(4)<num<<setw(10)<name<<setw(10)<sex<<setw(10)<roomnum<<setw(10)<tel<<endl<<'\n'; delete p2; } void Remove2 (CourseList & list2, const int index) { cout<<setiosflags(ios::left); if (list2.size == 0 || index = list2.size) return ; if (index == 0) { list2.size--; Student1 *p = list2.head; list2.head = list2.head->next; cout<<"删除文件b.txt中:"<<endl; cout<<"学号"<<' '<<"课程编号"<<' '<<"课程名称"<<' '<<"综合成绩"<<' '<<"实得学分"<<endl; cout<<setw(4)<num<<setw(10)<subnum<<setw(10)<subname<<setw(10)<m<<setw(10)<n<<endl<<'\n'; deleteAll1(p); delete p; return ; } Student1 *p1 = list2.head, *p2 = p1; for(int i = 0; i next; } list2.size--; p1->next = p2->next; cout<<"删除文件b.txt中:"<<endl; cout<<"学号"<<' '<<"课程编号"<<' '<<"课程名称"<<' '<<"综合成绩"<<' '<<"实得学分"<<endl; cout<<setw(4)<num<<setw(10)<subnum<<setw(10)<subname<<setw(10)<m<<setw(10)<n<<endl<num,num)==0) return i; p=p->next; } return -1; } int SearchList( CourseList & list, char * num) { Student1 *p = list.head; for(int i = 0; p != NULL; i++) { if (strcmp(p->num,num)==0) return i; p = p -> next; } return -1; } void DeleteOne()//删除函数 { cout<<setiosflags(ios::left); CourseList list1;//b.txt成绩 InfList list;//a.txt LoadData (list); LoadData1(list1); Student1 * pp=list1.head; Student2 * p=list.head; char num [20]; int sen,lin; strcpy(num,getChar("输入学号:")); sen=SearchData(list,num); if(sen==-1) cout<<"未找到学生"<<num; Remove1(list,sen); for(;;) { lin=SearchList(list1,num); if(lin==-1) break; Remove2(list1,lin); } ::ofstream outfile("a.txt"); if (!outfile ) { cout << "不能打开目的文件:"<<"a.txt"<<'\n'; return; } if((list.size)!=0) outfile<<"学号"<<'\t'<<"姓名"<<'\t'<<"性别"<<'\t'<<"宿舍号码"<<'\t'<<"电话号码"<<'\n'; else cout<<"文件已空"<<endl; Student2 * p1=list.head; while(p1!=NULL) { outfile<num<<'\t'<name<<'\t'<sex<<'\t'<roomnum<<'\t'<<'\t'<tel<next; } outfile.close(); ::ofstream outfile2("b.txt",ios::out); if (!outfile2 ) { cout << "不能打开目的文件:"<<"b.txt"<<'\n'; return; } if((list1.size)!=0) { outfile2<<"学号"<<' '<<"课程编号"<<' '<<"课程名称"<<' '<<"学分"<<' '<<"平时成绩"<<' '<<"实验成绩"; outfile2<<' '<<"卷面成绩"<<' '<<"综合成绩"<<' '<<"实得学分"<<'\n'; } else cout<<"文件已空"<subname,"VC++")==0) { if(pp1->next==NULL) { outfile2<num<<setw(6)<subnum; outfile2<<setw(6)<<' '<subname<<setw(5)<<' '<grade<<setw(4)<<' '<score1; outfile2<<setw(7)<<' '<score2<<setw(7)<<' '<score3; } else { outfile2<num<<setw(6)<subnum; outfile2<<setw(6)<<' '<subname<<setw(5)<<' '<grade<<setw(4)<<' '<score1; outfile2<<setw(7)<<' '<score2<<setw(7)<<' '<score3<<'\n';} } else { outfile2<num<<setw(6)<subnum; outfile2<<setw(6)<<' '<subname<<' '<grade<<setw(4)<<' '<score1; outfile2<<setw(7)<<' '<score2<<setw(7)<<' '<score3<next; } outfile2.close(); cout<<endl; if(getInt("是否继续删除:(1/0)")==1) DeleteOne(); cout<next; deleteAll1(p1); } removeAll1(list1); while(list.head!=NULL) { Student2*p1; p1=list.head; list.head=list.head->next; deleteAll(p1); } removeAll(list); } CourseList sortM(CourseList & list)//综合成绩降序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->mm) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } return list; } CourseList sortN(CourseList & list)//实得学分降序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(p1=list.head;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->nn) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } /*while(list.head!=NULL) { Student1*p1; p1=list.head; list.head=list.head->next; deleteAll1(p1); } removeAll1(list);*/ return list; } CourseList sortMM(CourseList & list)//综合成绩升序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(p1=list.head;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->m>p2->m) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } return list; } CourseList sortNN(CourseList & list)//实得学分升序排序 { LoadData1(list); Student1 *p1,*p2; char * data1; float data2; int n; n=list.size; p1=list.head; if (n==0||n==1) return list; for(p1=list.head;p1->next!=NULL;p1=p1->next) { p2=p1->next; for(;p2!=NULL;p2=p2->next) { if (p1->n>p2->n) { data1=p1->num; p1->num=p2->num; p2->num=data1; data1=p1->subnum; p1->subnum=p2->subnum; p2->subnum=data1; data1=p1->subname; p1->subname=p2->subname; p2->subname=data1; data1=p1->grade; p1->grade=p2->grade; p2->grade=data1; data1=p1->score1; p1->score1=p2->score1; p2->score1=data1; data1=p1->score2; p1->score2=p2->score2; p2->score2=data1; data1=p1->score3; p1->score3=p2->score3; p2->score3=data1; data2=p1->m; p1->m=p2->m; p2->m=data2; data2=p1->n; p1->n=p2->n; p2->n=data2; } } } /*while(list.head!=NULL) { Student1*p1; p1=list.head; list.head=list.head->next; deleteAll1(p1); } removeAll1(list);*/ return list; } void sortPrint (char * c,CourseList & list,char *cc)//输出实得学分排名 { system("cls"); Student1 * p = list.head; if (p==0) { cout<<"数据为空"<subname,c)&&!strcmp(cc,"实得学分")) { cout<<"第"<<n+1<<"名:"<<"学号:"<num<<'\t'<<"课程名称:"<subname<<'\t'<<"实得学分:"<n<subname,c)&&!strcmp(cc,"综合成绩")) { cout<<"第"<<n+1<<"名:"<<"学号:"<num<<'\t'<<"课程名称:"<subname<<'\t'<<"综合成绩:"<m<next; } if (n==0) cout<<"未找到"<<c<<'\n'; } int Select(){ cout<<"选择排序方式:"<<endl; cout<<" 1.升序"<<endl; cout<<" 2.降序"<<endl; cout<<" 0.退出"<<endl; return getInt("选择命令:"); } void Arrange1()//实得学分 { char str[3][10]={"大学物理","高等数学","VC++"}; char xf[]={"实得学分"}; int j=0; CourseList list1; char c[256]; strcpy(c,getChar("输入学科:")); for(int i=0;i<3;i++) { if (!strcmp(str[i],c)) j++; } if(j==0) cout<<"查无此学科"<<endl; else { int choice; while((choice= Select())!=0) { switch(choice) { case 1:sortPrint(c,sortNN(list1),xf);break; case 2:sortPrint(c,sortN(list1),xf);break; default:cout<<"输入命令不存在\n";cout<<"请重输:\n"<<endl;} } } if(getInt("是否继续排序:(1/0)")==1) Arrange1(); cout<next; deleteAll1(p1); } removeAll1(list1); } void Arrange2()//综合成绩 { char str[3][10]={"大学物理","高等数学","VC++"}; char zh[]={"综合成绩"}; int j=0; CourseList list1; char c[256]; strcpy(c,getChar("输入学科:")); for(int i=0;i<3;i++) { if (!strcmp(str[i],c)) j++; } if(j==0) cout<<"查无此学科"<<endl;//return; else { int choice; while((choice= Select())!=0) { switch(choice) { case 1:sortPrint(c,sortMM(list1),zh);break; case 2:sortPrint(c,sortM(list1),zh);break; default:cout<<"输入命令不存在\n"; cout<<"请重输:\n"<<endl; } } } if(getInt("是否继续排序:(1/0)")==1) Arrange2(); cout<next; deleteAll1(p1); } removeAll1(list1); } int enterChoice() { cout<<"\n\n"; cout<<" 学 生 信 息 管 理 系 统"; cout<<"\n\n\n\n"; cout<<"请输入命令编号:\n\n"; cout<<" 1. 学生成绩录入\n"; cout<<" 2. 学生信息查询\n"; cout<<" 3. 学生成绩查询\n"; cout<<" 4. 学生信息删除\n"; cout<<" 5. 实得学分排名\n"; cout<<" 6. 综合成绩排名\n"; cout<<" 0. 退出\n"; return getInt("选择命令:"); } void main() { int choice; while((choice = enterChoice()) != 0) { switch(choice) { case 1: GetAll();break; //学生成绩录入 case 2: LookInf(); system("cls"); break;//学生基本信息查询 case 3: LookGrade(); system("cls");break;//学生成绩查询 case 4: DeleteOne(); system("cls");break;//学生信息删除 case 5: Arrange1(); system("cls");break;//实得学分排名 case 6: Arrange2(); system("cls");break;//综合成绩排名 default:cout<<"输入命令不存在\n"; cout<<"请重输:\n"<<endl; } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值