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

📄 application1.cpp

📁 学生信息管理系统:本程序可以实现输入
💻 CPP
字号:
#include "Application1.h"
#include "StudentInfo.h"
#include "ListNode.h"
#include "LinkedList.h"
#include <fstream.h>
#include <stdlib.h>

Application::Application()
{
  list.ClearList();
}

Application::~Application()
{
  list.ClearList();
}
void Application::Process()
{
	cout<<"请输入功能序号choice:";
    int choice;
	cin>>choice;
	switch(choice){
	case 1:	
		(*this).Insert();
		break;
	case 2:
		(*this).Delete();
		break;
	case 3:
		(*this).Find();
		break;
	case 4:
		(*this).Update();
		break;
	case 5:
		(*this).Sort();
		break;
	case 6:
		(*this).Print();
		break;
	case 7:
		(*this).Analyze();
		break;
	case 8:
		(*this).Save();
		break;
	case 9:
		(*this).Load();
		break;
	default:
		cout<<"您输入的序号有误,请重新输入!!"<<endl;
	}
}

void Application::PrintTip()
{
	cout.setf(ios::right);
	cout<<"***************************学生信息管理系统*****************************"<<endl;
	cout<<setw(35)<<"作者: 闫晖"<<endl;
	cout<<setw(40)<<"版权所有,不得复制!!"<<endl<<endl<<endl;
    cout<<setw(40)<<"[q] 退出系统         "<<endl;	
	cout<<setw(40)<<"[1] 添加学生信息     "<<endl;
	cout<<setw(40)<<"[2] 删除学生信息     "<<endl;
	cout<<setw(40)<<"[3] 查询学生信息     "<<endl;
	cout<<setw(40)<<"[4] 更新学生信息     "<<endl;
	cout<<setw(40)<<"[5] 按成绩排序       "<<endl;
	cout<<setw(40)<<"[6] 输出学生信息     "<<endl;
	cout<<setw(40)<<"[7] 成绩分析器       "<<endl;
	cout<<setw(40)<<"[8] 把链表保存到文件 "<<endl;	
	cout<<setw(40)<<"[9] 从文件输出链表   "<<endl;
    cout<<"*********************************************************************"<<endl;
}

char Application::GetResponse() const
{
	char ch;
//	char chh;
	cout<<"按q退出学生信息系统,回车键继续输入功能选项!!";
//	cin.get(chh);
	cin.get(ch);
	cout<<endl;
	return ch;
}



void Application::Insert()
{
	char ch1,ch2;
	int x=0,y=0;
        Student q;
		do{		
			cout<<"您选择的是添加学生信息"<<endl;
			q.InputInfo();
           	cout<<"********************请选择插入的方式*******************"<<endl;
            cout.setf(ios::right);
			cout<<setw(30)<<"[1] 在链头插入    "<<endl;
			cout<<setw(30)<<"[2] 在指定位置插入"<<endl;
			cout<<setw(30)<<"[3] 在链尾插入    "<<endl;
			cout<<setw(30)<<"[4] 按顺序插入    "<<endl;
	        cout<<"*********************************************************"<<endl;
			cout<<endl;
		    cout<<"请输入要插入的位置:"<<endl;
			cin>>x;
			if(x==1){
				list.InsertFront(q);
				cout<<endl;
			}
			if(x==2){
			   cout<<"请输入要插入的位置(基于0):"<<endl;
			   cin>>y;
				list.InsertAt(q,y);
				cout<<endl;
			
			
			}
			if(x==3){
				list.InsertRear(q);	
				cout<<endl;
			
			
			}
			if(x==4){
				list.InsertOrder(q);
				cout<<endl;
			}
				cout<<"按回车键继续添加,q退出添加学生信息功能!!"<<endl;
				cin.get(ch2);
				cin.get(ch1);
		}while(ch1=='\n');


}

void Application::Delete()
{		
	char ch1,ch2;
	Student q;
	int x,y;
	do{
		   cout<<"您选择的是删除学生信息:"<<endl;
            cout<<"********************请选择删除方式: ********************"<<endl;
            cout<<setw(40)<<"[1] 删除链首的学生信息    "<<endl;
            cout<<setw(40)<<"[2] 删除链尾的学生信息    "<<endl;
            cout<<setw(40)<<"[3] 删除成绩最好的学生    "<<endl;
            cout<<setw(40)<<"[4] 删除成绩最坏的学生    "<<endl;
            cout<<setw(40)<<"[5] 已知该生在链表中的位置"<<endl;
            cout<<setw(40)<<"[6] 删除链表中所有信息    "<<endl;
            cout<<"********************************************************"<<endl;
			cin>>x;
			if(x==1){
				if(list.DeleteFront(q)){
					cout<<"您已经删除该生的信息!"<<endl;
				}
				else {
					cout<<"空链表!请先添加学生信息!!"<<endl;
				}
				cout<<endl;
			}
			    
			if(x==2){
				if(list.DeleteNode(list.DataOfNode(list.Length()-1))){
					cout<<"您已经删除该生的信息!"<<endl;
				}
				else{
                    cout<<"空链表!请先添加学生信息!!"<<endl;
				}
				cout<<endl;
			}
				
			if(x==3){
				if(list.DeleteMax(q)){
		          cout<<"您已经删除该生的信息!"<<endl;
				}
				else {
					cout<<"空链表!请先添加学生信息!!"<<endl;
				}
				cout<<endl;
			}
		
			if(x==4){
				if(list.DeleteMin(q)){
		          cout<<"您已经删除该生的信息!"<<endl;
				}
				else {
					cout<<"空链表!请先添加学生信息!!"<<endl;
				}
				cout<<endl;
			}
			if(x==5){
				cout<<"请输入其位子<基于0>:"<<endl;
				cin>>y;
				while(y>(list.Length()-1)){
					cout<<"您输入的位置太大,请重新输入正确的位置!!"<<endl;
					cin>>y;
				}
				if(list.DeleteAt(y,q)){
					cout<<"您已经删除该生的信息!"<<endl;
				}
				else{
					cout<<"链表为空!!"<<endl;
				}
				cout<<endl;
			}
			if(x==6){
				list.ClearList();
				cout<<"您已经删除链表的全部信息!!"<<endl;
			}
                cout<<"按回车键继续删除,q退出删除学生信息功能!!"<<endl;
	            cin.get(ch1);
				cin.get(ch2);
	}while(ch2=='\n');
			
				
			


}

void Application::Find()
{    char ch1,ch2; 
    int n,y,i=0,k=0;
	ULInt number;
	double score;
	Student s;
	do{
	if(list.IsEmpty()){
		cout<<"链表为空!请先添加学生信息!!"<<endl;
	}
	else{
	cout<<"您选择的是查询学生信息"<<endl;
			cout<<"*****************请选择查找方式*********************"<<endl;
			cout<<setw(40)<<"[1] 查找链首的学生信息    "<<endl;
	        cout<<setw(40)<<"[2] 查找链尾的学生信息    "<<endl;
			cout<<setw(40)<<"[3] 查找成绩最好的学生信息"<<endl;
	        cout<<setw(40)<<"[4] 查找成绩最差的学生信息"<<endl;
			cout<<setw(40)<<"[5] 以知在链表中的位置    "<<endl;
			cout<<setw(40)<<"[6] 已知该生姓名          "<<endl;
			cout<<setw(40)<<"[7] 已知该生学号          "<<endl;
			cout<<setw(40)<<"[8] 已知该生学习成绩      "<<endl;
			cout<<"****************************************************"<<endl;
			cout<<"请选择您要查找的方式"<<endl;
			cin>>n;
			if(n==1){
				cout<<"您所查询的学生信息为:"<<endl;
			 cout<<list[0]<<endl;
				
			}
			if(n==2){
				cout<<"您所查询的成绩最好的学生信息为:"<<endl;
				cout<<list[list.Length()-1]<<endl;
			}
			if(n==3){
				cout<<"您所查询的成绩最好的学生信息为:"<<endl;
				cout<<list.Max()->data<<endl;
			}
			if(n==4){
				cout<<"您所查询的成绩最差的学生信息为:"<<endl;
				cout<<list.Min()->data<<endl;
			}
			if(n==5){
				cout<<"请输入在链表中的位置(基于0):"<<endl;
			    cin>>y;
				cout<<list.DataOfNode(y)<<endl;
			}
		//	if(n==6){
		//		cout<<"请输入要查询学生的姓名:"<<endl;
		//		cin>>ch;
		//	for( i=0;i<list.Length();i++)
		//	{
		//		list.DataOfNode(i)).Getname()==
				
		//	}
			
			if(n==7){
				cout<<"请输入要查询学生的学号number:"<<endl;
				cin>>number;
				cout<<"您所查询的学生信息为:"<<endl;
				for( i=0;i<list.Length();i++)
				{
				   k=((list.DataOfNode(i)). Get_Student_number()==number);
				   if(k==1){
				   s=list.DataOfNode(i);
					    break;
				   }
				}
				if(k==1)
				    cout<<s;
					else{
						cout<<"链表中无此人!!"<<endl;
					}
			}
			if(n==8){
			cout<<"请输入要查询学生的学习成绩score:"<<endl;
				cin>>score;
				cout<<"您所查询的学生信息为:"<<endl;
				for( i=0;i<list.Length();i++)
				{
				   k=((list.DataOfNode(i)). Get_Score()==score);
				   if(k==1){
				   s=list.DataOfNode(i);
					    break;
				   }
				}
				if(k==1)
				    cout<<s;
					else{
						cout<<"链表中无此人!!"<<endl;
					}
			}
	}
				cout<<"按回车键继续添加,q退出查询学生信息功能!!"<<endl;
				cin.get(ch1);
				cin.get(ch2);
}while(ch2=='\n');
			

			cout<<endl;
}

void Application::Update()
{
	char ch1,ch2;
	Student q;
	int y;
	do{
		if(list.IsEmpty()){
			cout<<"链表为空!请先添加学生信息!!"<<endl;
		}
		else{
		  cout<<"您选择的是更新学生信息:"<<endl;
				cout<<"********************请选择更新方式: ********************"<<endl;
				cout<<setw(40)<<"[1] 以知该生在链表中的位置"<<endl;			
				cout<<"********************************************************"<<endl;
				cout<<"请输入其位置:"<<endl;
				cin>>y;
				list.DeleteAt(y,q);
				q.InputInfo();
				list.InsertAt(q,y);
				cout<<"您已经将其信息更新!!"<<endl;
				cout<<endl;
		}
				cout<<"按回车键继续添加,q退出更新学生信息功能!!"<<endl;
				cin.get(ch1);
				cin.get(ch2);
	}while(ch2=='\n');
				
}
	void Application::Sort()
	{
		char ch1,ch2;
		int x;
	do{
		if(list.IsEmpty()){
			cout<<"链表为空!请先添加学生信息!!"<<endl;
		}
		else{
			cout<<"您选择的是按成绩排序!"<<endl;
				cout<<"*********************请选择排序方式**********************"<<endl;
				cout<<setw(40)<<"[0] 成绩从低到高"<<endl;
				cout<<setw(40)<<"[1] 成绩从高到低"<<endl;
				cout<<"**********************************************************:"<<endl;
				cin>>x;
				if(x==0){
					list.Sort(0);
				}
				if(x==1){
					list.Sort(1);
				}
				cout<<"下面是排序的结果:"<<endl;
				cout<<list;
		}
			cout<<"按回车键继续添加,q退出学生成绩排序功能!!"<<endl;
			cin.get(ch1);
			cin.get(ch2);
	}	while(ch2=='\n');
		
		cout<<endl;
}

void Application::Print()
{
	char ch1,ch2;
	do{
			cout<<"您选择的是打印学生信息:"<<endl;
			if(list.IsEmpty()){
				cout<<"链表为空!请先添加学生信息!!"<<endl;
			}
			else{
                 cout<<list;
			}
	   cout<<"按回车键继续添加,q退出打印学生信息功能!!"<<endl;
	  cin.get(ch1);
	  cin.get(ch2);
	}while(ch2=='\n');
		cout<<endl;
}

void Application::Analyze()
{
	char ch1,ch2;
	int i;
	double sum=0;
	do{
		cout<<"您选择的是打印学生信息:"<<endl;
	    if(list.IsEmpty()){
	    cout<<"链表为空!请先添加学生信息!!"<<endl;
		}
	    else{
		   cout<<"您选择的是成绩分析器!"<<endl;
			for( i=0;i<list.Length();i++)
			{
				sum+=(list.DataOfNode(i)).Get_Score();
			}
			cout<<setw(20)<<"总人数  :"<<'\t'<<list.Length()<<endl;
			cout<<setw(20)<<"最高分  :"<<'\t'<<(list.Max()->data).Get_Score()<<endl;
			cout<<setw(20)<<"最低分  :"<<'\t'<<(list.Min()->data).Get_Score()<<endl;
			cout<<setw(20)<<"平均成绩:"<<'\t'<<sum/list.Length()<<endl;
			cout<<endl;
		}
	cout<<"按回车键继续添加,q退出学生成绩分析器!!"<<endl;
	  cin.get(ch1);
	  cin.get(ch2);
	}while(ch2=='\n');
}
void Application::Save()
{
	int i=0;
	ofstream fout;
	ifstream fin;
	cout<<"您选择的是保存链表!!"<<endl;
	if(list.IsEmpty()){
	   cout<<"链表为空!请先添加学生信息!!"<<endl;
	}
	else{
	fout.open("record.txt",ios::out);
	if(!fout)
	{
	  cout<<"Error:Can't open record.txt!";
	  exit(1);
	}
	while(fout&&i<list.Length())
	{

	fout<<list.DataOfNode(i)<<endl;
	i++;
	}
			

	fout.close();
	}
			
}

void Application::Load()
{
	int j=0;
	ofstream fout;
	ifstream fin;
	cout<<"您选择的是从文件输出链表!!"<<endl;
	fin.open("record.txt",ios::in);
	if(!fin)
	{
		cout<<"Error:Can't open record.txt!";
			exit(1);
	}
	while(fin&&j<list.Length())
	{
		fin>>list.DataOfNode(j);
		cout<<list.DataOfNode(j);
		j++;
	}
		
	fin.close();
}

⌨️ 快捷键说明

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