?? clist.cpp
字號:
#include "Clist.h"
#include<iostream>
#include <fstream>
using namespace std;
//#include"ulist.h"//包含類的頭文件
/**
請增加CUList的一個成員函數,voi print(); 將鏈表輸出
*/
bool LoadScore(char * sScoreFile,CUList * pScoreList);//從文件中裝載學生成績
void main()
{
CUList TestList_1;
bool ret = LoadScore("C:\\stu_list.txt",&TestList_1);
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);
TestList_4.print();//輸出檢查
TestList_4.Sort(1,false);
TestList_4.print();//輸出檢查
TestList_4.Sort(4,true);
TestList_4.print();//輸出檢查
TestList_4.Sort(4,false);
TestList_4.print();//輸出檢查
TestList_4.Delete("200600888");
TestList_4.Delete("200600056");//最開始一個記錄
//TestList_4.Delete("YYYYYY");//最后一個記錄
TestList_4.print();//輸出檢查
int nCurrentCount = TestList_4.GetCount();
STUDENT aNewStudent= {"2006ABC0099","王小三",88.3f,56.6f,25.6f,3};
TestList_4.Add(aNewStudent);
if(strcmp( TestList_4.Find(aNewStudent).Name," ") <0 )
cout<<"錯誤1";
if(TestList_4.GetCount() != nCurrentCount +1)
cout<<"錯誤2";
TestList_4.print();//檢查是否添加了aNewStudent
CUList TestList_5 = TestList_4;//賦值運算符重載
CUList TestList_6 = TestList_4;//賦值運算符重載
TestList_4.Clear();
TestList_5.print();//檢查TestList_5 是否= TestList_4
if( !(TestList_6 == TestList_5) )
cout<<"錯誤3";
{
CUList TestList_7 = TestList_6 + TestList_5;
TestList_7.Sort(3,true);//按學號升序排列
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 + -