c++猜名人读心术代码
#include
#include
#include
#include
using namespace std; class stu_info
{
public:
void search_info()
{
char buffer[256];
ifstream Q("que.txt");
if(!Q.is_open())
{
cout << "Error opening file";
exit(1);
}
while(!Q.eof())
{
Q.getline(buffer,100);
cout << buffer << endl;
}
}
};
int main ()
{
char username[10]; //用户名
char password[10]; //密码
string fam_id;
string que_id;
int a;
while (true)
{ cout<<"\n------------------";
cout<<"\n欢迎进入读心术游戏";
cout<<"\n------------------";
cout<<"\n用户类别:"<<"1.管理员"<<"2.玩家";
cout<<"\n--------------------------------------";
cout<<"\n请选择:";
cin>>a;
if(a==1)
{
cout << "\n请输入用户名:";
cin >> username;
cout << "\n请输入密码:";
cin >> password;
if (strcmp(username,"admin") == 0) //管理员
{
if (strcmp(password,"123") == 0)
{
cout<<"\n登陆成功";
start:
int chose;
cout<<"\n1.增加名人信息"
<<"\n2.删除名人信息"
<<"\n3.修改名人信息"
<<"\n4.增加询问问题"
<<"\n5.删除询问问题"
<<"\n6.修改询问问题"
<<"\n7.返回登录界面"
<<"\n请输入您需要的操作的序号,回车结束:";
cin>>chose;
char buffer[256];
ifstream F("fam.txt"); //读取fam.txt中的名人信息,保存在向量temp_fam
中
if(!F.is_open())
{
cout << "Error opening file";
exit(1);
}
vector temp_fam;
while(!F.eof())
{
F.getline(buffer,100);
temp_fam.push_back(buffer);
}
F.close();
ifstream Q("que.txt"); //读取que.txt中的询问问题,保存在向量temp_que
中
if(!F.is_open())
if(!Q.is_open())
{
cout << "Error opening file";
exit(1);
}
vector temp_que;
while(!Q.eof())
{
Q.getline(buffer,100);
temp_que.push_back(buffer);
}
Q.close();
if (chose==1) //增加名人信息
{
ofstream outfile;
outfile.open("fam.txt",ios::app);
if(!outfile)
{
cout << "Error opening file";
exit(1);
}
int i;
int n;
cout<<"输入你想增加的名人信息数量:";
cin>>n;
cout<<"输入增加的名人信息:\n";
for (i=1;i<=n;i++)
{
cout<> fam_id;
bool exist = false;
for(int i = 0; i < temp_fam.size();i++)
{
if(fam_id == temp_fam[i]) //增加的信息存在,则不做
任何处理
{
cout << "\n您输入的信息已经存在\n";
exist = true;
goto start;
}
}
if(!exist)
{
outfile<> fam_id;
for(int i = 0; i < temp_fam.size();i++)
{
if(fam_id == temp_fam[i]) //输入的信息存在,记录状
态和信息的位置
{
cout << temp_fam.size() << endl;
is_exist = true;
id_position = i;
break;
}
}
if(is_exist) //输入的信息存在,删除
{
temp_fam.erase(temp_fam.begin()+id_position);
cout << temp_fam.size() << endl;
cout<<"\n删除成功";
goto start;
}
else //输入的信息不存在,不做处理
cout << "\n您输入的信息不存在";
goto start;
}
if (chose==3) //修改名人信息
{
bool is_exist = false;
int id_position = 0;
cout << "请输入需要修改的信息:";
cin >> fam_id;
for(int i = 0; i < temp_fam.size();i++)
{
if(fam_id == temp_fam[i]) //输入的信息存在,记录状态和信息的位置
{
is_exist = true;
id_position = i;
break;
}
}
if(is_exist) //输入的信息存在,删除,并将名人信息写入到fam.txt中
{
temp_fam.erase(temp_fam.begin()+id_position);
ofstream F_write("fam.txt");
for( int i = 0; i < temp_fam.size(); i++)
{
F_write << temp_fam[i] << "\n";
}
F_write.close();
ofstream outfile;
outfile.open("fam.txt",ios::app);
if(!outfile)
{
cout << "Error opening file";
exit(1);
}
int j;
cout<<"输入修改后的名人信息:\n";
for (j=1;j<=1;j++)
{
cout<> fam_id;
bool exist = false;
for(int i = 0; i < temp_fam.size();i++)
{
if(fam_id == temp_fam[i]) //修改后的信息存在,则不做任何处理
{
cout << "\n您输入的信息已经存在\n";
exist = true;
break;
}
}
if(!exist)
{
outfile<>n;
cout<<"输入增加的询问问题:\n";
for (i=1;i<=n;i++)
{
cout<> que_id;
bool exist = false;
for(int i = 0; i < temp_que.size();i++)
{
if(que_id == temp_que[i]) //插入的问题存在,则不做
任何处理
{
cout << "\n您输入的信息已经存在\n";
exist = true;
break;
goto start;
}
}
if(!exist)
{
outfile<> que_id;
for(int i = 0; i < temp_que.size();i++)
{
if(que_id == temp_que[i]) //输入的问题存在,记录状态和问题的位置
{
cout << temp_que.size() << endl;
is_exist = true;
id_position = i;
}
}
if(is_exist) //输入的问题存在,删除
{
temp_que.erase(temp_que.begin()+id_position);
cout << temp_que.size() << endl;
cout<<"\n删除成功";
goto start;
}
else //输入的问题不存在,不做处理
cout << "\n您输入的问题不存在";
goto start;
}
if (chose==6) //修改询问问题
{bool is_exist = false;
int id_position = 0;
cout << "请输入需要修改的问题:";
cin >> que_id;
for(int i = 0; i < temp_que.size();i++)
{
if(que_id == temp_que[i]) //输入的问题存在,记录状
态和问题的位置
{
is_exist = true;
id_position = i;
break;
}
}
if(is_exist) //输入的问题存在,删除,并将询问问题写入到que.txt中
{
temp_que.erase(temp_que.begin()+id_position);
ofstream Q_write("que.txt");
for( int i = 0; i < temp_que.size(); i++)
{
Q_write << temp_que[i] << "\n";
}
Q_write.close();
ofstream outfile;
outfile.open("que.txt",ios::app);
if(!outfile)
{
cout << "Error opening file";
exit(1);
}
int j;
cout<<"输入修改后的询问问题:\n";
for (j=1;j<=1;j++)
{
cout<> que_id;
bool exist = false;
for(int i = 0; i < temp_que.size();i++)
{
if(que_id == temp_que[i]) //修改后的问题存在,则不做任何处理
{
cout << "\n您输入的问题已经存在\n";
exist = true;
break;
}
}
if(!exist)
{
outfile<temp_fam;
while(!F.eof())
{
F.getline(buffer,100);
temp_fam.push_back(buffer);
}
F.close();
stu_info Q;
Q.search_info();
cin>>que_id;
for(int i = 0; i < temp_fam.size();i++)
{
if(que_id == temp_fam[i])
cout <
本文档为【c++猜名人读心术代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。