⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stusysdlg.cpp

📁 应该会有很多漏洞的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			stu = (CSutInfo*) arLoad.ReadObject( RUNTIME_CLASS(CSutInfo) );
			//arLoad >> pStuLoad[i];
			m_Student[i].m_StuNum=stu->m_StuNum;
			m_Student[i].m_StuName=stu->m_StuName;
			m_Student[i].m_Age=stu->m_Age;
			m_Student[i].m_Grade=stu->m_Grade;
			m_Student[i].m_Sex=stu->m_Sex;
			m_Student[i].SoreIndex=stu->SoreIndex;
			for(int j=0;j<10;j++)
			{
				m_Student[i].m_ScoreName[j]=stu->m_ScoreName[j];
				m_Student[i].m_ScoreTeacher[j]=stu->m_ScoreTeacher[j];
				m_Student[i].m_Score[j]=stu->m_Score[j];
			}
			i++;
		}
		MessageBox("载入完毕!");
	}
	arLoad.Close();
	StuFile.Close();
	StuList.close();
}

void CStuSysDlg::OnCourseSave() 
{
	// TODO: Add your command handler code here
	if( MessageBox("是否保存数据从而刷新原有数据?","提示",MB_ICONWARNING|MB_OKCANCEL)==IDOK )
	{
		fstream StuList;
		CFile CourseFile;

		StuList.open("StuList.dat",ios::out|ios::binary);
		CArchive arStore(&CourseFile, CArchive::store|CArchive::bNoFlushOnDelete);
		CourseFile.Open(_T("CourseFile.dat"),CFile::modeWrite|CFile::modeCreate);
	    if(!CourseFile||!StuList)
		{
			MessageBox("保存文件失败,请查看是否缺失文件CourseFile.dat");
		}
		else
		{
			StuList.write((char*)&m_BaseInfo, sizeof(m_BaseInfo));
			CCourse* pCouStore[MAXCOURSE]; 
			for(int j=0;j<=MAXCOURSE;j++)
			{
				pCouStore[j]=&m_Course[j];
			}

			int i=0;
			while(i<MAXCOURSE)
			{
				arStore<<pCouStore[i];
				i++;
			}
			MessageBox("保存完毕!下次登录可以再次载入");
		}
		arStore.Close();
		CourseFile.Close();
		StuList.close();
	}	
}

void CStuSysDlg::OnCourseLoad() 
{
	// TODO: Add your command handler code here
	CFile CourseFile;
	fstream StuList;

	CArchive arLoad(&CourseFile, CArchive::load);
	CCourse *course;
	CourseFile.Open(_T("CourseFile.dat"), CFile::modeRead);
	StuList.open("StuList.dat", ios::in|ios::binary);

	if(!CourseFile||!StuList)
	{
		MessageBox("载入文件失败,请查看是否缺失文件CourseFile.dat");
	}
	else
	{
		int i=0;
		StuList.read( (char*)&m_BaseInfo,sizeof(m_BaseInfo)) ;
		while(i<MAXCOURSE)
		{
			course=(CCourse*) arLoad.ReadObject( RUNTIME_CLASS(CCourse) );
			m_Course[i].m_CourseName=course->m_CourseName;
			m_Course[i].m_CourseTeacher=course->m_CourseTeacher;
			m_Course[i].m_ToIndex=course->m_ToIndex;
			for(int j=0;j<m_Course[i].m_ToIndex;j++)
			{
				m_Course[i].m_StuToCourse[j]=course->m_StuToCourse[j];
			}
			i++;
		}
		MessageBox("载入完毕!");
	}
	arLoad.Close();
	CourseFile.Close();
	StuList.close();
}

void CStuSysDlg::OnCourseEdit() 
{
	// TODO: Add your command handler code here
	POSITION pos=m_CourseList.GetFirstSelectedItemPosition();
	int m_index=m_CourseList.GetNextSelectedItem(pos);
	if(m_index==-1)
	{
		MessageBox("请选择要修改的课程!","提示");
		return;
	}

	CEditCourse dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnScoreAdd() 
{
	// TODO: Add your command handler code here
//	POSITION pos=m_StuList.GetFirstSelectedItemPosition();
//	CurrentIndex=m_StuList.GetNextSelectedItem(pos);
	CAddScore dlg;	
//	if(CurrentIndex==-1)
//	{
//		MessageBox("请选择要记录!","提示");
//		return;
//	}
	dlg.DoModal();
}

void CStuSysDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	//	TODO: Add your control notification handler code here
	//	POSITION pos=m_CourseList.GetFirstSelectedItemPosition();
	//	CurrentIndex=m_CourseList.GetNextSelectedItem(pos);
	CShowScore dlg;
	dlg.DoModal();
	*pResult = 0;
}

void CStuSysDlg::OnPeople() 
{
	// TODO: Add your command handler code here
	int Man=0,Girl=0;
	CString ManTem1,GirlTem1,show;
	int trueindex;
	for(int i=0;i<=m_BaseInfo.LastAdd;i++)
	{
		trueindex=m_BaseInfo.m_StudentIndex[i];
		if(m_Student[trueindex].m_Sex==0)
		{
			Man++;
		}
		else
		{
			Girl++;
		}
	}
	ManTem1.Format("%d",Man);
	GirlTem1.Format("%d",Girl);
	show="男生:"+ManTem1+"人   女生:"+GirlTem1+"人  ";
	MessageBox(show,"统计结果");
}

void CStuSysDlg::OnCourseAvescore() 
{
	// TODO: Add your command handler code here
	POSITION pos=m_CourseList.GetFirstSelectedItemPosition();
	int m_index=m_CourseList.GetNextSelectedItem(pos);
	if(m_index==-1)
	{
		MessageBox("请选择要统计的课程!","提示");
		return;
	}
	float total=0;//存储总分
	float avescore=0;//平均成绩
	int totalstu=0;//存储选课人数
	CString show;
	CString CName=m_Course[m_index].m_CourseName;//临时存储课程名
	int stuindex=m_Course[m_index].m_ToIndex;//课程列表中存储选课学生的列表指针

	for(int i=0;i<stuindex;i++)//遍历课程列表中存储选课学生的列表
	{
		int trueindex=m_Course[m_index].m_StuToCourse[i];//学生的hash地址
		int scoreindex=m_Student[trueindex].SoreIndex;//学生选课列表的指针
		for(int j=0;j<scoreindex;j++)//遍历学生选课列表
		{
			if(m_Student[trueindex].m_ScoreName[j]==m_Course[m_index].m_CourseName)
			{
				total+=m_Student[trueindex].m_Score[j];
				totalstu++;//若该学生列表中有此课程则,加入总分,并且人数加加
			}
		}
	}
	if(totalstu!=0)
		avescore=total/totalstu;
	CString temp;
	temp.Format("%f",avescore);
	show="课程 "+CName+" 的平均成绩为"+temp;
	MessageBox(show,"统计结果");
}

void CStuSysDlg::OnSearchNum() 
{
	// TODO: Add your command handler code here
	CSearchOnNum dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnSearchName() 
{
	// TODO: Add your command handler code here
	CSearchOnName dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnSearchTeacher() 
{
	// TODO: Add your command handler code here
	POSITION pos=m_CourseList.GetFirstSelectedItemPosition();
	int m_index=m_CourseList.GetNextSelectedItem(pos);
	if(m_index==-1)
	{
		MessageBox("请选择要查找的课程!","提示");
		return ;
	}
	CSearchOnTeach dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnSearchGrade() 
{
	// TODO: Add your command handler code here
	CSearchOnGrade dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnSortTotal() 
{
	// TODO: Add your command handler code here
	CSortTotal dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnSortNum() 
{
	// TODO: Add your command handler code here

	struct node
	{
		int index;
		struct node *next;
	};
	
	struct node *p=NULL,*s=NULL,*h=NULL;
	int last=m_BaseInfo.LastAdd;
/*	p=s=new struct node;
	p->index=m_BaseInfo.m_StudentIndex[0];
	h=NULL;
	for(int point=1; point<=last;point++)
	{
		if(point==1)
		{
			h=p;
		}
		else
			s->next=p;
		s=p;
		p=new struct node;
		p->index=m_BaseInfo.m_StudentIndex[point];
	}
	s->next=NULL;*/
	//建链表的另一种途径
//	h=new struct node;
//	p=h;
	for(int point=0; point<=last;point++)
	{
		s=new struct node;
		s->index=m_BaseInfo.m_StudentIndex[point];
		s->next=NULL;
		if(point==0)
		{
			p=s;
			h=p;
		}
		else
		{
			p->next=s;
			p=s;
		}
	}	
	
/*	struct node *t1,*t2,*t3,*t4;//检查head链表使用
  t1=h->next;
   t2=t1->next;
   t3=t2->next;
   t4=t3->next;*/
	p=h;
	struct node *head[10];//各链队的首指针
	struct node *tail[10];//各链队的尾指针
	struct node *t;		  //一个指针起标志作用
	int i,j,k;
	for(i=0; i<=4; i++)
	{
		for(j=0;j<10;j++)
		{
			head[j]=tail[j]=NULL;
		}
		while(p!=NULL)//对链表中每个结点进行循环,从而按各基数分配
		{
			switch (i)
			{
				case 0:
				{
					CString temp;
					temp=m_Student[p->index].m_StuNum.Mid(8,1);
					k=_ttoi(temp);
					break;
				}
				case 1:
				{
					k=_ttoi(m_Student[p->index].m_StuNum.Mid(6,1));
					break;

				}
				case 2:
				{
					k=_ttoi(m_Student[p->index].m_StuNum.Mid(4,1));
					break;
				}
				case 3:
				{
					k=_ttoi(m_Student[p->index].m_StuNum.Mid(3,1));
					break;
				}
				case 4:
				{
					k=_ttoi(m_Student[p->index].m_StuNum.Mid(1,1));
					break;
				}
			}
			if(head[k]==NULL)
			{
				head[k]=p;
				tail[k]=p;
			}
			else
			{
				tail[k]->next=p;
				tail[k]=p;
			}
			p=p->next;
		}
		p=NULL;//重新用p收集所有结点
		for(j=0;j<10;j++)//对每一个链队进行收集
		{
			if(head[j]!=NULL)//对一个链队循环,若链队为空退出
			{
				if(p==NULL)
				{
					p=head[j];
					t=tail[j];
				}
				else
				{
					t->next=head[j];
					t=tail[j];
				}
			}

		}
		t->next=NULL;//最后一个结点的next域为NULL
	}

	int nCount = m_StuList.GetItemCount();
	for (int jj=0; jj<nCount; jj++)
	{
		m_StuList.DeleteItem(0);
	}
	//将输入的全部记录显示
	struct node *q;
	q=p;
	int listindex=0;
	while(q!=NULL)
	{
	
		//显示学号
		m_StuList.InsertItem(listindex,m_Student[q->index].m_StuNum);//插入行 
		//显示姓名
		m_StuList.SetItemText(listindex,1,m_Student[q->index].m_StuName);
		//显示性别
		if(m_Student[q->index].m_Sex==0)
			m_StuList.SetItemText(listindex,2,"男");
		else
			m_StuList.SetItemText(listindex,2,"女");
		//显示年龄
		CString temp;
		temp.Format("%d",m_Student[q->index].m_Age);
		m_StuList.SetItemText(listindex,3,temp);
		//显示年级
		if(m_Student[q->index].m_Grade==0)
			m_StuList.SetItemText(listindex,4,"大一");
		else if(m_Student[q->index].m_Grade==1)
			m_StuList.SetItemText(listindex,4,"大二");
		else if(m_Student[q->index].m_Grade==2)
			m_StuList.SetItemText(listindex,4,"大三");
		else 
			m_StuList.SetItemText(listindex,4,"大四");
		q=q->next;
		listindex++;
	}
	MessageBox("排序完毕","提示");
}

void CStuSysDlg::OnSortScore() 
{
	// TODO: Add your command handler code here
	POSITION pos=m_CourseList.GetFirstSelectedItemPosition();
	int m_index=m_CourseList.GetNextSelectedItem(pos);
	if(m_index==-1)
	{
		MessageBox("请选择要排序的的课程!","提示");
		return ;
	}
	CSortSing dlg1;
	dlg1.DoModal();
}

void CStuSysDlg::OnSortAge() 
{
	// TODO: Add your command handler code here
	int max=m_BaseInfo.LastAdd;
	int age[MAXSTU];
	int HashAdd[MAXSTU];
	int trueindex;
	for(int i=0;i<=max;i++)
	{
		trueindex=m_BaseInfo.m_StudentIndex[i];
		age[i]=m_Student[trueindex].m_Age;
		HashAdd[i]=trueindex;
	}

	int ii,jj,kk;
	int	  tempage;
	int   tempindex;
	for(ii=0; ii<=max; ii++)
	{
		kk=ii;
		for(jj=ii+1;jj<=max;jj++)
		{
			if(age[jj]<age[kk])
				kk=jj;
		}
		if(kk!=ii)
		{
			tempage=age[ii];
			tempindex=HashAdd[ii];

			age[ii]=age[kk];
			HashAdd[ii]=HashAdd[kk];

			age[kk]=tempage;
			HashAdd[kk]=tempindex;
		}
	}	
	//删除原来列表信息
	int nCount = m_StuList.GetItemCount();
	for (int m=0; m<nCount; m++)
	{
		m_StuList.DeleteItem(0);
	}
	//显示
	//显示学号
	for(int j=0;j<=max;j++)
	{
		int index=HashAdd[j];
		m_StuList.InsertItem(j,m_Student[index].m_StuNum);//插入行 
		//显示姓名
		m_StuList.SetItemText(j,1,m_Student[index].m_StuName);
		//显示性别
		if(m_Student[index].m_Sex==0)
			m_StuList.SetItemText(j,2,"男");
		else
			m_StuList.SetItemText(j,2,"女");
		//显示年龄
		CString temp;
		temp.Format("%d",m_Student[index].m_Age);
		m_StuList.SetItemText(j,3,temp);
		//显示年级
		if(m_Student[index].m_Grade==0)
			m_StuList.SetItemText(j,4,"大一");
		else if(m_Student[index].m_Grade==1)
			m_StuList.SetItemText(j,4,"大二");
		else if(m_Student[index].m_Grade==2)
			m_StuList.SetItemText(j,4,"大三");
		else 
			m_StuList.SetItemText(j,4,"大四");
	}
	MessageBox("排序完毕","提示");

}

void CStuSysDlg::OnSearchSex() 
{
	// TODO: Add your command handler code here
	CSearchOnSex dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnVersionInfo() 
{
	// TODO: Add your command handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}

void CStuSysDlg::OnHelp() 
{
	// TODO: Add your command handler code here
	CHelp dlg;
	dlg.DoModal();
}

int CStuSysDlg::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex) 
{
	// TODO: Add your message handler code here and/or call default
	
	return CDialog::OnVKeyToItem(nKey, pListBox, nIndex);
}

void CStuSysDlg::OnCancelMode() 
{
	CDialog::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -