void message::alter()
{
ifstream inData("pmessage.txt", ios::in);
if (!inData)
{
cout <<endl <<"对不起不能打开文件!!!!!" <<endl <<endl;
system("pause");
return;
}
string sign;
cout <<endl <<"请输入你想要修改的学生的姓名或学号:";
cin >>sign;
fflush(stdin);
string str1;
getline(inData, str1);
memorize *H = new memorize;
memorize *p = H;
memorize *q = H;
bool flag = true;
while (inData >>p->object.name >>p->object.number >>p->object.qq
>>p->object.major >>p->object.classnum)
{
p->next = new memorize;
p = p->next;
p->prior = q;
q->next = p;
q = p;
}
p->next = NULL;
inData.close();
p = H;
while (p)
{
if ((p->object.name==sign) || (p->object.number==sign))
{
if (flag)
{
cout <<endl <<"你想修改你学生的信息如下: " <<endl <<endl;
cout <<endl <<str1 <<endl;
cout <<setiosflags(ios::left) <<setw(17)
<<p->object.name <<" " <<setw(16) <<p->object.number
<<" " <<setw(18) <<p->object.qq
<<" " <<setw(14) <<p->object.major
<<" " <<setw(20) <<p->object.classnum <<endl;
flag = false;
}
cout <<endl <<"请根据下面提示修改信息 : " <<endl;
cout <<"姓名 :" ;
cin >>p->object.name;
fflush(stdin);
cout <<"学号 :";
cin >>p->object.number;
fflush(stdin);
cout <<"班级 :";
cin >>p->object.classnum;
fflush(stdin);
cout <<"QQ :";
cin >>p->object.qq;
fflush(stdin);
cout <<"专业 :";
cin >>p->object.major;
fflush(stdin);
break;
}
p = p->next;
}
if (flag)
{
cout <<endl <<"你的花名册中没有你找的学生 !!!!" <<endl <<endl;
system("pause");
return;
}
else
{
ofstream out("pmessage.txt",ios::out);
if (!out)
{
cout <<endl <<"对不起!!!不能打开文件!!!!" <<endl;
system("pause");
return;
}
out <<str1 <<endl;
p = H->next;
while (p)
{
cout <<setiosflags(ios::left) <<setw(17) <<p->object.name
<<" " <<setw(16) <<p->object.number
<<" " <<setw(18) <<p->object.qq
<<" " <<setw(14) <<p->object.major
<<" " <<setw(20) <<p->object.classnum <<endl;
p = p->next;
}
out.close();
cout <<endl <<"信息已经修改完成!!!!" <<endl <<endl;
system("pause");
}
}
//查询联系人
void message::select()
{
ifstream inData("pmessage.txt",ios::in);
if (!inData)
{
cout <<endl <<"对不起!!!!文件找不到!!!!" <<endl;
system("pause");
return;
}
string sign;
cout <<endl <<"输入你想查找的学生的姓名或学号: ";
cin >>sign;
fflush(stdin);
string str1;
bool flag = true;
string str;
while (inData >>name >>number)
{
getline(inData, str);
if ((name==sign) || (number==sign))
{
cout <<endl <<"你要查找的学生是: " <<endl <<endl;
cout <<str1 <<endl;
cout <<setiosflags(ios::left) <<setw(17) <<name
<<number <<str <<endl;
flag = false;
break;
}
}
system("pause");
}