text: #ifndef HEADER_STU_CPP
  #define HEADER_STU_CPP
  
  #include "studentDataBase.h"
  #include <string>
  #include <iostream>
  
  using namespace std;
  
  Student::Student()//初始化
  {
      id = "";
      charge = 0;
      orders = 0;
  }
  
  studentDataBase::studentDataBase(int x)//初始化，最大学生量为x
  {
      hashTable = new Student[x];
      maxStu = x;
  }
  
  studentDataBase::~studentDataBase() { delete[] hashTable; }//销毁
  
  int studentDataBase::hash(string str)//求字符串哈希值
  {
      clog << "hash:"<<str << endl;
      //使用BKDR Hash算法，因子选择13
      int hashStr = 0;
      for (auto c : str)
      {
          hashStr = hashStr * 13 + c;
      }
      hashStr = hashStr >= 0 ? hashStr : -hashStr;//绝对值
      return hashStr % maxStu;//求余数
  }
  
  Student *studentDataBase::findStu(string id)//寻找学生
  {
      clog << "findStu:"<<id << endl;
      int hashID = hash(id), index;
      if (hashTable[hashID].id == id)//先找哈希值对应桶
      {
          index = hashID;
      }
  
      else//否则启动线性试探
      {
          for (index = (hashID + 1) % maxStu; index != hashID; index = (index + 1) % maxStu)
          {
              if (hashTable[index].id == id)//找到则退出
                  break;
          }
          if (index == hashID)//线性试探失败返回空指针
              return nullptr;
      }
      return hashTable + index;
  }
  
  bool studentDataBase::newStu(string id,double charge,int orders)//新建学生
  {
      clog << "newStu:"<<id<<','<<charge<<','<<orders << endl;
      int hashID = hash(id), index;
      if (hashTable[hashID].id == "")//先找哈希值对应桶
      {
          index = hashID;
      }
  
      else//否则启动线性试探
      {
          for (index = (hashID + 1) % maxStu; index != hashID; index = (index + 1) % maxStu)
          {
              if (hashTable[index].id == "")//找到则退出
                  break;
          }
          if (index == hashID)//没有空桶，线性试探失败返回假
              return false;
      }
      hashTable[index].id = id;
      hashTable[index].charge=charge;
      hashTable[index].orders=orders;
      return true;//返回真
  }
  
  bool studentDataBase::deleteStu(string id)//删除某学生
  {
      clog << "deleteStu:"<<id<< endl;
      Student *cur = findStu(id);
      if (!cur)
      {
          return false;
      }
      cur->id = "";
      cur->orders = 0;
      cur->charge = 0;
      return true;
  }
  
  void studentDataBase::traverse(void (*visit)(Student &))//遍历
  {
      clog << "traverse"<< endl;
      for (int i = 0; i < maxStu; i++)
      {
          if (hashTable[i].id != "")//学生信息有效
          {
              visit(hashTable[i]);
          }
      }
  }
  
  #endif
  