1.1基于顺序存储结构的图书信息表的创建和输出
#include<iostream>
#include<iomanip>//该头文件为了后面的输出保留两位小数
using namespace std;
#define MAXSIZE 100
#define OVERFLOW -2
#define OK 1
typedef int Status;
typedef struct {//图书信息定义
char no[20];
char name[50];
float price;
}Book;
typedef struct {
Book* elem;//存储空间基地址
int length;//图书表中当前图书个数
}SqList;//图示表的顺序结构存储类型SqList
Status InitList(SqList& L) {//顺序表初始化
L.elem = new Book[MAXSIZE];
if (!L.elem) exit(OVERFLOW);
return OK;
}
int main() {
SqList L;
InitList(L);
int i=1;
while (1) {
cin >> L.elem[i - 1].no >> L.elem[i - 1].name >> L.elem[i - 1].price;
if (!strcmp(L.elem[i - 1].no, "0") && !strcmp(L.elem[i - 1].name, "0") && L.elem[i - 1].price == 0.0)//存疑
{
break;
}
i++;
}
L.length = i - 1;
cout << L.length << endl;
for (int j = 1; j <= L.length; j++) {
cout << L.ele