AddrList.h
#include <iostream>
#include <iomanip>
#include <fstream>
#include <process.h>
#include <string.h>
using namespace std;
const int LIST_INIT_SIZE=10;
const int LISTINCREMENT=5;
//student,
typedef struct Contacts
{
char id[10]; //学号
char name[10]; //姓名
char sex[10]; //性别
char class_number[10]; //班级
char class_name[30]; //科目
char score[30]; //成绩
}Student;
//scorebook表
typedef struct scorebook
{
Student *elem;
int length;
int listsize;
int incrementsize;
}scorebook;
//错误运行
void ErrorMessage(char *s)
{
cout<<s<<endl;
exit(1); //非正常运行导致退出程序
}
//getchar()吸收换行来模拟暂停
void Pause()
{
cout<<endl<<"按任意键继续......";
getchar();getchar();
}
//初始化 length=0,获取 maxsize, incresize,new 长度为maxsize的student数组
void InitList_Sq(scorebook &L, int maxsize=LIST_INIT_SIZE, int incresize=LISTINCREMENT)
{
L.elem=new Student [maxsize];
L.length=0;
L.listsize=maxsize;
L.incrementsize=incresize;
}
//查找元素(按id学号查询)
int LocateElem_Sq(scorebook &L, Student e)
{
for(int i=0;i<L.length;i++)
if(strcmp(L.elem[i].id,e.id)==0) return i+1;
return 0;
}
//获取元素
void GetElem_Sq(scorebook &L, int i, Student &e)
{
e=L.elem[i-1];
}
//增加存储空间和长度
void increment(scorebook &L)
{
Student *p=new Student[L.listsize+L.incrementsize];
for(int i=0;i<L.length;i++)
p[i]=L.elem[i];
delete [] L.elem;
L.elem=p;
L.listsize=L.listsize+L.incrementsize;
}
//增加元素
void ListInsert_Sq(scorebook &L, Student e)
{
if(L.length>=L.listsize)
increment(L);
if(L.length ==0)
{
L.elem[0]=e;
L.length++;
}
else
{
int i=L.length-1;