run.cpp

来自「二叉树的 学生成绩管理系统 c」· C++ 代码 · 共 239 行

CPP
239
字号
#include "Run.h"

void Run::InPut()
{
	ifstream in;
	in.open("Student.dat",ios::in||ios::nocreate);
	if(!in)
	{
		cout<<"\tThere is no dat,save it formost"<<endl;
	}
	Load();
	if(!Tree.CountNode(Tree.Root()))
	{
		cout<<"\tInput record wind up when the number inputed with 0 "<<endl;
		Student S;
		Tree.Initial(S);
	}
	else
	{
		cout<<"\tInput record wind up when the number inputed with 0 "<<endl;
		Student S;
		Tree.initial(S);
	}
}

void Run::Save()
{
	if(!Tree.CountNode(Tree.Root()))
	{
		cout<<"\tNo record to save!"<<endl;
		return;
	}
	ofstream out;
	out.open("Student.dat",ios::out);
	if(!out)
	{
		cout<<"\tCannot open the dat!"<<endl;
		exit(1);
	}
	out.close();
	Tree.InOrdering();
	cout<<"\t"<<Tree.CountNode(Tree.Root())<<"Record have been saved"<<endl;
}

void Run::Load()
{
	ifstream in;
	in.open("Student.dat",ios::in||ios::nocreate);
	if(!in)
	{
		cout<<"There is no dat"<<endl;
		return;
	}
	in.close();
	cout<<"\tLoad the dat..."<<endl;
	Tree.Construct();
	cout<<"\tLoad"<<Tree.CountNode(Tree.Root())<<"records"<<endl;
}

void Run::Display()
{
	Load();
	int choose;
	cout<<"\tChoose the display class"<<endl;
	cout<<"\t1.Current Information"<<endl;
	cout<<"\t2.Original Information"<<endl;
	cout<<"\t";
	cin>>choose;
	while(1)
	{
		if(choose<1||choose>2)
		{
			cout<<"\tError InPut please input again:"<<endl;
			cout<<"\t";
			cin>>choose;
		}
		else
			break;
	}
	switch(choose)
	{
	case 1:
		{
			if(!Tree.CountNode(Tree.Root()))
			{
				cout<<"\tThere is no imformation"<<endl;
				return;
			}
			cout<<"\tno\tname\tsex\tscore"<<endl;
		    Tree.PostOrdering();
		    cout<<endl;
		    break;
		}
	case 2:
		{
			if(!Tree.CountNode(Tree.Root()))
			{
				cout<<"\tThere is no imformation"<<endl;
			}
			Load();
			cout<<"\tno\tname\tsex\tscore"<<endl;
			Tree.PostOrdering();
			cout<<endl;
		    break;
		}
	}
}

void Run::Search()
{
	long nu;
	cout<<"\tInput number:"<<endl;
	cout<<"\t";
	cin>>nu;
	Student S(nu);
	cout<<"\tThe record you want is:"<<endl;
	if(!Tree.LevelScan(Tree.Root(),S))
		cout<<"\tThere is no record you want!"<<endl;
}

void Run::SortRecord()
{
	int choose;
	cout<<"\tSort the record class with no"<<endl;
	cout<<"\t1.Increase"<<endl;
	cout<<"\t2.Decrease"<<endl;
	cout<<"\t";
	cin>>choose;
	while(1)
	{
		if(choose<1||choose>2)
		{
			cout<<"\tError InPut please input again:"<<endl;
			cout<<"\t";
			cin>>choose;
		}
		else
			break;
	}
	switch(choose)
	{
	case 1:
		{
			if(!Tree.CountNode(Tree.Root()))
			{
				cout<<"\tThere is no imformation"<<endl;
				return;
			}
			cout<<"\tno\tname\tsex\tscore"<<endl;
		    Tree.InOrder();
		    cout<<endl;
		    break;
		}
	case 2:
		{
			if(!Tree.CountNode(Tree.Root()))
			{
				cout<<"\tThere is no imformation"<<endl;
				return;
			}
			cout<<"\tno\tname\tsex\tscore"<<endl;
			Tree.Exchange(Tree.Root());
			Tree.InOrder();
			cout<<endl;
		    break;
		}
	}
}

void Run::DeleteRecord()
{
	long nu;
	cout<<"\tInput the to be delete student's number:"<<endl;
	cout<<"\t";
	cin>>nu;
	Student S(nu);
	if(!Tree.LevelScan(Tree.Root(),S))
	{
		cout<<"\tThere is no record you want!"<<endl;
		cout<<"\tFailed in deleting!"<<endl;
	}	
	else
	{
		Tree.Remove(S,Tree.Root());
		cout<<"\tSuccess in deleting!"<<endl;
	}
}

void Run::Analyse()
{
	Student S;
	int choose;
	cout<<"\tNow Analyse the record"<<endl;
	cout<<"\t1.The most excellent student"<<endl;
	cout<<"\t2.The most stupid student"<<endl;
	cout<<"\t";
	cin>>choose;
	while(1)
	{
		if(choose<1||choose>2)
		{
			cout<<"\tError InPut please input again:"<<endl;
			cout<<"\t";
			cin>>choose;
		}
		else
			break;
	}
	switch(choose)
	{
	case 1:
		{
			if(!Tree.CountNode(Tree.Root()))
			{
				cout<<"\tThere is no imformation"<<endl;
				return;
			}
			Tree.PreOrdering();
			cout<<"\tno\tname\tsex\tscore"<<endl;
		    Tree.Max(Tree.Root(),S);
			cout<<S;
		    cout<<endl;
		    break;
		}
	case 2:
		{
			if(!Tree.CountNode(Tree.Root()))
			{
				cout<<"\tThere is no imformation"<<endl;
				return;
			}
			Tree.PreOrdering();
			cout<<"\tno\tname\tsex\tscore"<<endl;
			cout<<Tree.Min(Tree.Root())->Data();
			cout<<endl;
		    break;
		}
	}
}

⌨️ 快捷键说明

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