RE: [Dev-C++] student needs a little help
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-02-16 03:46:50
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Marton
Rusk
Sent: Saturday, February 16, 2002 12:24 AM
To: dev...@li...
Subject: [Dev-C++] student needs a little help
Hello Everyone,
I'm currently a CS Student and need a little help. I have been given the
enclosed programming assignment but I'm not sure how to do it. It seems
like a simple problem to solve but I don't know how to do list let and
from the looks of the problem it will need one. I guess the teacher
things we are supposed to know how to do list already.
Anyhow, I'd like a few pointers on how to do this problem if possible.
Maybe how to do the part of the code where it would require a list and
search.
Any help is appreciated, thanks.
Except of the fact that you can use the ready C++ list in <list> header
file, you can use an array too. In fact i do not see why you shoud use
any container at all.
Marton
Program #2: Grocery Store Checkout (60 points)
Your assignment is to write, run, and test a C++ program, pg2, 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.
A data structure example:
class product
{
unsigned product_number;
std::string description;
unsigned price;
unsigned tax;
public:
product(const unsigned &pn, const std::string &desc, const unsigned &pr,
const unsigned &tx): product_number(pn), description(desc), price(pr),
tax(tx) {}
const unsigned &get_product_number() const { return product_number; }
const std::string &get_desc() const { return description; }
const unsigned &get_price() const { return price; }
const unsigned &get_tax() const { return tax; }
void set_product_number(const unsigned &pr) { product_number=pr; }
void set_desc() { description=desc; }
// ...
};
INPUT
The input for pg2 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:
<product number> <description> <price> <tax>
where <product number> is a five-digit positive (nonzero) integer,
<description> is a string of
at most 12 characters with no embedded blanks, <price> is a real
number, and <tax> 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.
For every element you will do checking to see if the arguments comply
with these rules and then you will throw an exception for everyone it
doesn't. You will create an exception inheritance like this:
class general_exception
{
unsigned exc_id;
public:
general_exception(const unsigned int &id): exc_id(id) {}
virtual operator unsigned() { return exc_id; }
virtual ~general_exception {}
virtual const std::string & message() const=0;
};
class desc_exception: public general_exception
{
std::string msg;
// ...
};
Or something that fits you better.
2. The customer transactions are input from the keyboard, in the
following format:
<product number> <times>
where <product number> is as described above, and <times> is an
integer in the range 1 to 100,
indicating the quantity of this product desired. A zero input for
<product number> 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.)
You will throw exceptions in case of errors.
OUTPUT
The program outputs should be written to a text file called
"receipts.out", which can be printed
out for purposes of determining your grade.
1. The inventory information of invent.dat 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
pg2 first reads in all of the inventory information from file
invent.dat, echo printing the
information to the output file receipts.out. 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 pg2
1. Duplicate <product number> in inventory file. Write an error message
to the output file and skip
the second entry.
2. <Product number> not in inventory file. Write an error message on the
receipt, ignore that product
number, and continue with the next item.
3. <Times> 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
DATA STRUCTURE
The inventory information can be stored in a list of product records.
Assume that the maximum
number of products is 50, for purposes of writing this program. As the
data in the inventory file
is ordered from smallest to largest product number, it is very simple to
insert the product records
into this data structure in order. You can use either a sequential or
binary search to locate a product
number in the inventory.
You should specify this data structure as an ADT, as described in the
chapter; define and implement
a set of operations to encapsulate it.
TEST PLAN
Be sure to include test cases to test your error conditions in your test
plan.
DELIVERABLES
1. A disk of the source code of the program pg2 and all included files.
2. Hard copy of a listing of your implemented test plan.
3. Hard copy of the output file, "receipts.out", produced by running
your program using the input
specified in your test plan.
For sorting and deleted the elements you will place another field in the
class like bool erased; which you will mark as true when you delete a
record, and then you will copy the contents of the file in a temporary
file, sort them there and then copy them back without the logically
deleted records.
Ioannis
* Ioannis Vranos
* Programming pages: <http://www.noicys.d2g.com/>
http://www.noicys.d2g.com
* Alternative URL: <http://run.to/noicys> http://run.to/noicys
|