Home | Community | Message Board

MagicBag Grow Bags
This site includes paid links. Please support our sponsors.


Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Shop: Kraken Kratom Red Vein Kratom   PhytoExtractum Maeng Da Thai Kratom Leaf Powder

Jump to first unread post Pages: 1
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
C++
    #7418109 - 09/16/07 09:57 PM (16 years, 4 months ago)

i need some help from all you programmers out there.

i need to write a program that handles resources for projects, like when to buy materials, how much to buy and stuff like that.

but i ran into a little problem. i need to be able to enter a product, then the materials needed for that product, then for each of those materials i need to enter their respective materials and so on. i need to enter a whole lot more things but after i figure this out i can do that on my own. here's an example:

for product T i need 2 units of material U and 3 units of material V. Now, for U i need 1 unit of W and 2 units of X. For V i need 2 units of W and 2 units of Y.

so what i had thought of doing was this:

struct product{
        char name[20];
        ....
        ....
        .... // these are a bunch of other variables that i need, don't mind them.
        int components; // this is the number of materials or components that this particular product or part needs
        product *parts; // this is were i'll make an array of all the components for this part or product, that's why i need "components"
};

so basically, i would ask for the name and a bunch of other data and then i would ask how many components or materials this product needs, and based on this number i would make an array of products/materials/components needed for this part/product.

for T, i need 2 materials so T.components would take the value of two and then i would do this:
T.parts = new product[T.components];

that would create an array of products "inside" (you know what i mean) of T, and then i would have to fill up all the members of this array(in the example i gave it would be U and V). so when filling up U and V, it would in turn create new arrays of products/materials for them. but since i don't know how many "levels" of materials there will be i think i need a recursive function to fill up the chain. i was wondering if anyone knew how that function should be cuz i have no idea. i haven't had anything to do with C++(or any other language) in at least three years so i'm more than just a little rusty, i'm fucking lost.

any help would be greatly appreciated. :yesnod:


Extras: Filter Print Post Top
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
Re: C++ [Re: maggotz]
    #7418116 - 09/16/07 09:58 PM (16 years, 4 months ago)

was i making myself clear?


Extras: Filter Print Post Top
InvisibleJrsxt
Stranger

Registered: 05/14/07
Posts: 1,043
Re: C++ [Re: maggotz]
    #7418136 - 09/16/07 10:02 PM (16 years, 4 months ago)

what kind of business is it


Extras: Filter Print Post Top
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
Re: C++ [Re: Jrsxt]
    #7418196 - 09/16/07 10:17 PM (16 years, 4 months ago)

i actually need it for a class.


Extras: Filter Print Post Top
OfflineCompass
Ancient Light

Registered: 10/17/06
Posts: 1,149
Loc: The Border of Reality
Last seen: 7 years, 2 months
Re: C++ [Re: maggotz]
    #7418203 - 09/16/07 10:20 PM (16 years, 4 months ago)

if it is C++, maybe use std::string instead of char[20] ?

and instead of an array of products, consider std::vector

but for the recursive part,

Code:
void fill_products(product& prod) {

if more products:
allocate array
for each product in new array:
fill_products(i)

else: // base case
return

}



Extras: Filter Print Post Top
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
Re: C++ [Re: Compass]
    #7418237 - 09/16/07 10:28 PM (16 years, 4 months ago)

that probably makes more sense but like i said i hadn't seen a line of code in like 3 years and i still haven't checked my book.

i'll try that recursive bit but it'll have to wait till tomorrow. i've has like 5 hours of sleep since friday. thanks for your input.


Extras: Filter Print Post Top
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
Re: C++ [Re: maggotz]
    #7418246 - 09/16/07 10:29 PM (16 years, 4 months ago)

could you elaborate on std::vector? what is it and how could i use it?


btw, i'm no pro programmer.


Extras: Filter Print Post Top
OfflineCompass
Ancient Light

Registered: 10/17/06
Posts: 1,149
Loc: The Border of Reality
Last seen: 7 years, 2 months
Re: C++ [Re: maggotz]
    #7418499 - 09/16/07 11:36 PM (16 years, 4 months ago)

a vector is like an array, but it keeps track of the size for you and automatically allocates new space when you add new items to the *back* of the array.

it's part of standard C++, so you will always be able to use it. it is part of the std (standard) namespace.

at the top of your code.

#include <vector>
using std::vector;

then you can just say

struct product {
// ....
vector parts < product >;
}

if you don't know about namespaces and templates, read up! key to learning C++, instead of just C.


--------------------
nystagmus dopamine guru inverted pop culture love scars of sorrow fleshy synesthesia hippie farts perpetual tinnitus
Reclaim the Swastika!


Extras: Filter Print Post Top
OfflineSymmetryGroup8
It's about theFLOW!
Male


Registered: 02/25/07
Posts: 506
Last seen: 16 years, 8 days
Re: C++ [Re: Compass]
    #7418605 - 09/17/07 12:34 AM (16 years, 4 months ago)



--------------------
Be like water my friend!


Extras: Filter Print Post Top
OfflineSeussA
Error: divide byzero


Folding@home Statistics
Registered: 04/27/01
Posts: 23,480
Loc: Caribbean
Last seen: 2 months, 20 days
Re: C++ [Re: maggotz]
    #7418861 - 09/17/07 05:17 AM (16 years, 4 months ago)

It sounds like a very simple 'n-tree' problem with 'prefix traversal' to calculate the result. Google is your friend, now that you know the appropriate search terms.


--------------------
Just another spore in the wind.


Extras: Filter Print Post Top
Offlinesupra
computerEnthusiast
Registered: 10/26/03
Posts: 6,446
Loc: TEXAS
Last seen: 12 years, 9 months
Re: C++ [Re: maggotz]
    #7420400 - 09/17/07 04:44 PM (16 years, 4 months ago)

take a look here, anytime i need help with certain containers or classes, this is where i look

http://www.sgi.com/tech/stl/

and for vectors, here is a complete list of its member functions and use

http://www.sgi.com/tech/stl/Vector.html

personally, if i was to code this, i would use a switch/case setup to call different functions for each product....but im also no programmer.

And definitely use a string for the name, it is just an array of chars anyways...

peace


Extras: Filter Print Post Top
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
Re: C++ [Re: supra]
    #7422563 - 09/18/07 06:56 AM (16 years, 4 months ago)

thank you all for your help. and yeah, i ended up using string instead of the char[20]. i haven't figured it out 100% yet but with all these links i think i'm on the right track now. :yesnod:

i remember back in the day, when i could have this shit sorted out in no time.


Extras: Filter Print Post Top
OfflineSeussA
Error: divide byzero

Folding@home Statistics
Registered: 04/27/01
Posts: 23,480
Loc: Caribbean
Last seen: 2 months, 20 days
Re: C++ [Re: maggotz]
    #7422570 - 09/18/07 07:00 AM (16 years, 4 months ago)

> i remember back in the day, when i could have this shit sorted out in no time.

*laugh* I hadn't written a line of C code in years (a while back) and sat down one day to write something... it took a good week or two before I got my skills back... and I am somebody that has literally written several hundred thousand lines of C code.


--------------------
Just another spore in the wind.


Extras: Filter Print Post Top
Invisiblemaggotz


Registered: 06/24/06
Posts: 7,539
Re: C++ [Re: Seuss]
    #7422587 - 09/18/07 07:08 AM (16 years, 4 months ago)

i know how you feel. i had forgotten how fun it was to write a few good lines. am i nerd for saying that? :lol:


Extras: Filter Print Post Top
Jump to top Pages: 1

Shop: Kraken Kratom Red Vein Kratom   PhytoExtractum Maeng Da Thai Kratom Leaf Powder


Similar ThreadsPosterViewsRepliesLast post
* Biodiesel Production from Algae
( 1 2 all )
Baby_Hitler 4,823 24 03/15/10 12:25 AM
by Baby_Hitler
* BMW Begins Production of Hydogen Powered Car DiploidM 1,636 9 09/13/06 10:35 PM
by badreligion2good
* Self-replicating production facilities: What would their impact be?
( 1 2 all )
Baby_Hitler 2,797 23 04/10/05 06:14 PM
by blkhole
* The 25 worst tech products of all time RandalFlagg 825 7 05/29/06 09:18 AM
by OJK
* Microchips in ALL consumer products: Invasion of privacy? Cow Shit Collector 979 7 07/21/03 10:24 PM
by Gumby
* Lost my XP product key - NEW QUESTION
( 1 2 all )
Great Scott 2,908 22 09/03/07 09:32 PM
by sherm
* A new backup power supply (UPS) technology/product? HagbardCeline 330 0 08/10/06 09:11 PM
by HagbardCeline
* Calling gentoo users
( 1 2 all )
supra 2,503 28 10/20/08 08:23 PM
by automan

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: trendal, automan, Northerner
1,109 topic views. 0 members, 1 guests and 3 web crawlers are browsing this forum.
[ Show Images Only | Sort by Score | Print Topic ]
Search this thread:

Copyright 1997-2024 Mind Media. Some rights reserved.

Generated in 0.027 seconds spending 0.006 seconds on 14 queries.