在书架管理软件中添加书架问题! [英] Adding shelves in a Library management software problem!

查看:143
本文介绍了在书架管理软件中添加书架问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的图书馆管理系统代码.现在,我尝试在此代码中添加一个应以这种方式工作的书架功能:每个书架可以有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...


这篇关于在书架管理软件中添加书架问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆