資源簡介
支持學生信息的錄入,刪除,修改,按姓氏模糊查找,姓名/學號查詢,按時間查詢,并且將信息寫入到本地文件
代碼片段和文件信息
#include
#include
#include
#define?met(a)?memset(a0sizeof(a))
#define?fup(ianb)?for(int?i=a;i #define?fow(janb)?for(int?j=a;j>0;j-=b)
#define?MOD(x)?(x)%mod
using?namespace?std;
const?int?maxn?=?2*1e4;
const?int?mod=1e9+7;?
int?Node_len=1;
int?D?=?0;
struct?Node?{
char?Name[25];
char?Snum[25];
char?Location[40];
char?Time[30];
int?flag;
}Student[maxn];
void?Init();
void?Add();
void?Del();
void?Pref();
void?Query_Fname();
void?Query_Snum();
void?Query_Time();
void?Close();
void?Sign();
int?main(int?argc?const?char?*?argv[])?{
Init();
Sign();
int?Chose;
while?(cout<<“選擇操作:“&&cin?>>?Chose)?{
if?(Chose?==?0)break;
else?if?(Chose?==?1)Add();
else?if?(Chose?==?2)Del();
else?if?(Chose?==?3)Pref();
else?if?(Chose?==?4)Query_Fname();
else?if?(Chose?==?5)Query_Snum();
else?if?(Chose?==?6)Query_Time();
else?cout?<“無效操作“?< }
Close();
return?0;
}
?void?fileEmpty(const?char?fileName[])
{
fstream?file(fileName?ios::out);
return;
}
?void?Init()?{
?FILE*?fp;
?int?k=1;
?fp?=?fopen(“E:/Len.dll“?“a+“);
?Node_len?=?getw(fp);
?if?(Node_len?<=?0)Node_len?=?1;
?fclose(fp);
?fp?=?fopen(“E:/Student.dll“?“a+“);
?for?(int?i?=?1;?i?
?}
?void?Close()?{
?fileEmpty(“E:/Len.dll“);
?fileEmpty(“E:/Student.dll“);
?FILE*?fp;
?fp=?fopen(“E:/Len.dll“?“a+“);
?putw(Node_len?fp);
?fclose(fp);
?fp?=?fopen(“E:/Student.dll“?“a+“);
?for?(int?i?=?1;?i? ?if?(Student[i].flag)continue;
?else?fwrite(&Student[i]?sizeof(Node)?1?fp);
?fclose(fp);
?}
void?Add()?{
cout?<“請以此輸入學生姓名,學號,簽到地點,簽到時間“?< scanf(“%s“?Student[Node_len].Name);
scanf(“%s“?Student[Node_len].Snum);
scanf(“%s“?Student[Node_len].Location);
scanf(“%s“?Student[Node_len++].Time);
}
void?Del()?{
int?ai;
cout?<“請輸入要刪除信息序號:“;
cin?>>?a;
if?(a?>=?Node_len)cout?<“錯誤操作,第a條信息不存在“< for?(i?=?1;?i? if?(Student[i].flag?==1)continue;
if?(a?==?1)break;
a--;
}
Student[i].flag?=?1;
}
void?Pref()?{
int?a?i;
cout?<“請輸入要修改信息序號:“;
cin?>>?a;
if?(a?>=?Node_len)cout?<“錯誤操作,第a條信息不存在“?< for?(i?=?1;?i? if?(Student[i].flag?==1)continue;
if?(a?==?1)break;
a--;
}
int?ch;
cout?<“請選擇要修改的信息:1-姓名,2-學號,3-簽到地點,4-簽到時間\t:“;
cin?>>?ch;
if?(ch?==?1)cin?>>?Student[i].Name;
else?if?(ch?==?2)cin?>>?Student[i].Snum;
else?if?(ch?==?3)cin?>>?Student[i].Location;
else?if?(ch?==?4)cin?>>?Student[i].Time;
else?cout?
- 上一篇:計算機圖形學 幀動畫
- 下一篇:C++定義一個MyString類,實現兩個字符串相加
評論
共有 條評論