学生成绩管理系统(数据结构之线性表实现)

这里写图片描述

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;
        
  • 24
    点赞
  • 200
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值