如何在不同的链表中添加变量 [英] How to add variables in different linked list

查看:62
本文介绍了如何在不同的链表中添加变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为bookInventory的类,它是进入链表的不同元素的日志..所以每次运行程序时,它都会保存日志并创建一个新的链表。我需要能够获取一个名为bookPages的元素,并保持每次创建新条目时正在读取的页数的运行总计。所以每个列表都有一个变量int bookPages ..所以我需要做的是继续添加这些来创建一个名为int totalBookPages的变量..

类bookInventory

string nameofBook ,bookBook,publishBook,placebook;

int bookPages,totalPagesRead;



菜单:

1.输入图书信息:

2.使用书名搜索图书信息:

3.使用图书名称修改图书信息:

4.删除使用书名预订信息:

5.将图书信息保存到文件并退出



每次输入图书信息时,它都会被输入从上面的变量2并保存它们..所以我的保存文件看起来像这样

哈利波特

JK罗琳

一些发布者

英格兰

205

205

指环王

JRR Tolkien

另一个出版商

中世纪

350

总计应为205 + 350 = 555



所以我的问题是如何让我的程序保持总计的totalPagesRead。因此它会自动将其打印出来而无需用户进行数学计算。

I have a class called bookInventory that is a log of different elements that go into a linked list.. so every time the program is ran it saves the logs and creates a new linked list. I need to be able to take an element called bookPages and keep a running total of how many pages are being read each time a new entry is created. So each list will have a variable int bookPages.. so what I need to do is keep adding these to create a variable called int totalBookPages..
Class bookInventory
string nameofBook, authorBook, publishBook, placebook;
int bookPages, totalPagesRead;

Menu:
1. Enter Book Information:
2. Search for Book Information using Name of Book:
3. Modify Book Information using Name of Book:
4. Delete Book Information using Name of Book:
5. Save Book Information to file and Exit

Each time Enter Book Information is ran it takes in the variable2 from above and saves them.. so my save file looks like this
Harry Potter
JK Rowlings
some Publisher
England
205
205
Lord of the Rings
J. R. R. Tolkien
another Publisher
Medieval
350
total should be 205+350=555

So my question is how can I get my program to keep a running total of totalPagesRead. so it prints it out automatically without the user having to do the math.

推荐答案

你的问题不是那么清楚(也不是问题)但如果你是每次都建立一个新的链表,然后重新计算列表中的总项目。如果要构建链表的列表,那么在每个列表的头节点中可能包含一些将提供列表总数的内容。
Your question is not really that clear (nor is it a question) but if you are building a new linked list each time, then just recalculate the total items in the list. If you are building a list of linked lists, then in the head node of each list perhaps include something that will provide the total for the list.


这篇关于如何在不同的链表中添加变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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