📄 unit.cpp
字号:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include"unit.h"
struct danyuan
{
char name[30];
char phone[15];
char qq[10];
int sign;
}s1,s2;
long posend;
void basic::showlist(fstream f)
{
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
cout<<" 姓名"<<" , "<<"电话"<<endl;
do
{
f.read((char*)&s1,sizeof(danyuan));
if(s1.name==""||!strcmp(s1.name,"wwwwwwww"))continue;
else
cout<<s1.name<<" "<<s1.phone<<" "<<endl;
}
while(f.tellg()!=posend);
}
normal::normal()
{
sign=0;
};
void normal::lookup(fstream f)
{
int i=1;
cout<<"按 1.姓名 2.电话 3.QQ号"<<endl;
cin>>i;
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
switch (i)
{
case 1:
{
cout<<"请输入姓名:"<<endl;
cin>>name;
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.name,name)&&f.tellg()!=posend||!strcmp(s1.name,"wwwwwwww"));
if(!strcmp(s1.name,name))
{
cout<<"姓名:"<<s1.name<<" 电话:"<<s1.phone<<" QQ号:"<<s1.qq<<" 级别:";
showstatus(s1.sign);
cout<<endl;
}
else cout<<"查无此人."<<endl;
};break;
case 2:
{
cout<<"请输入电话:"<<endl;
cin>>phone;
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.phone,phone)&&f.tellg()!=posend);
if(!strcmp(s1.phone,phone))
{
cout<<"姓名:"<<s1.name<<" 电话:"<<s1.phone<<" QQ号:"<<s1.qq<<" 级别:";
showstatus(s1.sign);
cout<<endl;
}
else cout<<"查无此人."<<endl;
};break;
case 3:
{
cout<<"请输入QQ号:"<<endl;
cin>>qq;
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.qq,qq)&&f.tellg()!=posend);
if(!strcmp(s1.qq,qq))
{
cout<<"姓名:"<<s1.name<<" 电话:"<<s1.phone<<" QQ号:"<<s1.qq<<" 级别:";
showstatus(s1.sign);
cout<<endl;
}
else cout<<"查无此人."<<endl;
};break;
}
}
void normal::add(fstream f)
{
f.seekp(0,ios::end);
cout<<"请输入 姓名,电话,QQ号(默认级别为normal):"<<endl;
cin>>s1.name>>s1.phone>>s1.qq;
s1.sign=0;
f.write((char*)&s1,sizeof(danyuan));
}
void normal::plus(fstream f)
{
cout<<"请输入姓名:"<<endl;
cin>>name;
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
f.seekp(0,ios::beg);
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.name,name)&&f.tellg()!=posend);
if(!strcmp(s1.name,name))
{
f.seekg(-long(sizeof(danyuan)),ios::cur);
long pos=f.tellg();
s2=s1;
strcpy(s2.name ,"wwwwwwww");
strcpy(s2.phone,"wwwwwwww");
strcpy(s2.qq,"wwwwwwww");
s2.sign=2;
f.seekp(pos,ios::beg);
f.write((char*)&s2,sizeof(danyuan));
}
else cout<<"查无此人"<<endl;
}
void normal::chenge(fstream f)
{
cout<<"请输入姓名:"<<endl;
cin>>name;
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
f.seekp(0,ios::beg);
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.name,name)&&f.tellg()!=posend);
if(!strcmp(s1.name,name))
{
int i;
f.seekg(-long(sizeof(danyuan)),ios::cur);
long pos=f.tellg();
s2=s1;
cout<<"请输入要修改的元素(1.姓名,2.电话,3.QQ号):";
cin>>i;
while(i>3||i<1){cout<<"输入错误,请重新输入:"<<endl;cin>>i;}
cout<<"请输入改后的相关内容:";
{switch(i)
{
case 1:cin>>s2.name;break;
case 2:cin>>s2.phone;break;
case 3:cin>>s2.qq;break;
default:break;
}
f.seekp(pos,ios::beg);
f.write((char*)&s2,sizeof(danyuan));
}
}
else cout<<"查无此人."<<endl;
}
void normal::showstatus(int i)
{
if(i==0)cout<<"normal"<<endl;
else cout<<"friend"<<endl;
}
void normal::shownorlist(fstream f)
{
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
cout<<"姓名"<<" "<<"电话"<<endl;
do
{
f.read((char*)&s1,sizeof(danyuan));
if(s1.name==""||!strcmp(s1.name,"wwwwwwww")||s1.sign==1)continue;
else cout<<s1.name<<" "<<s1.phone<<" "<<endl;
}
while(f.tellg()!=posend);
}
void normal::chengetofri(fstream f)
{
cout<<"请输入姓名:"<<endl;
cin>>name;
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
f.seekp(0,ios::beg);
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.name,name)&&f.tellg()!=posend);
if(!strcmp(s1.name,name))
{
f.seekg(-long(sizeof(danyuan)),ios::cur);
long pos=f.tellg();
s2=s1;
s2.sign=1;
f.seekp(pos,ios::beg);
f.write((char*)&s2,sizeof(danyuan));
}
else cout<<"查无此人."<<endl;
}
fri::fri()
{
sign=1;
};
void fri::showfrilist(fstream f)
{
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
cout<<"姓名"<<" "<<"电话"<<endl;
do
{
f.read((char*)&s1,sizeof(danyuan));
if(s1.name==""||!strcmp(s1.name,"wwwwwwww")||s1.sign==0)continue;
else cout<<s1.name<<" "<<s1.phone<<" "<<endl;
}
while(f.tellg()!=posend);
}
void fri::chengetonor(fstream f)
{
f.seekg(-long(sizeof(danyuan)),ios::cur);
cout<<"请输入姓名:"<<endl;
cin>>name;
f.seekg(0,ios::end);
posend=f.tellg();
f.seekg(0,ios::beg);
f.seekp(0,ios::beg);
do
{
f.read((char*)&s1,sizeof(danyuan));
}while(strcmp(s1.name,name)&&f.tellg()!=posend);
if(!strcmp(s1.name,name))
{
long pos=f.tellg();
s2=s1;
s2.sign=0;
f.seekp(pos,ios::beg);
f.write((char*)&s2,sizeof(danyuan));
}
else cout<<"查无此人."<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -