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

📄 file.cpp

📁 学校的教学管理系统
💻 CPP
字号:
#include"head.h"
#include<fstream.h>
#include<stdlib.h>

extern void SortEachClass(Student* &);

ostream& operator <<(ostream& oo,Student& d)
{
	oo<<d.Name<<" "<<d.Class<<" "<<d.Number<<" "<<d.Sex<<" "<<d.Age<<" "<<d.Room<<" "
	  <<d.Tel<<" "<<d.Score[0]<<" "<<d.Score[1]<<" "<<d.Score[2]<<" "<<d.Score[3]<<" "
	  <<d.Score[4]<<" "<<d.Average<<endl;
	return oo;
}

istream& operator >>(istream& oo,Student& d)
{
	oo>>d.Name>>d.Class>>d.Number>>d.Sex>>d.Age>>d.Room>>d.Tel>>d.Score[0]>>d.Score[1]
	  >>d.Score[2]>>d.Score[3]>>d.Score[4]>>d.Average;
	return oo;
}

void Save(Student* &head)
{
	Student* pGuard;
	
	fstream outfile("c:\\wmzlq.txt",ios::out|ios::trunc);
	
	if(outfile.fail())
	{
		cerr<<"打开文件wmzlq时出错,程序运行结束! 请与作者联系."<<endl;
		exit(1);
	}

	SortEachClass(head);       //保存时先排序,以便下次运行程序

	for(pGuard=head;pGuard!=NULL;pGuard=pGuard->next)
	{
		outfile<<*pGuard;
	}

	cout<<"所有学生的信息已成功的保存在c:\\wmzlq.txt中!"<<endl;
}

void Getout(Student* &head)
{
	fstream infile("c:\\wmzlq.txt",ios::in);

	if(infile.fail())
	{
		cout<<"打开文件wmzlq时出错,程序运行结束! 请与作者联系."<<endl;
		exit(1);
	}

	Student* pGuard;
	Student* pS;
	pS=new Student;
	pGuard=pS;

	while(infile>>*pS)
	{
		if(head==NULL)
			head=pS;
		else
		{
			pGuard->next=pS;
		}

		pGuard=pS;
		pS=new Student;
	}
	delete pS;
	pGuard->next=NULL;
}

⌨️ 快捷键说明

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