📄 student_structure.h
字号:
#include <string.h>
#include <fstream.h>
#pragma once
struct student_structure
{
char name[10];
char number[10];
char sex[2];
char birthday[8];
char zzmm[4];
char jtzz[20];
};
const int MAXSIZE=100;
class sheet
{
student_structure sheet_information[MAXSIZE];
int length;
public:
sheet()
{
fstream file;
file.open("information.dat",ios::in);
if(!file)
return;
file.read((char*)&sheet_information[0],sizeof(student_structure));
length=0;
while(!file.eof())
{
length++;
file.read((char*)&sheet_information[length],sizeof(student_structure));
}
file.close();
}
~sheet()
{
fstream file;
file.open("information.dat",ios::out);
for(int i=0;i<length;i++)
{
file.write((char*)&sheet_information[i],sizeof(student_structure));
}
file.close();
}
void insert(student_structure information)
{
strcpy(sheet_information[length].name,information.name);
strcpy(sheet_information[length].number,information.number);
strcpy(sheet_information[length].sex,information.sex);
strcpy(sheet_information[length].zzmm,information.zzmm);
strcpy(sheet_information[length].jtzz,information.jtzz);
length++;
return;
}
void delete_by_name(char* number)
{
int i;
i=query(number);
if (i!=-1)
{
for(int j=i+1;j<length;j++)
sheet_information[j-1]=sheet_information[j];
}
return;
}
int query(char* number)
{
for (int i=0;i<length;i++)
{
if(!strcmp(number,sheet_information[i].number))
return i;
}
return -1;
}
void display()
{
for(int i=0;i<length;i++)
{
cout <<sheet_information[i].name<<" "<<sheet_information[i].number<<" "<<sheet_information[i].sex<<" "<<sheet_information[i].birthday<<" "<<sheet_information[i].zzmm<<" "<<sheet_information[i].jtzz<<endl;
}
return;
}
void modify(char *number)
{
int i;
i=query(number);
if (i==-1 )
throw "查找失败!!!";
cout<<"input the new information"<<endl;
cout<<"birthday:";
cin >>sheet_information[i].birthday;
cout<<"政治面貌:";
cin>>sheet_information[i].zzmm;
cout<<"家庭住址:";
cin>>sheet_information[i].jtzz;
return;
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -