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

📄 main.cpp

📁 实现一个链表类
💻 CPP
字号:
#include<iostream>
#include<fstream>
using namespace std;
#include"ulist.h"

bool LoadScore(char * sScoreFile,CUList * pScoreList);//从文件中装载学生成绩

void main()
{
	CUList TestList_1;
	bool ret = LoadScore("stu_list.txt",&TestList_1);
	cout<<"TestList_1\n";
	TestList_1.print();

	cout<<endl;

	CUList TestList_2(TestList_1);//拷贝构造函数
	CUList TestList_3(TestList_2);
	CUList TestList_4(TestList_2);	

	TestList_1.Clear();
	TestList_2.Clear();

	TestList_4.Sort(1,true);
	cout<<"TestList_4--降序:    按学号\n";
	TestList_4.print();//输出检查

	cout<<endl;

	TestList_4.Sort(1,false);
	cout<<"TestList_4--升序:    按学号\n";
	TestList_4.print();//输出检查

	cout<<endl;

	TestList_4.Sort(4,true);
	cout<<"TestList_4--降序:    按第三门成绩\n";
	TestList_4.print();//输出检查

	cout<<endl;

	TestList_4.Sort(4,false);
	cout<<"TestList_4--升序:    按第三门成绩\n";
	TestList_4.print();//输出检查

	cout<<endl;

	TestList_4.Delete("200600054");

	//TestList_4.Delete("XXXXX");//最开始一个记录
	//TestList_4.Delete("YYYYYY");//最后一个记录

	TestList_4.print();//输出检查

	cout<<endl;

	int nCurrentCount = TestList_4.GetCount();
	STUDENT  aNewStudent= {"2006ABC0099","王小三",88.3f,56.6f,25.6f};
	TestList_4.Add(aNewStudent);
	if(strcmp( TestList_4.Find(aNewStudent).Name," ") < 0 )
		cout<<"错误1";

	if(TestList_4.GetCount() != nCurrentCount +1)
		cout<<"错误2";	

	CUList TestList_5 = TestList_4;//赋值运算符重载
	CUList TestList_6 = TestList_4;//赋值运算符重载
	TestList_4.Clear();

	cout<<"LIst_5:\n";
	TestList_5.print();
	cout<<endl;
	cout<<"LIst_6:\n";
	TestList_6.print();
	cout<<endl;

	if( !(TestList_6 == TestList_5) )
		cout<<"错误3";


	{
		CUList TestList_7 = TestList_6 +  TestList_5;
		TestList_7.Sort(2,false);
		cout<<"TestList_7--升序:    按第一门成绩\n";
		TestList_7.print();
		TestList_7.Clear();
	}
}

#define STUDENT_STRUCT_SCORECOUNT 3  //结构体中存储的成绩个数

//从指定的文件中装载学生数据
bool LoadScore(char * sScoreFile,CUList * pScoreList)//ScoreList  学生成绩链表
{
	//ScoreList;//学生成绩链表
	ifstream inFile(sScoreFile,ios::in);
	if(!inFile.is_open()) return false;	
	while(!inFile.eof())
	{
		STUDENT aStudent;
		aStudent.ScoreCount = STUDENT_STRUCT_SCORECOUNT;		
		{//读一个学生的数据
			inFile>>aStudent.NUMBER>>aStudent.Name;
			for(int i = 0;i<aStudent.ScoreCount;i++)
				inFile>>aStudent.Score[i];
		}
		pScoreList->Add(aStudent);

	}
	return false;
}



⌨️ 快捷键说明

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