Jump to content

C++ Multiple Classes


aimforthehead

Recommended Posts

I am working on a class called "CashRegister", which uses a class called "InventoryItem" that is given to me.

An InventoryItem objects has a description, cost, and unitSize ( "Pepsi", .85, 100);

 

Basically what it does is constructs an array of 5 InventoryItem's, and get's user input from which of the 5 items they would like to purchase and how many of them, subtracting from the total amount.

Then calls function Purchase, which does the calculating and adds the total for that choice into a subtotal.

 

If it were all done as an array in a main program I could do this relatively easily...but I have no clue how to deal with multiple classes.

What information would i put in main? Would i only call a CashRegister object from main? If so, how do I get into the functions/variables in InventoryItem?

 

For example, if I wanted to display a menu of the 5 items I created in CashRegister, would I create a display() function in CashRegister that would display the items, and call that?

What I was thinking is something like

void display(InventoryItem items)

//for loop that displays items

 

But that wouldn't work because when I call it from main I would need access to the items to put into the parameter..I am so confused, if anyone could explain to me it would be helpful, thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.