#include<fstream>
#include<cstring>
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -1
#define List_INIT_SPACE 100 //存储空间初始分配量
#define List_INC_SPACE 10 //存储空间分配增量
int node = 1;
typedef struct Student
{
int age; //年龄
int student_id; //学号
int course_id; //题目编号
char student_name[40]; //姓名
char sex[10]; //性别
char Class[40]; //班级
char specialty[40]; //专业
char course_name[40]; //题目名称
char keyword[40]; //关键词
char technology[40];
}Student;
typedef struct STent_list
{
struct Student *stu; //存储空间基址
int length; //当前长度
int listsize; //当前分配的存储容量(以sizeof(Student)为单位
}STent_list;
int STent_listInit(STent_list &S)
{
//在内存中分配空间
S.stu = (Student*)malloc(List_INC_SPACE*sizeof(Student));
if(!S.stu) exit(OVERFLOW); //存储空间分配失败
//构造一个空的线性表
S.length = 0;
S.listsize = List_INC_SPACE; //初始存储容量
return OK;
}//函数STent_listInit结束
void write(STent_list &S, int n)
{
fstream myfile;
myfile.open("student.txt",ios::out|ios::binary);
//fstream myfile("student.txt",ios::out|ios::binary);
if(! myfile)
{
cout<<"该文件不能打开!"<<endl;
abort(); //异常终止函数
}
int count = n;
myfile<<count<<endl<<endl;
for(int i = 0; i <= count; i++)
{
myfile<<(S.stu[i]).student_id<<" "<<(S.stu[i]).student_name<<" "<<(S.stu[i]).sex<<" "<<(S.stu[i]).age<<" "<<(S.stu[i]).Class<<" "<<(S.stu[i]).specialty<<" "<<S.stu[i].course_id<<" "<<S.stu[i].course_name<<" "<<S.stu[i].keyword<<" "<<S.stu[i].technology<<" "<<endl;
}
myfile.close();
}
/**************************************/
//函数名: read(STent_list &S)
//参数: (传入) STent_list S顺序表
//返回值: int型,返回1表示创建成功,0表示失败
//功能: 读取顺序表中的内容
/*************************************/
int read(STent_list &S)
{
fstream myfile;
myfile.open("student.txt",ios::in|ios::binary);
//fstream myfile("student.txt",ios::out|ios::binary);
if(! myfile)
{
cout<<"该文件不能打开"<<endl;
abort();
}
int count;
myfile.seekg(0);
myfile>>count;
for(int i = 0; i <= count; i++)
{
myfile>>S.stu[i].student_id>>S.stu[i].student_name>>S.stu[i].sex>>S.stu[i].age>>S.stu[i].Class>>S.stu[i].specialty>>S.stu[i].course_id>>S.stu[i].course_name>>S.stu[i].keyword>>S.stu[i].technology;
}
myfile.close();
return count;
}
/*****************************************/
//函数名:add(STent_list &S)
//参数: (传入)STent_list S,顺序表
//返回值: 空
//功能: 添加学生信息
/*****************************************/
void add(STent_list &S)
{
int n = read(S);
int i = 0;
char sign = 'F';
cout<<endl<<"请输入增加的学生的相关信息:"<<endl;
while(sign != 'N')
{
loop:
cout<<"学号:";
cin>>S.stu[i].student_id;
cout<<endl;
int c = 0;
while(c < i)
{
c++;
if(S.stu[i].student_id == S.stu[i-c].student_id)
{
cout<<"你输入的学号已经存在!请重新输入" <<endl;
goto loop;
}
}
cout<<"姓名:";
cin>>S.stu[i].student_name;
cout<<endl;
cout<<"性别:";
cin>>S.stu[i].sex;
cout<<endl;
cout<<&#
课程设计选题管理系统
最新推荐文章于 2024-06-14 20:47:52 发布