学生管理系统(完整版)

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <vld.h>
#include <string.h>

#define INIT_SIZE 100
#define SIZE 3

typedef struct Student
{
	char id[15];    //15
	char name[20];  //15+20
	char sex[10]; //35+10
	int age;       //45+3  +4
	double score[SIZE];  //52+4  +8*3
	double sum;        //80 +8
	double avg;        //88+8    
}Student, *PStudent;   //96  

typedef struct Student_Head
{
	struct Student* arr;//用来保存malloc返回的堆内内存块地址
	int length;//当前空间已使用个数
	int list_size;//当前空间总大小
}Student_Head, *PStudent_Head;
void Init_Student_Head(struct Student_Head *p)//初始化模块
{
	assert(p != NULL);
	if(p == NULL)
	{
		printf("指针为NULL\n");
		return;
	}
	p->arr = (struct Student*)malloc(INIT_SIZE * sizeof(struct Student));
	assert(p->arr != NULL);

	p->length = 0;
	p->list_size = INIT_SIZE;

}
static bool IsFull(PStudent_Head p)//判满操作
{
	return p->length == p->list_size;
}
static void Inc(PStudent_Head p)//扩容操作
{
	//*2 
	p->arr = (struct Student*)realloc(p->arr, p->list_size*sizeof(struct Student)*2);
	assert(p->arr != NULL);

	//p->length;//当前容量没有变化,只是将总空间变大两倍
	p->list_size *= 2;

}

bool Add_Student(PStudent_Head p)//添加学生信息
{
	assert(p != NULL);
	if(p == NULL)
	{
		printf("指针为NULL\n");
		return false;
	}

	if(IsFull(p))//判满
	{
		Inc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值