Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been working at this assignment but I keep getting stuck. I could really u

ID: 3622037 • Letter: I

Question

I've been working at this assignment but I keep getting stuck. I could really use an example of how this is done. I received some help, but I'm still stuck.

I have to write a program for a vending machine. The user has to deposit money, then order the product. As the machine operates, it must keep a log of what is happening, and must also keep inventory. I can have a maximum of 20 products. If the number of a particular item is low, it must read low-inventory next to the product. If the item is sold out, the item should not be available for purchase.

The main issue I'm having is with the file saving and the 2 configuration files we have to tie in. I know I need to use arrays to save the data, but this is my first experience with the file saving and I'm somewhat confused.

The configuration files must format should read like this:
1. The name of the vending machine
2. The vending machine ID#
3. The company that owns the machine
4. Advertising message for a product
5. Goodbye message after the the transaction is finished

I understand this is lengthy, but I could really use some help. I've been at this for 2 weeks and it's just not coming out right. Like I said before, the trouble for me is in the files and the configuration files. If more information is needed (like the configuration files or anything else), please let me know. Thanks

Explanation / Answer

This site should help you with file IO. To write files, you want to create an ofstream (output file stream) which you can write to like cout.

When writing arrays to a file, the easiest way is to write each element separately. For example, you might have the format

length

element0

element1

element2

...

Each element could be several items, i.e. you could have

length

name0 id0 company0 advertising_message0 goodbye_message0

name1 id1 company1 advertising_message1 goodbye_message1

name2 id2 company2 advertising_message2 goodbye_message2

...

Each item could even be on a separate line if necessary. That just changes how you read it in.

When you read the file, read in the length, then loop that many times to read in elements.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote