首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

尚未完成的一个程序解决思路

2012-02-21 
尚未完成的一个程序修改功能,年龄.性别的判断尚未实现,麻烦哪位大侠完善一下:#includeiostream.h#includ

尚未完成的一个程序
修改功能,年龄.性别的判断尚未实现,麻烦哪位大侠完善一下:
#include   <iostream.h>
#include <string.h>
int   count   =1;

struct   readerInfo
{
char   ID[30];
char   name[20];
char   gender[8];
char   age[4];
char   city[20];
bool   isValled;

}reader[1000];

void   addReader();

void   modifyReader();

void   deleteReader();

void   queryReader();

void   main()
{
int   choice   =   1;
while(true)
{
cout   < <   "                 图书馆读者管理系统\n ";
cout   < <   "-------------------------------------------\n ";
cout   < <   "                 -1-                 添加读者\n ";
cout   < <   "                 -2-                 修改信息\n ";
cout   < <   "                 -3-                 删除信息\n ";
cout   < <   "                 -4-                 信息查询\n ";
cout   < <   "                 -5-                 退出系统\n ";
cout   < <   "请选择输入: ";
cin   > >   choice;
switch(choice)
{
case   1:
addReader();
break;
case   2:
modifyReader();
break;
case   3:
deleteReader();
break;
case   4:
queryReader();
break;
case   5:
return;
}
}
}

void   addReader()
{
char   isSave   =   'y ';
char   isContinue   =   'y ';
do
{
readerInfo   read;
cout   < <   "正在添加第 "   < <   count   < <   "位读者\n读者呢称: ";
cin   > >   read.ID;
cout   < <   "读者真实姓名: ";
cin   > >   read.name;
cout   < <   "读者性别(male\\female): ";
cin   > >   read.gender;
read.isValled   =   true;
cout   < <   "读者年龄(0-100): ";
cin   > >   read.age;
cout   < <   "读者城市: ";
cin   > >   read.city;
cout   < <   "是否保存?(y/n) ";
cin   > >   isSave;
if   (( 'y '   ==   isSave)   ||   ( 'Y '   ==   isSave))
reader[count++]   =   read;
cout   < <   "是否继续?(y/n) ";
cin   > >   isContinue;
}while(( 'y '   ==   isContinue)   ||   ( 'Y '   ==   isContinue));
}

void   queryReader()
{
int   choice   =   0;
cout   < <   "--------------------------------------------\n ";
cout   < <   "               -1-                         查询现有读者\n ";


cout   < <   "               -2-                         查询已删除读者\n ";
cout   < <   "--------------------------------------------\n ";

cin   > >   choice;
if   (choice   ==   1)
{
for   (int   i   =   0;   i   <   count;   i++)
{
if   (reader[i].isValled)
{
cout   < <   reader[i].ID   < <   "\t\t ";
cout   < <   reader[i].name   < <   "\t\t ";
cout   < <   reader[i].gender   < <   "\t\t ";
cout   < <   reader[i].age   < <   "\t\t ";
cout   < <   reader[i].city   < <   "\t\t ";
}
}
}

else  
{
for   (int   i   =   0;   i   <   count;   i++)
{
if   (!reader[i].isValled)
{
cout   < <   reader[i].ID   < <   "\t\t ";
cout   < <   reader[i].name   < <   "\t\t ";
cout   < <   reader[i].gender   < <   "\t\t ";
cout   < <   reader[i].age   < <   "\t\t ";
cout   < <   reader[i].city   < <   "\t\t ";
}
}
}
}

void   deleteReader()
{
int   i   =   0;
readerInfo   read;
char   isDelete   =   'y ';
cout   < <   "------------------------ ";
cout   < <   "请输入要删除的读者昵称: ";
cout   < <   "-------------------------------- ";
cin   > >   read.ID;
for   (i   =   0;   i   <   count;   i++)
{
if   (!   strcmp(reader[i].ID,read.ID))
{

cout   < <   reader[i].ID   < <   "\t\t ";
cout   < <   reader[i].name   < <   "\t\t ";
cout   < <   reader[i].gender   < <   "\t\t ";
cout   < <   reader[i].age   < <   "\t\t ";
cout   < <   reader[i].city   < <   "\t\t ";
break;
}
}
cout   < <   "(y/n) ";
cin   > >   isDelete;
if   (( 'y '   ==   isDelete)   ||   ( 'Y '   ==   isDelete))
{
reader[i].isValled   =false;
cout   < <   "删除成功! ";
}
}

[解决办法]
修改功能 


void modifyReader()
{
int i = 0;
readerInfo tmp;
char isSave = 'y ';
cout < < "------------------------ ";
cout < < "请输入要修改信息的读者昵称: ";
cout < < "---------------------------\n ";
cin > > tmp.ID;
for (i = 0; i < count; i++)
{
if (! strcmp(reader[i].ID,tmp.ID))
{
cout < < "要修改信息的读者信息如下: " < < endl;
cout < < reader[i].ID < < "\t\t ";


cout < < reader[i].name < < "\t\t ";
cout < < reader[i].gender < < "\t\t ";
cout < < reader[i].age < < "\t\t ";
cout < < reader[i].city < < "\t\t ";
break;
}
}
cout < < "正在修改第 " < < i < < "位读者呢称为: " < < reader[i].ID < < "的信息 \n ";
cout < < "请输入读者呢称: ";
cin > > tmp.ID;
cout < < "读者真实姓名: ";
cin > > tmp.name;
cout < < "读者性别(male\\female): ";
cin > > tmp.gender;
tmp.isValled = reader[i].isValled;
cout < < "读者年龄(0-100): ";
cin > > tmp.age;
cout < < "读者城市: ";
cin > > tmp.city;
cout < < "是否保存?(y/n) ";
cin > > isSave;
if (( 'y ' == isSave) || ( 'Y ' == isSave))
reader[i] = tmp;
cout < < "修改成功! ";
}

热点排行