鱼C论坛

 找回密码
 立即注册
查看: 2990|回复: 1

[其他分类] C++:基于顺序存储结构的图书信息表的创建和输出

[复制链接]
发表于 2021-9-29 21:34:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 划句顾 于 2021-9-29 21:35 编辑

作业题啦~~~  记录作业,以后期末考可以拿来看看复习一下嘿嘿
  1. /**
  2. @time:2021/9/29
  3. @author:LaoGu
  4. @purpose:基于顺序存储结构的图书信息表的创建和输出
  5. **/
  6. #include<iostream>
  7. #include<string.h>

  8. using namespace std;  //加了这句话,下面的cout和cin就不用加std:: ,例如std::cout<<

  9. #define OK 1
  10. #define ERROR 0
  11. #define OVERFLOW -2
  12. typedef int Status;
  13. #define MAXSIZE 10000

  14. typedef struct tagBook{
  15.   char no[20];
  16.   char name[50];
  17.   float price;
  18. }Book;

  19. typedef struct tagSqList{
  20.   Book *elem;
  21.   int length;
  22. }SqList;

  23. int main(){
  24.         //声明函数
  25.         Status InitList_Sq(SqList &L);
  26.         Status PrintList_Sq(SqList &L);
  27.         Status CreationList_Sq(SqList &L,char *no,char *name,float &price);
  28.         SqList L;    //定义L为SqList
  29.         InitList_Sq(L);  //初始化L
  30.         char no[20],name[50];
  31.         float price;
  32.     cout<<"ISBN "<<"书名   "<<"价格   "<<endl;
  33.         while(cin>>no>>name>>price){
  34.           if(!strcmp(no,"0")&&!strcmp(name,"0")&&price==0.0)
  35.                   break;
  36.           CreationList_Sq(L,no,name,price);
  37.         }
  38.         PrintList_Sq(L);
  39.         return 0;
  40. }


  41. //函数
  42. Status InitList_Sq(SqList &L){
  43.   L.elem = new Book[MAXSIZE];
  44.   if(!L.elem) exit(OVERFLOW);
  45.   L.length = 0;  //空表长度为0
  46.   return OK;
  47. }

  48. Status CreationList_Sq(SqList &L,char *no,char *name,float &price){
  49.   Book B;
  50.   strcpy(B.no,no);
  51.   strcpy(B.name,name);
  52.   B.price = price;
  53.   L.elem[L.length] = B;
  54.   L.length++;
  55.   return OK;
  56. }

  57. Status PrintList_Sq(SqList &L){
  58.     cout<<endl; //空一行
  59.         cout<<L.length<<endl;  //输出书本的总数
  60.     cout<<"ISBN  "<<" 书名   "<<"价格   "<<endl;
  61.         for(int i = 0; i<L.length;i++){
  62.           cout<<L.elem[i].no<<"   "<<L.elem[i].name<<"  ";
  63.           printf("%.2f\n",L.elem[i].price);
  64.         }
  65.          return OK;
  66. }
复制代码




                               
登录/注册后可看大图

运行结构如下:
1632922316(1).jpg



                               
登录/注册后可看大图

QaQ 作业还要画流程图!!!giao要命
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-11-5 09:06:58 | 显示全部楼层
学习了  

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-1 00:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表