# include & ltiostream & gt
# include & ltfstream & gt
使用命名空間std
結構學生
{
字符名稱[10];
int Age
迷人的性愛;
char聯系電話[13];
};
結構學生ST[100];
int Num = 0;
fstream ftxl
int fNum = 0;
void InStu()
{
int n,I,be;
be = Num
cout & lt& lt" n = ";
CIN & gt;& gtn;
for(I = be;我& ltbe+n;i++)
{
cout & lt& lt"請輸入第壹個"
cout & lt& lt”名稱:“;
CIN & gt;& gt聖[我]。姓名;
cout & lt& lt"年齡:";
CIN & gt;& gt聖[我]。年齡;
cout & lt& lt“性別”:
CIN & gt;& gt聖[我]。性;
cout & lt& lt“手機”:
CIN & gt;& gt聖[我]。電話;
num++;
}
}
void OutStu()
{
cout & lt& lt“以下是通訊簿中的所有學生信息”
cout & lt& lt"名稱"
for(int I = 0;我& ltNumi++)
cout & lt& lt聖[我]。名稱& lt& lt" \ t " & lt& lt聖[我]。年齡& lt& lt" \ t " & lt& lt聖[我]。性& lt& lt" \ t " & lt& lt聖[我]。電話& lt& ltendl
}
void SelStu()//
{
char tmpName[20];
cout & lt& lt請輸入要查詢的名稱:“;
CIN & gt;& gttmpName
for(int I = 0;我& ltNumi++)
if(strcmp(st[i].Name,tmpName)==0)
{
cout & lt& lt聖[我]。名稱& lt& lt" \ t " & lt& lt聖[我]。年齡& lt& lt" \ t " & lt& lt聖[我]。性& lt& lt" \ t " & lt& lt聖[我]。電話& lt& ltendl
打破;
}
if(i==Num)
cout & lt& lt“沒有要查詢的學生!”& lt& ltendl
}
void AppStu()
{
int n,I;
cout & lt& lt" n = ";
CIN & gt;& gtn;
int end = Num+n;
for(I = Num;我& lt結束;i++)
{
cout & lt& lt"請輸入第壹個"
cout & lt& lt”名稱:“;
CIN & gt;& gt聖[我]。姓名;
cout & lt& lt"年齡:";
CIN & gt;& gt聖[我]。年齡;
cout & lt& lt“性別”:
CIN & gt;& gt聖[我]。性;
cout & lt& lt“手機”:
CIN & gt;& gt聖[我]。電話;
num++;
}
}
void DelStu()
{
char tmpName[20];
int索引;
cout & lt& lt請輸入要查詢的名稱:“;
CIN & gt;& gttmpName
for(int I = 0;我& ltNumi++)
if(strcmp(st[i].Name,tmpName)==0)
{
index = I;
打破;
}
if(i==Num)
cout & lt& lt“沒有要刪除的學生!”& lt& ltendl
其他
{
for(I =索引;我& ltnum-1;i++)
ST[I]= ST[I+1];
cout & lt& lt“刪除成功!”& lt& ltendl
Num = Num-1;
}
}
void finput()
{
int I = 0;
ftxl.open("d:\\txl.txt ",IOs::in);
if(ftxl.fail())
{
cout & lt& lt"無法打開輸入文件!"& lt& ltendl
退出(0);
}
而(!ftxl.eof())
{
ftxl & gt& gt聖[我]。姓名;
ftxl & gt& gt聖[我]。年齡;
ftxl & gt& gt聖[我]。性;
ftxl & gt& gt聖[我]。電話;
fnum++;
i++;
}
num = fNum-1;
ftxl . close();
ftxl . clear();
}
無效菜單()
{
cout & lt& ltendl & lt& ltendl
cout & lt& lt“* * * * * * * * * *歡迎使用通訊錄管理系統* * * * * * * * < & lt;endl
cout & lt& lt" \ t \ t \ tEnter student-1 " < & lt;endl
cout & lt& lt" \ t \ t \輸出學生-2 "
cout & lt& lt" \ t \ t \查詢學生-3 "
cout & lt& lt" \ t \ t \附加記錄-4 "
cout & lt& lt"刪除記錄-5 "
cout & lt& lt" \ t \ t \退出系統-0 "
cout & lt& ltendl
}
無效輸出()
{
ftxl.open("d:\\txl.txt ",IOs::out);
if(ftxl.fail())
cout & lt& lt"無法打開輸出文件!"& lt& ltendl
for(int I = 0;我& ltNumi++)
{
ftxl & lt& lt聖[我]。名稱& lt& lt" \ t " & lt& lt聖[我]。年齡& lt& lt" \ t " & lt& lt聖[我]。性& lt& lt" \ t " & lt& lt聖[我]。電話& lt& ltendl
cout & lt& lt聖[我]。名稱& lt& lt" \ t " & lt& lt聖[我]。年齡& lt& lt" \ t " & lt& lt聖[我]。性& lt& lt" \ t " & lt& lt聖[我]。電話& lt& ltendl
}
ftxl . close();
}
void main()
{
int sel
finput();
while(1)
{
menu();
cout & lt& lt"請輸入壹個選項:";
CIN & gt;& gtsel
開關(選擇)
{
案例1:InStu();打破;
案例二:out stu();打破;
案例三:sel stu();打破;
案例四:app stu();打破;
案例五:德爾斯圖();打破;
案例0:fout put();
退出(1);
}
}
}