//简单的顺序表
#include <iostream>
#include <string>
using namespace std;
typedef int Elemtype;
#define Maxsize 100
//图书信息查询
typedef struct{
string Name;
string Num;
float Price;
}Book;
typedef struct{
Book *elem; //基地址-可以找数据信息
int length;
}Lnode;
//初始化
bool Init(Lnode &L){
L.elem = new Book[Maxsize];//生成一个数组,其每一个数据元素都是Book类型;返回一个指针
if(!L.elem) exit(0);
L.length = 0;
}
//创建
bool CreatList(Lnode &L,int i){
cout<<"请输入书籍名字:\n"<<"编号\n"<<"价格\n";
//Book *p = L.elem;
cin>>L.elem[i].Name>>L.elem[i].Num>>L.elem[i].Price; //基地址的调用方式
L.length ++;
//cin>>p->Name>>p->Num>>p->Price>>endl;
}
//查看
void CatList(Lnode &L){
int len = L.length;
int i = 0;
for(i;i<len;i++){
cout<<"名字:"<<L.elem[i].Name;
cout<<"\n";
}
}
int main(){
int i = 0;
Lnode l;
Init(l);
for(i;i<3;i++){
CreatList(l,i);
}
CatList(l);
//CreatList(l);
}
网友评论