第83章 不要
不要看!
{
elemtype data[maxsize];
int length;
}sqlist;
void createlist(sqlist& l, elemtype a[], int n)//创建
{
int i = 0, k = 0;
l = (sqlist)malloc(sizeof(sqlist));
while (i < n)
{
l->data[i] = a[i];
k++;
i++;
}
l->length = k;
}
void destroylist(sqlist& l)
{
free(l);
}
void displist(sqlist l)//显示
{
int i;
for (i = 0; i < l->length; i++)
{
cout<<l->data[i]bname<<" "<< l->data[i]price<<" "<< l->data[i]num<<endl;
}
}
int locateelem(sqlist l, char e[])//查找
{
int i = 0;
while (i < l->length&& strcmp(l->data[i]bname, e))
i++;
if (i >= l->length)
return 0;
else return i + 1;
}
bool listinsert(sqlist& l, int i, elemtype e)//插入学生信息
{
int j;
if (i<1 || i>l->length + 1)
return false;
i--;//转换
for (j = l->length; j > i; j--)
l->data[j] = l->data[j - 1];
l->data[i] = e;
l->length++;
return true;
}
bool listdelete(sqlist& l, int i, elemtype& e)//删除
{
int j;
if (i<1 || i>l->length)
return false;
i--;
for (j = i; j < l->length - 1; j++)
{
l->data[j] = l->data[j + 1];
l->length--;
return true;
}
}
void mean() {
cout << "" << endl;
cout << "1、按行删除图书" << endl;
cout << "2、按名查找图书" << endl;
cout << "3、增加图书信息" << endl;
cout << "4、显示图书架" << endl;
cout << "" << endl;
}
int main() {
elemtype a[10] = { {"格林童话",40,01},{"穆斯林的葬礼",51,02},{"聊斋志异",31,03},{"红楼梦",42,04},{"西游记",42,05},{"水浒传",44,06},{"三国演义",45,07} };
int find;
sqlist sq;
char name[10];
elemtype e;
createlist(sq, a, 7);
int x;
while (true) {
mean();
cin >> x;
switch (x) {
case 1:
int a;
cout << "请输入要删除的书本的行数:";
cin>>a;
find=listdelete(sq, a, e);
cout << "删除书籍的第n行数据后,全部书籍的内容如下:\n";
displist(sq);
break;
case 2:
cout << "请输入要查找的书本的名字:";
cin >> name;
find=locateelem(sq, name);
cout<<"\n经查找,书本的信息如下:\n"<< name;
cout << "书名:" << sq->data[find - 1]bname << " " << "价格:" << sq->data[find - 1]price << " " << "编号:" << sq->data[find - 1]num << endl;
break;
case 3:
int b;
cout << "\n请输入需要在几行添加书本的信息:(行数 书名 价钱 编号)\n";
cin >>b>> ebname>>eprice>> enum;
find = listinsert(sq, b, e);
cout << "\n在全部书籍的第a行插入一个新书后,全部书籍的内容如下:\n";
displist(sq);
break;
case 4:
cout << "全部书本的内容如下:\n";
displist(sq);
break;
default: