|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 划句顾 于 2021-9-29 21:35 编辑
作业题啦~~~ 记录作业,以后期末考可以拿来看看复习一下嘿嘿
- /**
- @time:2021/9/29
- @author:LaoGu
- @purpose:基于顺序存储结构的图书信息表的创建和输出
- **/
- #include<iostream>
- #include<string.h>
- using namespace std; //加了这句话,下面的cout和cin就不用加std:: ,例如std::cout<<
- #define OK 1
- #define ERROR 0
- #define OVERFLOW -2
- typedef int Status;
- #define MAXSIZE 10000
- typedef struct tagBook{
- char no[20];
- char name[50];
- float price;
- }Book;
- typedef struct tagSqList{
- Book *elem;
- int length;
- }SqList;
- int main(){
- //声明函数
- Status InitList_Sq(SqList &L);
- Status PrintList_Sq(SqList &L);
- Status CreationList_Sq(SqList &L,char *no,char *name,float &price);
- SqList L; //定义L为SqList
- InitList_Sq(L); //初始化L
- char no[20],name[50];
- float price;
- cout<<"ISBN "<<"书名 "<<"价格 "<<endl;
- while(cin>>no>>name>>price){
- if(!strcmp(no,"0")&&!strcmp(name,"0")&&price==0.0)
- break;
- CreationList_Sq(L,no,name,price);
- }
- PrintList_Sq(L);
- return 0;
- }
- //函数
- Status InitList_Sq(SqList &L){
- L.elem = new Book[MAXSIZE];
- if(!L.elem) exit(OVERFLOW);
- L.length = 0; //空表长度为0
- return OK;
- }
- Status CreationList_Sq(SqList &L,char *no,char *name,float &price){
- Book B;
- strcpy(B.no,no);
- strcpy(B.name,name);
- B.price = price;
- L.elem[L.length] = B;
- L.length++;
- return OK;
- }
- Status PrintList_Sq(SqList &L){
- cout<<endl; //空一行
- cout<<L.length<<endl; //输出书本的总数
- cout<<"ISBN "<<" 书名 "<<"价格 "<<endl;
- for(int i = 0; i<L.length;i++){
- cout<<L.elem[i].no<<" "<<L.elem[i].name<<" ";
- printf("%.2f\n",L.elem[i].price);
- }
- return OK;
- }
复制代码
运行结构如下:
QaQ 作业还要画流程图!!!giao要命 |
|