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

📄 studenttable.cpp

📁 用面向连接的TCP实现学生信息的管理
💻 CPP
字号:
// StudentTable.cpp: implementation of the StudentTable class.
//
//////////////////////////////////////////////////////////////////////

#include "StudentTable.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
RecordList recList;

StudentTable::StudentTable()
{
}

void StudentTable::addRecord(Record *rec)
{
	recList.push_back(rec);
}

void StudentTable::removeRecord(RecordList::iterator it)
{ recList.erase(it);}

void StudentTable::saveRecords(ostream& os)
{os<<recList<<endl;}

StudentTable::~StudentTable()
{

}
void StudentTable::loadFile()
{
	ifstream fin("student.txt");
	int count=loadRecords(fin);
	cout<<"file has been succefully loaded!" <<endl;
	cout<<"and there are  "<<count<<" piece of message"<<endl;
	fin.close();
}


StudentTable::loadRecords(istream& in)//从文件中读取并在内存中组织为链表
{
	
	int count=0;
	char str[100];
	
	while(in.getline(str,100))
	{
	 char *token;
	 char *stud[3];
	 char seps[]= " ,\t\n";
	
	 token = strtok( str, seps );
	 
	 for(int i=0;i<3 && token != NULL;i++)
	 {
		 stud[i]=token;
		 token= strtok( NULL, seps );
	 }
	 Record *record =new Record;
	 
	 string no(stud[0]);
	 string name(stud[1]);
	 int score=atoi(stud[2]);
	 record->no=no;
	 record->name=name;
	 record->score=score;
	 recList.push_back(record);
	 count++;
	}
	
	return count;
}


void StudentTable::displayRecord()
{
	if(recList.empty())
		cout<<"It's a empty record"<<endl;
	else
	{
	 Iterator it;
	 cout<<endl<<"Now the Students is: "<<endl;
	 for(it=recList.begin();it!=recList.end();it++)
		cout<<setiosflags(ios::left)
	        <<setw(10)
		    <<(*it)->name
	        <<setw(10)
		    <<(*it)->no
			<<setw(4)
			<<(*it)->score<<endl;
     }
}

string StudentTable::queryRecord(string sno)
{
	Iterator it;
	string result;
	char buff[4];
	for(it=recList.begin();it!=recList.end();it++)
		if((*it)->no==sno) 
		{
			_itoa((*it)->score,buff,10);
			string score(buff);
			result=(*it)->no+" "+(*it)->name+" "+score;
		}
	return result;	
}



⌨️ 快捷键说明

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