C++ :: What STL Container Should Be Used For Inventory
Mar 27, 2014
So I'm writing an RPG and I'm in need of an inventory system. Of course as an relatively old member of the forum I know best than just come here and ask so I've already researched quite a bit and I've formulated this idea.
I've kind of conceptualized it like so: I'll have some sort of STL container of a unique_ptr of my base item class. There will be derived item classes. Taking advantage of polymorphism I can then call the new Derivedclass when inserting it in the STL container.
My questions are: What STL container should be used for the inventory(fixed sized)?
View 2 Replies
ADVERTISEMENT
Jan 15, 2015
im working on mine first 2d game and im practicing a lot, how to input my inventory for character ( for items, and others ) So, i just want to let u know that i have :
#define WEAPON_LONGSWORD (1)
#define WEAPON_WARAXE (2)
#define WEAPON_DAGGER (3)
#define WEAPON_SHORTSWORD (4)
#define WEAPON_BOW (5)
#define WEAPON_MAX (6)
So, i want to put this in my shop and if i buy it i want to appear in my inventory, or sell sell trought my inventory.Also i have one define
#define WEAPONBEGIN_WOODENSTICK (1)
Which will go instant ( when u create character ) to inventory. And:If i have 1, 2, 3, 4, 5, 6, 7, 8, 9 slots ( example ) and i sell item which was on 3rd slot, what will happen with others ? will they just go back for one slot or ?
View 5 Replies
View Related
Sep 2, 2014
I am making a text based rpg for school and im having troubles with it. Ineed to add an inventory into my game and im not to sure as to where or how.. this is what i got for player
#ifndef PLAYER_H
#define PLAYER_H
//console Util.h includes <iostream> , <string> and <window.h> and defines
//the NOMINMAX macro. As a result of including ConsoleUtil.h, PLayer will
// also knaow about thoes objects.
#include "ConsoleUtil.h"
[Code] ...
View 2 Replies
View Related
Jan 26, 2013
How to make a program in C to create a product inventory file containing pro0duct name, cost and quantity and then read the prouct inventory file.
View 9 Replies
View Related
Jul 14, 2014
How would i do this? Im trying to create an inventory but this just will not work, when i do it how i have it originally (as shown below):
cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y') {
cout << endl;
string invintory2[6] =
[Code] ....
the program outputs this:
cout << "Do you have weapons and armor?: ";
cin >> yEquip;
if (yEquip == 'y'){
cout << endl;
string invintory1[6];
[Code] ....
however programing it like this seems very... time consuming.
my other arrays (normal ones that just hold a set of int's) look like this:
int *player[] = {&yhp,&ymp,&ypatk,&ymatk,&yratk,&ypdef,&ymdef,&yrdef,&ydb,&yacc,&ycr,&yas};
Is there any way to do a string array in this way?
View 8 Replies
View Related
Jan 13, 2015
I'm trying to create an inventory system in C++ using classes and objects. Here is what I have now
Item.h
#pragma once
#include <iostream>
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
[Code]....
Basically what I want my inventory system to become is this: [URL] Each slot can hold an item.
Basically this inventory system should be able to do what RS Inventory system can do. (Hold items, Use items, Equip Items (No need for moving item))
View 5 Replies
View Related
Jun 7, 2013
So my inventory program runs fine as far as I can tell. Except when entering "Amounts" with more that 1-precision . ie
Amount Entered : 25.99 // Problem
Amount Entered : 25.9 // No Problem
When entering say 25.99, the rest of the file is jibberish. but 25.9, the rest of the file is fine
Code:
#include <stdio.h>
typedef struct toolRecord{
int record_num;
char tool_name[16];
int quantity;
double price;
[Code] .....
View 5 Replies
View Related
Nov 14, 2014
You are requested to create an inventory control application for a drink stall (give a name to the stall). The application is used to show the list of drinks the stall sells, how many of each item on‐hand and the cost of each item. The records are to be saved and retrieved to/from a binary file called “drinks.txt”. For each drink in the stall, your program is to keep the information as a Record Structure called DrinkRecord. The structure should at least consist of the following:
(1) Item Number
(2) Item Name
(3) Quantity
(4) Unit Price
Your application should have the following features:
(a) Display a drink information
(b) Add a new drink information
(c) Update a new drink information
(d) Delete a drink information
(e) Display all drink information
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
[code].....
Everything works fine with minor issues, but I'm having trouble with the editing function. I need to be able to search for a specific drink then be able to edit its contents and print the new contents to the file. I have not created a structure yet. I will do that as soon as possible.
View 1 Replies
View Related
Feb 9, 2013
I made two dimensional array to represent my (game) inventory. Slot is empty if its value is 0 and 1 if not.
Now i need to find if i can put new item in my inventory that can take up 4x2 slots. I tried this but it doesn't work as i expected:
#include <iostream>
int main() {
const int inventorySlotRows = 5;
const int inventorySlotColumns = 5;
int arr[inventorySlotRows][inventorySlotColumns] =
[Code] .....
View 2 Replies
View Related
Apr 10, 2015
I am having some trouble creating a listbox in visual studio. I declared an array, set initial values, and now I would like to be able to update those values. It is a pizza inventory app, so I need to update the initial values once the user has added inventory. This is the code I have for the "Update Inventory" button:
// read in value and convert to double
double dblInput = Convert.ToDouble(txtInput.Text);
// loop through ingredients and add inventory to selected ingredient
for (int i = 0; i < dblInventory.Length; i++) {
// is item at i checked for update?
if(lstInventory.GetItemCheckState(i) == CheckState.Checked)
[Code]....
View 11 Replies
View Related
Aug 25, 2014
You are required to write a program for a Used Car Dealer company. In the system you need to maintain the cars’ inventory and details. Each car in the company contains the following details:
• Car Registration Number
• Car Make or Brand
• Car Model
• Car Colour (eg. Silver, Black , Red)
• Year of manufacturing (The year the car was manufacture)
• Engine Capacity (in cc)
• Transmission (manual or automatic)
• Cost of the car (SGD)
The Car Registration Number is in the format of AAA1234 or AA1234A or A1234A which is accordance to the Malaysia car registration format. The A alphabet is in accordance to the registration number for respective in Singapore. (eg. AEW9829 or W1212Y or MCD1177). Note the A and the 1234 total count in the registration number can be less than 3 like AT9829 or BHY280. The Car Make is for the identifying the manufacturer of the car like Honda, Toyota, Proton..etc. The Car Model is to represent the Manufacturers’ respective model like Honda City, Honda Civic, Honda Accord, Toyota Vios, Toyota Camry … etc.
You are required to create menu and operations for:
1) Create a new Car account
2) Edit existing Car account details
3) Remove a car account from the system
4) Search for cars in the system (based on Car Make, Model, Year of manufacturing or Price)
5) Check total inventory in the system
View 1 Replies
View Related
Feb 23, 2014
Write a constructor that initializes a new inventory object with the values passed as arguments, but which also includes a reasonable default value for each parameter.
#include "stdafx.h"
#include <iostream.h>
#include <stdio.h>
#include <string.h>
class inventory {
[Code] ....
I am not trying to get my homewotk done, just to understand my errors. It complies without problem. But doesn't run.
View 2 Replies
View Related
Sep 22, 2013
What is container class? what its advantage ?
View 2 Replies
View Related
Sep 16, 2012
I have a pile of data, which i need to access frequently and fast. One entry consists of two unsigned ints, let`s call them source and destination.
One source can have several destinations, but this rarely ever happens. Several sources can have the same destination - this happens more frequently, but still scarcely.
Once the data is set up, it rarely ever changes - yet it should be possible to add or remove entries.
I now need to find all sources for a given destination, or all destinations for a given source.
The question: which stl container to choose?
I have tried a multimap, using the source as key. This works good for finding all d for a given s, but is inefficient in the other direction.
Do you think it would be more efficient to have two multimaps, sorted respectively by source and destination?
View 1 Replies
View Related
Mar 6, 2013
I am trying to come up with a way to make use of a "multilevel dynamic" container. I am parsing a file to grab some pieces of data. Lets say the first field of data I find I push into an array. At the same time lets I wish to create 2 cascaded sublevels. So an element in Modules is a pointer to the Types vector associated with that module and each element in Types is a pointer to a vector of Data. This concept should be similar to memory paging.
/*
Modules Types Data
____ _____ ______
|____|------> |_____| ---------->|______|
|____| |_____| |______|
|____| |_____| |______|
|____|
|____|
|____| _____ ______
|____|------> |_____|----------->|______|
|____| |_____| |______|
*/
Obviously this becomes very hair quickly so it is obvious that I need to dynamically create and destroy vectors (if I do it this way). Should I just create pointers using the new operator?
Here is some of my code if it is even worthwhile to read:
class Parser {
//storage arrays
vector <string> modules;
vector <string> terminal_type;
vector <string> tag_type;
vector <string> data;
[Code] ....
parse this stuff and nicely organize it.
If you take the first one, "max_logvar" is a module so everything between < and > is associated with that module.
symb is unimportant for now.
then "proterm" is a "module type" so then module now needs a module type container but I may have more than one of those.
so then I break it down by "Input" and "Output" where each of those can have the integer values (just in an array where each position will be set) that are in the fields to the right.
View 1 Replies
View Related
Nov 21, 2013
I have a container in c++11 and i must delete first object and i don't know how...
for (const prob& p : *static_cast<vector<prob>*>(list.listData)){
// i must delete the first object
}
View 2 Replies
View Related
Apr 25, 2014
How do we design a container of objects all of which belong to some subclass which directly/indirectly inherits from a given parent class? Moreover, I would like to have functions that enable me to pick only objects of a certain class type from the container.
For example if the parent class is A and I have a hierarchy of classes that derive from it, we must have a container that can contain any class that exists in this hierarchy. Also, get_B() must be able to let me examine only those objects in this container that inherit (directly/indirectly) from class B (class B exists in the hierarchy rooted at A).
Preferably, we would like to avoid downcasting. Or even explicit typechecking of any sort.
View 8 Replies
View Related
Mar 30, 2014
To my understanding, a Container should have an Allocator member data, which is used internally.
Question: what happens, for example, when we swap() two containers that use different allocators?
Must the allocators be swapped as well?
Must all elements of the container be reallocated when the allocator is changed?
View 7 Replies
View Related
Jun 24, 2013
I need to create an array container with the same structure as double myA [100][100];. But I cannot declare it as array<double, 100, 100> myA; however I do need this container for its format. How can I make it work.
View 6 Replies
View Related
Feb 9, 2013
I know that it's a class that contains data from another class I just do not know how to make them both work together.
View 1 Replies
View Related
Jun 14, 2013
i built a programming language called jade that right now can only print. i want to add variables to it however. I am going to use a modified bajarne stroustrop calculator to handle expressions (ie will now include string manipulations and such), but I want to build a var class into the program to make it easier for the program. i want variables to act like python variabes, and arrays to act like python associative arrays. Ive scoured different containers, but they only work if the variable isnt an array in my language, because it will only have one type. the only thing i can come up with is a union and 4 overloaded = operators (for bool, int, double, and string) is there a better way to do this?
View 2 Replies
View Related
Oct 31, 2013
so i have a container called Source that is of type std::map<std::string, std::vector<std::string>> but when I try to print it with this function:
void Lexer::PrintSource()
{
for(auto Iterator = this->Source.begin(); Iterator != this->Source.end(); Iterator++)
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
cout<< *SubIterator << endl;
}
i get these errors:
Lexer.cpp: In member function 'void Lexer::PrintSource()':
Lexer.cpp:29:42: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'begin'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
Lexer.cpp:29:76: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'end'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
View 6 Replies
View Related
Nov 23, 2013
I have a deposit of containers and i must delete the cats container. How i can do that?
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Cat {
string name;
int age;
[Code] .....
View 2 Replies
View Related
May 13, 2014
I want to find all instances of a substring mysub in array container myarr and replace each occurrence of mysub with empty string " ". To do that, I'd like to use for loop with search algorithm.
Code below:
p=array iterator
for ( p=search(myarr.cbegin(),myarr.end(), mysub.begin(),mysub.end();
p!=myarr.end();
p=search(p,myarr.end(),mysub.begin(),mysub.end() ); {
[Code] ......
View 2 Replies
View Related
Jun 30, 2014
I need a "meaningful" way of accessing a table, the column is representing Err magnitude, and the row is representing Rate magnitude. For each error magnitude and rate magnitude, i define an action magnitude, which is the contains of the table. For example,
Code:
int matrix[10][10];
int Action1 = matrix[0][0];
int Action2 = matrix[0][1];
However, i need a better way of getting matrix[0][0], row and col itself is meaningless. I want to access the table like
"Action magnitude" = matrix["Rate magnitude 1"]["Err magnitude 2"]; using a string instead of int id.
How to easily do this in c++ container?
View 4 Replies
View Related
Jan 16, 2012
I have a class called CTestObject and it has one variable int id. I want to add instances of this to an std container and be able to:
1. quickly determine if the value of "int id" exists in the container and update the object
or
2. add a new object to the container
Which std container is the best for this application? What method should I use to search the container for the object id?
View 14 Replies
View Related