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

📄 application.cpp

📁 基于链表模板的学生成绩管理系统
💻 CPP
字号:
# include "Application.h"

void Application::AddData()
{
	int sno;
	string sname;
	double math;
	double chinese;
	cout<<"Please input the information of a student :"<<endl;
	cin>>sno>>sname>>math>>chinese;
	Student s(sno,sname,math,chinese);
	l.Insert(s);
}

void Application::Save()
{
	ofstream of;
	of.open("Student.txt",ios::out);
	l.Save(of);
	of.clear();
	of.close();
} 

void Application::Read()
{
	ifstream in;
	in.open("Student.txt",ios::in);
	l.Clear();
	l.Read(in);
	in.clear();
	in.close();
}

void Application::Print()
{
	cout<<"sno"<<"\t"<<"sname"<<"\t"<<"math"<<"\t"<<"chinese"<<"\t"<<"avg"<<"\t"<<endl;
	l.Print();
}

void Application::Find()
{
	string sname;
	int sno;
	cout<<"Now Finding the student's information in detail:"<<endl;
	cout<<"1.Input sno:"<<endl;
	cout<<"2.Input sname:"<<endl;
	int no;
	cin>>no;
	if(no==1)
	{
		cout<<"Now you can input the sno:"<<endl;
		cin>>sno;
		Student stu(sno,"",0.0,0.0);
		l.FindAndPrint(stu);
	}
	else if(no==2)
	{
		cout<<"Now you can input the sname:"<<endl;
		cin>>sname;
		Student stu(0,sname,0.0,0.0);
		l.FindAndPrint(stu);
	}
	else
		cout<<"Error input!"<<endl;
}

void Application::Delete()
{
	string sname;
	int sno;
	cout<<"Now Deleting the student's information:"<<endl;
	cout<<"1.Input sno:"<<endl;
	cout<<"2.Input sname:"<<endl;
	int no;
	cin>>no;
	if(no==1)
	{
		cout<<"Now you can input the sno:"<<endl;
		cin>>sno;
		Student stu(sno,"",0.0,0.0);
		l.Delete(stu);
		return;
	}
	else if(no==2)
	{
		cout<<"Now you can input the sname:"<<endl;
		cin>>sname;
		Student stu(0,sname,0.0,0.0);
		l.Delete(stu);
		return;
	}
	else
		cout<<"Error input!"<<endl;
}

void Application::Sort()
{
	cout<<"Now Sorting the student's information:"<<endl;
	cout<<"1.Sort with sno:"<<endl;
	cout<<"2.Sort with sname:"<<endl;
	cout<<"3.Sort with math score:"<<endl;
	cout<<"4.Sort with chinese score"<<endl;
	cout<<"5.Sort with average score"<<endl;
	int no;
	cin>>no;
	if(no==1)
	{
		Student temp;
		for(ListItem<Student> *p=l.GetFront();p!=NULL;p=p->GetNext())
		{
			for(ListItem<Student> *q=p->GetNext();q!=NULL;q=q->GetNext())
			{
				if(p->GetValue().GetSno()>q->GetValue().GetSno())
				{
					temp=q->GetValue();
					q->SetValue(p->GetValue());
					p->SetValue(temp);
				}
			}
		}
	}
	else if(no==2)
	{
		Student temp;
		for(ListItem<Student> *p=l.GetFront();p!=NULL;p=p->GetNext())
		{
			for(ListItem<Student> *q=p->GetNext();q!=NULL;q=q->GetNext())
			{
				if(p->GetValue().GetSname()>q->GetValue().GetSname())
				{
					temp=q->GetValue();
					q->SetValue(p->GetValue());
					p->SetValue(temp);
				}
			}
		}
	}
	else if(no==3)
	{
		Student temp;
		for(ListItem<Student> *p=l.GetFront();p!=NULL;p=p->GetNext())
		{
			for(ListItem<Student> *q=p->GetNext();q!=NULL;q=q->GetNext())
			{
				if(p->GetValue().GetMath()>q->GetValue().GetMath())
				{
					temp=q->GetValue();
					q->SetValue(p->GetValue());
					p->SetValue(temp);
				}
			}
		}
	}
	else if(no==4)
	{
		Student temp;
		for(ListItem<Student> *p=l.GetFront();p!=NULL;p=p->GetNext())
		{
			for(ListItem<Student> *q=p->GetNext();q!=NULL;q=q->GetNext())
			{
				if(p->GetValue().GetChinese()>q->GetValue().GetChinese())
				{
					temp=q->GetValue();
					q->SetValue(p->GetValue());
					p->SetValue(temp);
				}
			}
		}
	}
	else if(no==5)
	{
		Student temp;
		for(ListItem<Student> *p=l.GetFront();p!=NULL;p=p->GetNext())
		{
			for(ListItem<Student> *q=p->GetNext();q!=NULL;q=q->GetNext())
			{
				if(p->GetValue().GetAvg()>q->GetValue().GetAvg())
				{
					temp=q->GetValue();
					q->SetValue(p->GetValue());
					p->SetValue(temp);
				}
			}
		}
	}
	else
		cout<<"Error input!"<<endl;
}

void Application::Analyse()
{
	cout<<"Now Analysing the student's information:"<<endl;
	cout<<"1.Create the stu_mean file:"<<endl;
	cout<<"2.Read and the stu_mean file:"<<endl;
	cout<<"3.Create the stu_bad file:"<<endl;
	cout<<"4.Read and the stu_bad file:"<<endl;
	int no;
	cin>>no;
	if(no==1)
	{
		ofstream of;
		of.open("Stu_mean.txt",ios::out);
		if(!of)
		{
			cerr<<"The file cannot be created!"<<endl;
			return;
		}
		for(ListItem<Student> *p=l.GetFront();p!=NULL;p=p->GetNext())
		{
			sm s={p->GetValue().GetSname(),p->GetValue().GetAvg()};
			of<<s.sname<<endl;
			of<<s.avg<<endl;
		}
		of.close();
		cout<<"The file has been created!"<<endl;
	}
	else if(no==2)
	{
		stu_mean.clear();
		ifstream in;
		in.open("Stu_mean.txt");
		if(!in)
		{
			cerr<<"The file cannot be read!"<<endl;
			return;
		}
		sm s;
		while(in>>s)
		{
			stu_mean.push_back(s);
		}
		in.close();
		cout<<"sname"<<"\t"<<"avg"<<"\t"<<endl;
		vector<sm>::iterator it=stu_mean.begin();
		while(it!=stu_mean.end())
		{
			cout<<it->sname<<"\t"<<it->avg<<endl;
			it++;
		}
	}
	else if(no==3)
	{
		ofstream on;
		on.open("Stu_bad.txt",ios::out);
		if(!on)
		{
			cerr<<"The file has been created!"<<endl;
			return;
		}
		ListItem<Student>* p=l.GetFront();
		while(p!=NULL)
		{
			if(p->GetValue().GetMath()<60&&p->GetValue().GetChinese()<60)
			{
				on<<p->GetValue();
			}
			p=p->GetNext();
		}
		on.close();
		cout<<"The file has been created!"<<endl;
	}
	else if(no==4)
	{
		stu_bad.clear();
		ifstream in;
		in.open("Stu_bad.txt");
		if(!in)
		{
			cerr<<"The file cannot be read!"<<endl;
			return;
		}
		Student s;
		while(in>>s)
		{
			stu_bad.push_back(s);
		}
		in.close();
		cout<<"sno"<<"\t"<<"sname"<<"\t"<<"math"<<"\t"<<"chinese"<<"\t"<<"avg"<<"\t"<<endl;
		vector<Student>::iterator it=stu_bad.begin();
		while(it!=stu_bad.end())
		{
			cout<<*it;
			it++;
		}
	}
	else
		cout<<"Error input!"<<endl;
}


void Application::Run()
{
	bool run=1;
	while(run)
	{
		cout<<"**********************************"<<endl;
		cout<<"***Student Management System******"<<endl;
		cout<<"***Produced by Sapphire Lee*******"<<endl;
		cout<<"**********************************"<<endl;
		cout<<"Now Analysing the student's information"<<endl;
	    cout<<"1.Reading infomation from file"<<endl;
	    cout<<"2.Saving infomation to file"<<endl;
	    cout<<"3.Adding infomation"<<endl;
	    cout<<"4.Searching infomation"<<endl;
		cout<<"5.Deleting infomation"<<endl;
		cout<<"6.Sorting infomation"<<endl;
		cout<<"7.Analysing infomation"<<endl;
		cout<<"8.Printing infomation"<<endl;
		cout<<"9.Exit"<<endl;
		int choose;
		cout<<"Please input the choice:"<<endl;
		cin>>choose;
		switch(choose)
		{
		case 1:
			Read();
			Print();
			break;
		case 2:
			Save();
			break;
		case 3:
			AddData();
			break;
		case 4:
			Find();
			break;
		case 5:
			Delete();
			break;
		case 6:
			Sort();
			break;
		case 7:
			Analyse();
			break;
		case 8:
			Print();
			break;
		case 9:
			run=0;
			break;
		}
	}
}

⌨️ 快捷键说明

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