本周代码时间20多个小时,主要用于完成小学期的数据结构作业的第一阶段与第二阶段。
6月19日:试实现迪杰斯特拉最短路径算法。后可使用迪杰斯特拉算法进行最短路径的实现,对于每一点的初始化了解较深,但是对于v0到每一个顶点的最短路径的循环迭代,已经更新确实难以弄清。最后从网上进行代码查找,书上进行选择理解,书上有现成源代码以及注释,进行手动推算。
6月20日:将给定的一系列数字插入初始为空的AVL树,请你输出最后生成的AVL树的根结点的值。对于给定一系列数字,插入初始为空的AVL树,可以输出最后生成的AVL树的根结点的值。对于平衡化的四种方式,LL,RR,LR,RL的函数不知道怎么何时应用,以及实现的平衡化的方法。最后在网上搜索左旋转,右旋转,左右旋转,右左旋转的实现图,实现平衡的方法,以及RL,LR,LL,RR的应用场景。
6月21日:按词频从小到大的顺序给出各个字符(不超过30个)的词频,根据词频构造哈夫曼树,给出每个字符的哈夫曼编码,并对给出的语句进行译码。可实现可以按树的先序顺序输出所有字符的编码,最后一行给出需译码的原文,但遇到对于输入的存在问题,一直不能很好实现字符与double类型的分别提取,对于哈夫曼树的结构体的定义存在一些问题,对于先序输出无法很好衔接,最后通过从网上进行代码查找,用scanf(“%c%lf”,&a,&b);解决第一个问题,必须要getchar(),消除会车影响,第二个结构体中加入了一个char ch,字段,方便填写,以及先序输出进行输出,加入这个字段后进行先序输出可以直接输出,为NULL则不输出来解决。
6月22日:实现输入首先给出两个正整数N(≤106)和M(≤10)在一行内按非递增顺序输出资产排前M位的大富翁的个人资产值。数字间以空格分隔,但结尾不得有多余空格。题较为简单,对于vector容易的一些函数不清楚不能很好书写代码查找了关于vector的相关函数功能进行学习。
6月23日:将团队程序进行整合,完成第一阶段实验报报
6月24日:实现了学生课程成绩的录入管理。实现学生课程信息的管理;实现基于成绩的各类查询、汇总、排序;实现各类统计信息的输出到文件;实现基于成绩的、排序;利用函数将文件提取信息到结构体中,每一次对结构操作完后,对文件进行整体替换,来达到实时更新
6月25日:进行验收,补充各类成绩的排行,成绩修改的功能。
第二阶段代码源码:
#include<iostream> #include<fstream> #include<set> #include<map> using namespace std; struct Course { string CourseName; string CourseCredit; }course[100]; struct STC { string StudentName; string CourseName; int grade; }stc[1000]; int Coursecount; int Studentcount; void menu(); void manage_course(); void grade_In(); void grade_search(); void grade_Analyse(); void grade_Sort(); void write_Course(Course course[],int n); int read_Course(Course course[]); int read_STC(STC stc[]); void write_STC(STC stc[],int n); void updataSTC(string CourseName); void subject_sort(string CourseName); void update_infor(); int main() { menu(); return 0; } void update_infor() { cout<<"--------------成绩修改--------------"<<endl; cout<<"请输入学生姓名"<<endl; string StudentName; cin >> StudentName; for(int i = 0;i < Coursecount ;i++) { if(stc[i].StudentName == StudentName) { cout<<"修改"<<stc[i].CourseName<<"成绩"<<endl; int grade; cin >> grade; stc[i].grade = grade; } } write_STC(stc,Studentcount); menu(); } void updataSTC(string CourseName) { Studentcount = read_STC(stc); for(int i = 0;i<Studentcount;i++) { if(stc[i].CourseName == CourseName) { for(int j = i;j <= Studentcount-1;j++) { stc[j].StudentName= stc[j+1].StudentName; stc[j].CourseName= stc[j+1].CourseName; stc[j].grade= stc[j+1].grade; } Studentcount--; } } write_STC(stc,Studentcount); } void write_Course(Course course[],int n) { fstream myFile; myFile.open("course.txt", ios::out | ios::binary); if (!myFile) { cout << "course.txt can't open!" << endl; abort(); } int count = n; myFile << count << endl<<endl; for (int i = 0; i < count; i++) { myFile << course[i].CourseName << "\t" << course[i].CourseCredit << endl; } myFile.close(); } int read_Course(Course course[]) { fstream myFile; myFile.open("course.txt", ios::in | ios::binary); if (!myFile) { cout << "course.txt can't open!" << endl; abort(); } int count; myFile.seekg(0); myFile >> count; for (int i = 0; i <= count; i++) { myFile >> course[i].CourseName >> course[i].CourseCredit; } myFile.close(); return count; } void write_STC(STC stc[],int n) { fstream myFile; myFile.open("stc.txt", ios::out | ios::binary); if (!myFile) { cout << "stc.txt can't open!" << endl; abort(); } int count = n; myFile << count << endl<<endl; for (int i = 0; i < count; i++) { myFile << stc[i].StudentName << "\t" << stc[i].CourseName << "\t" << stc[i].grade<< endl; } myFile.close(); } int read_STC(STC stc[]) { fstream myFile; myFile.open("stc.txt", ios::in | ios::binary); if (!myFile) { cout << "stc.txt can't open!" << endl; abort(); } int count; myFile.seekg(0); myFile >> count; for (int i = 0; i <= count; i++) { myFile >> stc[i].StudentName >> stc[i].CourseName >> stc[i].grade; } myFile.close(); return count; } void subject_sort(string CourseName) { cout<<endl; cout<<CourseName<<"的排名:"<<endl; map<double,string> maps; for(int i = 0;i<Studentcount;i++) { if(stc[i].CourseName == CourseName) { maps[stc[i].grade] = stc[i].StudentName; } } for(map<double,string>::reverse_iterator it=maps.rbegin();it!=maps.rend();it++) { cout<<it->second<<"\t\t"; cout<<it ->first<<endl; } menu(); } void manage_course() { cout<<"--------------管理课程信息-------------"<<endl; cout<<" 1 查看课程信息"<<endl; cout<<" 2 添加课程信息"<<endl; cout<<" 3 删除课程信息"<<endl; cout<<" 4 修改课程信息"<<endl; cout<<" 5 退出"<<endl; cout<<"---------------------------------------"<<endl; int choose; cin >> choose; switch(choose) { case 1: { cout<<"--------------查看课程信息-------------"<<endl; cout<<"课程名"<<"\t\t"<<"课程学分"<<endl; Coursecount = read_Course(course); for(int i = 0;i < Coursecount;i++) { if(course[i].CourseName.length()<8) { cout<<course[i].CourseName<<"\t"<<"\t"<<course[i].CourseCredit<<endl; } else { cout<<course[i].CourseName<<"\t"<<course[i].CourseCredit<<endl; } } manage_course(); } case 2: { cout<<"--------------添加课程信息-------------"<<endl; int flag = 1; while(flag) { cout<<"请输入课程名"<<endl; string CourseName; cin >> CourseName; cout<<"请输入课程学分"<<endl; string CourseCredit; cin >> CourseCredit; course[Coursecount].CourseName = CourseName; course[Coursecount++].CourseCredit = CourseCredit; cout<<"是否继续输入(y/n)"<<endl; string c; cin >> c; if(c=="y") { flag = 1; }else if(c=="n"){ flag = 0; }else{ cout<<"选项不存在,退出"<<endl; flag = 0; } } write_Course(course,Coursecount); manage_course(); } case 3: { cout<<"--------------删除课程信息-------------"<<endl; cout<<"请输入删除的课程的名称"<<endl; string CourseName; cin>>CourseName; for(int i = 0;i < Coursecount;i++) { if(course[i].CourseName==CourseName) { if(i == Coursecount-1) { Coursecount--; cout<<"删除"<<CourseName<<"成功"<<endl; break; } for(int j = i;j < Coursecount-1;j++) { course[j].CourseName=course[j+1].CourseName; course[j].CourseCredit=course[j+1].CourseCredit; } Coursecount--; cout<<"删除"<<CourseName<<"成功"<<endl; break; } } write_Course(course,Coursecount); updataSTC(CourseName); manage_course(); } case 4: { cout<<"--------------修改课程信息-------------"<<endl; cout<<"请输入修改的课程的名称"<<endl; string CourseName; cin>>CourseName; cout<<"请输入修改的课程的学分"<<endl; string CourseCredit; cin >> CourseCredit; for(int i = 0;i < Coursecount ;i++) { if(course[i].CourseName==CourseName) { course[i].CourseCredit=CourseCredit; cout<<"修改"<<CourseName<<"成功"<<endl; break; } } write_Course(course,Coursecount); manage_course(); } case 5: { menu(); return ; } default: break; } } void menu() { Coursecount = read_Course(course); cout<<"------------学生成绩管理系统-----------"<<endl; cout<<" 1 管理课程信息"<<endl; cout<<" 2 学生课程成绩录入"<<endl; cout<<" 3 成绩查询"<<endl; cout<<" 4 成绩汇总"<<endl; cout<<" 5 成绩排序"<<endl; cout<<" 6 课程排序"<<endl; cout<<" 7 学生课程成绩修改"<<endl; cout<<" 8 退出"<<endl; cout<<"---------------------------------------"<<endl; int choose; cin >> choose; switch(choose) { case 1: { manage_course(); break; } case 2: { grade_In(); break; } case 3: { Studentcount = read_STC(stc); grade_search(); break; } case 4: { Studentcount = read_STC(stc); grade_Analyse(); break; } case 5: { Studentcount = read_STC(stc); grade_Sort(); break; } case 6: { Studentcount = read_STC(stc); cout<<"--------------课程排序--------------"<<endl; cout<<"请输入查看的课程名称"<<endl; string CourseName; cin >> CourseName; subject_sort(CourseName); break; } case 7: { Studentcount = read_STC(stc); update_infor(); break; } case 8: { cout<<"欢迎下次使用"<<endl; exit(0); break; } default: break; } } /* set 统计人名 map 进行汇总排序 */ void grade_Sort() { cout<<"--------------成绩排序--------------"<<endl; set<string> s; map<double,string> maps; for(int i = 0;i<Studentcount;i++) { s.insert(stc[i].StudentName); } set<string>::iterator it; for(it=s.begin();it!=s.end();it++) { double temp = 0; for(int i = 0;i<Studentcount;i++) { if(*it == stc[i].StudentName) { temp += stc[i].grade; } } maps[temp] = *it; } cout<<"成绩单\t\t"; for(int i = 0;i < Coursecount;i++) { if(course[i].CourseName.length()<8) { cout<<course[i].CourseName<<"\t"<<"\t"; } else { cout<<course[i].CourseName<<"\t"; } } cout<<"平均分"<<endl; for(map<double,string>::reverse_iterator it=maps.rbegin();it!=maps.rend();it++) { cout<<it->second<<"\t\t"; for(int i = 0;i<Studentcount;i++) { if(it->second == stc[i].StudentName) { cout<<stc[i].grade<<"\t\t"; } } cout<<(it->first)/Coursecount<<endl; } menu(); } /* set 统计人名 遍历统计 */ void grade_Analyse() { cout<<"--------------成绩汇总--------------"<<endl; cout<<endl; cout<<"--------学生成绩单---------"<<endl; set<string> s; for(int i = 0;i<Studentcount;i++) { s.insert(stc[i].StudentName); } set<string>::iterator it; //定义前向迭代器 //中序遍历集合中的所有元素 cout<<endl; cout<<"成绩单\t\t"; for(int i = 0;i < Coursecount;i++) { if(course[i].CourseName.length()<8) { cout<<course[i].CourseName<<"\t"<<"\t"; } else { cout<<course[i].CourseName<<"\t"; } } cout<<"平均分"<<endl; for(it=s.begin();it!=s.end();it++) { cout<<*it<<"\t\t"; double temp = 0; for(int i = 0;i<Studentcount;i++) { if(*it == stc[i].StudentName) { cout<<stc[i].grade<<"\t\t"; temp += stc[i].grade; } } cout<<temp/Coursecount<<endl; } menu(); } void grade_search() { cout<<"--------------成绩查询--------------"<<endl; cout<<"请输入学生姓名"<<endl; string StudentName; cin >> StudentName; int flag = 0; for(int i = 0;i<Studentcount;i++) { if(stc[i].StudentName == StudentName) { flag = 1; break; } } if(flag) { cout<<StudentName<<"的成绩单"<<endl; }else { cout<<"无该学生信息"<<endl; menu(); } for(int i = 0;i<Studentcount;i++) { if(stc[i].StudentName == StudentName) { if(course[i%Coursecount].CourseName.length()<8) { cout<<course[i%Coursecount].CourseName<<"\t"<<"\t"<<stc[i].grade<<endl; } else { cout<<course[i%Coursecount].CourseName<<"\t"<<stc[i].grade<<endl; } } } menu(); } void grade_In() { cout<<"--------------学生课程成绩录入--------------"<<endl; int flag = 1; while(flag) { cout<<"请输入学生姓名"<<endl; string StudentName; cin >> StudentName; for(int i = 0;i<Coursecount;i++) { stc[Studentcount].StudentName = StudentName; cout<<"请输入"<<course[i].CourseName<<"的成绩"<<endl; stc[Studentcount].CourseName = course[i].CourseName; int grade; cin >> grade; stc[Studentcount++].grade = grade; } cout<<"是否继续输入(y/n)"<<endl; string c; cin >> c; if(c=="y") { flag = 1; }else if(c=="n"){ flag = 0; }else{ cout<<"选项不存在,退出"<<endl; flag = 0; } } /* cout<<"记录:"<<Studentcount<<endl; for(int i = 0;i<Studentcount;i++) { cout<<stc[i].StudentName<<" "<<stc[i].CourseName<<" "<<stc[i].grade<<endl; } */ write_STC(stc,Studentcount); menu(); }
标签:cout,stc,假期,void,第一周,grade,int,CourseName,进度 From: https://www.cnblogs.com/JIANGzihao0222/p/17504233.html