在书架管理软件中添加书架问题!

编程入门 行业动态 更新时间:2024-10-09 00:44:23
本文介绍了在书架管理软件中添加书架问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的图书馆管理系统代码.现在,我尝试在此代码中添加一个应以这种方式工作的书架功能:每个书架可以有3个书本条目,然后,将书本输入到下一个书架中. 我遇到的问题是,即使在第三次输入之后,所有书籍也都被输入到第一层书架中.此功能使用的代码为粗体!

Here is my code for library management system. Now i have tried to add a shelves function in this code which is supposed to work in this manner: Each shelf can have 3 book entries and after that, books are entered into the next shelf. The problem i''m having is that all the books are entered into the 1st shelf even after the 3rd entry. The code used for this function is in bold!

//*************************************************************** // CLASS USED IN PROJECT //*************************************************************** class book { char bno[6]; char bname[50]; char aname[20]; int count1; int shelf; public: book() { count1=0; shelf=1; } void create_book() { cout<<"\nNEW BOOK ENTRY...\n"; cout<<"\nEnter The book no."; cin.ignore(); cin.getline(bno,6); cout<<"\n\nEnter The Name of The Book "; cin.getline(bname,50); cout<<"\n\nEnter The Author's Name "; cin.getline(aname,20); cout<<"\n\n\nBook Created.."; count1++; if (count1 == 3 ) { shelf++; count1=0; } } void show_book() { cout<<"\nBook no. : "<<bno; cout<<"\nBook Name : "<<bname; cout<<"\nAuthor Name : "<<aname; cout<<"\nShelf number : "<<shelf; } char* retbno() { return bno; } void report() {cout<<bno<<setw(30)<<bname<<setw(30)<<shelf<<setw(30)<<aname<<endl;} }; //class ends here

推荐答案

您需要创建一个静态类成员来保存下一个计数和架子,并对其进行静态初始化,而不是在构造函数中对其进行初始化... You need to make a static class member that holds the next count and shelf, and initialize them statically, rather than initializing them in the constructor... class book { char bno[6]; char bname[50]; char aname[20]; int my_count; int my_shelf; static int total_books_count; static int current_shelf; book () { my_count = total_books_count; my_shelf = current_shelf; total_books_count++; if (total_books_count == 3) { total_books_count = 0; current_shelf++; } } void create_book() { cout<<"\nNEW BOOK ENTRY...\n"; cout<<"\nEnter The book no."; cin.ignore(); cin.getline(bno,6); cout<<"\n\nEnter The Name of The Book "; cin.getline(bname,50); cout<<"\n\nEnter The Author''s Name "; cin.getline(aname,20); cout<<"\n\n\nBook Created.."; } ... } int book::total_books_count = 0; int book::current_shelf= 0;

编写代码的方式是,每本书都以它自己的count1 = 0且架子= 1开头,而每本书都认为这是唯一的一本书...

The way you have the code written, every book starts out with it''s own count1 = 0 and shelf = 1 and each book thinks it''s the only book...

更多推荐

在书架管理软件中添加书架问题!

本文发布于:2023-11-23 07:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620592.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:书架   管理软件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!