C++ data structures help?

C++ data structures help?
Hi everyone, I’m working on a project. I really just need a little help getting started and a little help with the lingo that is used in the description. Any help would be appreciated.

I’ll post the program description at the bottom since its quite long, first thing..can someone explain to me what it wants when it says that the inventory is echo printed to the output file. I have never heard of echo printing, and also when it shows an example it only shows the inventory which the person has input, so maybe thats what it mean by echo printing? Can someone point me towards a webpage maybe that will help me with inputting from a file, and exception classes for errors.
I also don’t know what it means when its talking about ADT, is it wanting a class template?

Lastly, I would like a few ideas to how to set the program up. Could someone give me a few ideas what functions and such I should use and how I should set the inventory up in an array. Should I use a array for the product number, and then different arrays for the name, price and tax? I would think there is a better way of doing it then that..

Sorry for all the questions, I haven’t coded anything this advanced, and I haven’t used inputting files enough..any help at all will be appreciated. I’m sure ill figure it out slowly. And sorry for writing a book =)

Here is the program description:

Write, run, and test a C++ program to simulate the operation of a grocery store checkout system. Your program should first build a data structure to contain information on all the products available in the store. Then the program should print the cash register receipt for each customer.
Input
The input for this program has two sources: the inventory information is input from a text file, and the customer transactions are input from the keyboard.
1. The information about each product carried by the store is listed on a single line in the inventory file “Invent.dat”, in the following format:


where is a five-digit positive (nonzero) integer, is a string of at most 12 characters with no embedded blanks, is a real number, and is a character (‘T’ if the product is taxable; ‘N’ if it is not taxable). The data in the inventory file is ordered from smallest to largest product number.
2. The customer transactions are input from the keyboard, in the following format:


where is as described above, and is an integer in the range 1 to 100, indicating the quantity of this product desired. A zero input for indicates the end of the customer’s order. (The store will soon be using a scanner to input the product number, but for now it is typed in by the cashier.)
Output

The program outputs should be written to a text file called “Receipts.out”.
1. The inventory information is echo printed to the output file.
2. The cash register receipt for each customer is written to the output file. The receipts should be nicely formatted, with the product description (not the product number), number of items, item price, and total price for each product printed on a single line. At the end of each customer’s order, the subtotal for all items, amount of tax on taxable items, and total bill should be printed, clearly labeled. (The tax rate is 7.5% for taxable items.)
Processing
The program first reads in all of the inventory information from file “Invent.in”, echo printing the information to the output file. The program then prompts the cashier to begin inputting the order for the first customer. This customer’s order is processed, and the receipt is printed to the output file.

After each customer’s order is processed, the program should ask the cashier if another customer is to be processed. If the answer is ‘Y’, the program sets up to process the next customer; if the answer is ‘N’, the program terminates with a friendly message.
Error Checking
The following input errors are possible and should be handled by an exception class:
1. Duplicate in inventory file. Write an error message to the output file and skip the second entry.
2. not in inventory file. Write an error message on the receipt, ignore that product number, and continue with the next item.
3. not in the specified range. Write an error message to the output file, ignore that line, and continue with the next item.
Example
From File “Invent.in”:
11012 gallon-milk 1.99 N
11014 butter 2.59 N
11110 pie-shells 0.99 N
20115 laundry-soap 3.60 T
30005 homestyle-br 0.99 N

From keyboard (one customer):
11110 2
40012 3
20115 1
0

To “Receipts.out” file:
——————————————————
SEP 10, 1998 6:00 pm (* date and time optional *)
Customer 1
pie-shells 2 @ 0.99 1.98
*** item 40012 not in inventory ***
laundry-soap 1 @ 3.60 3.60 TX
Subtotal 5.58
Tax 0.27

Total 5.85
madmik3, thanks for the help. We can use vectors..or basically anything…I tend to have trouble starting the projects but once I get in my head what I am doing I am fine. I think its just because I haven’t had to write enough programs using the things I have learned. I learned a lot of the input from files but never had to write a program using it. I have used output quite a bit though. The problem doesn’t seem that bad..once I understand how to get input to read the file and store the information, once its stored I need to figure out how to get the program to look at the stored information and get it to output in the right order.

I can code everything else fine, and this shouldn’t be that bad either, ill take a look at vectors and see if that will help me.

Best answer:

Your questions are somewhat hard to answer and this is obviously a homework problem. So I won’t give everything away.

First off, working with files from c++ will be a bit tricky for the new programmer. I would first write a few small test programs to ensure that you understand basic file io. IO in c++ is operating system independent. So it’s hard to tell you exactly what to look for because I don’t know what operating system you are working with. But in general it seems that fopen and fscanf and fprintf are the functions I would use to solve the problems listed here. There are numerous sources that show you how to use them.

Secondly, programmers test to “see there functions” differently. To answer the question what functions do you need ask yourself what would I do if I was doing this without a computer. Perhaps you would examine the input, then calculate the output and then report the output. so your functions would be Examine, Calculate, and Report.

Data structures are complicated and it’s hard to tell you what to do because I don’t know what you can use. But I would use a vector from the standard template library. This might be considered cheating for a homework project.

Lastly, break your problem down into small chucks. Solve each of them and them composite the result. Don’t try and do everything at once. Create and test each part independently. Think of it as 5 small projects and not one big one.

good luck and remember this should be kind of fun, if it’s not maybe programming is not for you as it will be a lot more of the same :)

Tags: , ,

Under Forum

1 Comment for C++ data structures help?

  • 1. MichaelInScarborough  |  March 6th, 2008 at 12:25 pm

    Here are the 3 files:
    class implementation is here:
    inventory.h – pastebin.com/fc0a8a9f
    static variable initialization is here:
    inventory.cpp – pastebin.com/f524b2dc7
    Here is the program, using the CInventory class
    pos.cpp – pastebin.com/f212538b0

    You need to have an input file called inventory.dat
    A file called receipt.dat will be created (everytime new, when you restart the program)

    Three input errors are taken care off:
    1. duplicate entry in inventory.dat
    2. quantity less then 1 (0 terminates the program)
    3. input item not found

    receipt.dat could be looking like this:
    Jan 30, 2010 06:56
    Customer 1
    ===================================================

    1 is not in inventory
    1 is not in inventory
    11012 QUANTITY less than 1
    20115 has duplicate inventory #
    gallon-milk 3 @ 1.99 N 5.97
    butter 5 @ 2.59 N 12.95
    general-purp 10 @ 5.99 T 59.90
    laundry-soap 3 @ 3.60 T 10.80
    homestyle-br 2 @ 0.99 N 1.98

    —————————————————
    Sub Total: 91.60
    Taxes : 5.30
    —————————————————
    Total : 96.90
    ===================================================

    Have fun

Leave a Comment for C++ data structures help?

You must be logged in to post a comment.

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories