顺序表,读入相应数据完成信息表的创建,然后根据指定的位置序号,查找,输出相应图书的信息。

 输入:

8
9787302257646 Data-Structure 35.00
9787302164340 Operating-System 50.00
9787302219972 Software-Engineer 32.00
9787302203513 Database-Principles 36.00
9787810827430 Discrete-Mathematics 36.00
9787302257800 Data-Structure 62.00
9787811234923 Compiler-Principles 62.00
9787822234110 The-C-Programming-Language 38.00
2
2
0

输出: 

9787302164340 Operating-System 50.00
Sorry,the book on the best position doesn't exist!

代码:

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define OK 1
#define error 0
#define Maxsize 1000

typedef struct
{
	string IBNS;
	string NAME;
	float PRICE;
}Book;

typedef struct
{
	Book* elem;
	int length;
}List;

int InitList_L(List& L);
int InsertList_L(List& L);
int FindList_L(List L);

int main()
{
	List L;
	InitList_L(L);
	InsertList_L(L);
	FindList_L(L);
	return 0;
}

int InitList_L(List& L)
{
	L.elem = new Book[Maxsize];
	if (!L.elem) exit(0);
	L.length = 0;;
	return OK;
}
int InsertList_L(List& L)
{
	int num;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		cin >> L.elem[i].IBNS >> L.elem[i].NAME >> L.elem[i].PRICE;
		L.length++;
	}
	return OK;
}

int FindList_L(List L)
{
	int num;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		int num1;
		cin >> num1;
		if (num1 > 0 && num1 < L.length)
			cout << L.elem[num1-1].IBNS << " " << L.elem[num1-1].NAME << " " << fixed << setprecision(2) << L.elem[num1-1].PRICE << endl;
		else
			cout << "Sorry,the book on the best position doesn't exist!" << endl;
	}
	return OK;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值