图书馆(书籍)计划 [英] Library (of books) program

查看:62
本文介绍了图书馆(书籍)计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在研究一个使用类(Shelf)和struct(Book)的程序。在主程序中,我们声明了一个类型为shelf的数组(Library [25])。该程序收集有关书籍(作者,标题,isbn等)的各种信息,然后允许您搜索以某个字母开头的书籍,然后显示这些书籍及其上的信息。

此时我可以输入信息,并显示1本书的信息。我很困惑我应该在哪里输入更多信息。我假设它应该在我的主要。我是否需要在循环结束时递增i(我的计数器),以便信息不会复制自身?


Hello everyone. I''m working on a program which uses a class (Shelf) and a struct (Book). In the main program we declare an array (Library[25]) which is of type shelf. The program takes in various info about books (author, title, isbn, etc) and then allows you to search for books starting with a certain letter, and in turn displays those books and the info on them.

At this point I can enter the info, and display the info for 1 book. I''m confused about where I should look to enter more info. I''m assuming it should be in my main. Do I need to increment i (my counter) at the end of the loop so the info is not copying over itself?


展开 | 选择 | Wrap | 行号

推荐答案

你的班级设计有些问题。


你的货架类固定数组为50在课堂上没有任何书籍,书架上有多少本书的数据成员。


你需要一个数据成员。


每次向书架添加书籍时,都可以访问此数据成员,添加和更新数据成员。然后使用原始值将该书添加到数组中的该位置。书架总是需要知道它有多少书。


你需要一个成员函数,如果书架已满(50本书),则返回true,否则返回false。


您需要一个可以定位到任何书籍的成员函数。该职位是另一个数据成员。通过这种方式,您可以调用此函数来设置图书数组中的位置。


您需要一个成员函数转移到下一本书。


等...


或者,您可以使用向量< book>在你的货架类中,并在使用这个向量的货架上写成员函数。
You have some problems in your class design.


Your shelf class has a fixed array of 50 books burt nowhere in the class is there a data member for how many books are on the shelf.

You need a data member for that.

Each time you add a book to the shelf, you access this data member, add, and update the data member. Then using the original value add the book at that location in the array. The shelf always needs to know how many books it has.

You need a member function that returns true if the shelf is full (50 books) and false otherwise.

You need a member function that positions to any book. This position is another data member. This way you call call this function to set the position in your book array.

You need a member function that moves to the next book.

etc...

Or, you could use a vector<book> in your shelf class and write member function in the shelf that work with this vector.


我已经在类bool中声明了。这就是我计划用于真/假......的决定因素。这是不正确的?我想每次调用输入功能我都会计算并调用完整功能,以确定货架是否已满。


J
I have declared in the class bool full. That is what I was planning on using for the true/false....determiner. Is that incorrect? I figured each time I called the input function I would count and also call the full function, to determine whether the shelf was full or not.


J



已在类bool中声明为full。这就是我计划用于真/假......的决定因素。这是不正确的?我想每次调用输入函数时我都会计算并调用完整函数,以确定架子是否已满。
have declared in the class bool full. That is what I was planning on using for the true/false....determiner. Is that incorrect? I figured each time I called the input function I would count and also call the full function, to determine whether the shelf was full or not.



bool full不是会员功能。它只是一个公共数据成员。避免公共数据成员。原因是在main()中使用名称 full 然后如果您需要更改实现完整的方式,则还需要更改所有用户代码。用户不喜欢这样。


就个人而言,由于您有50本书的硬编码限制,我会写一个成员函数名称Full()来测试数组中的书籍数量(使用数据成员)那还不存在)如果这个数字是50,我会回复。

the bool full is not a member function. It is just a public data member. Avoid public data members. The reason is the name full gets used in main() then if you ever need to change how you implement full, you will also need to change all the user code. Users don''t like that.

Personally, since you have a hard-coded limit of 50 books, I would write a member function name Full() to test the number of books in the array (using a data member that''s not there yet) and if that number is 50, I would return true.


这篇关于图书馆(书籍)计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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