100分求以下代码: 读文件内容,做逻辑判断
o1n 2008-12-18 04:55:55 本来想自己写的,结果要出差没时间写了。高分求以下程序的代码。谢谢各位啦……
附security.txt 格式:
1234 a Lindsay
1730 a Eugene
1030 c Phil
5844 c Bruce
data.txt的格式:
Code, Item name, Description, Price (Ex GST), GST
0001, Fish hook, Useful for catching fish, 0.5, 1
0110, Metronome, A device for keeping musical time, 49, 1
1234, Basil, Bunch of basil, 2.5, 0
0002, Bread, Essene Sprouted Bread, 5.2, 0
1000, Blah, Not something you'd buy, 12.4, 1
程序需求:
you are now asked to design and create a Point of Sale (POS) system.
The system will start by asking for a 4-digit security code, which must exist in the security file (security.txt). This file also stores the users’ names (so the system can be polite) and admin level.
After the code has been accepted, there will be a menu with the following functionality:
List items for sale - this gives the user the choice of listing all items or only items within a certain price range.
*Add item - for adding the details for a new item and storing it in the data file and memory.
Purchase items - for POS processing; customers buy one or more items (the clerk enters the codes) and the system presents a ‘docket’ with the total price and other details.
Logout - this option allows a new clerk to login, entering a new security code.
Quit
*The Add item functionality is only available to administrators. Administrators are identified by the ‘a’ character after their code in the security file.
You are provided with sample security and data files, which the system must use (no other file format).
You are also provided with a working executable, so you can test the program to see how it should run.
See the sample output below (and executable file) for more details of how the program should work.
Your program should format all currency amounts with two decimal places, e.g. $450.00.
You should check the login code is exactly 4 numeric characters, as shown in the sample.
When adding items, you should check for valid input: item codes must be 4 numeric characters and must not already exist, item names and descriptions can’t be blank, item prices can’t be $0 or less, GST must be 1 or 0.
You are to handle file errors with the following error messages: if a file fails to open for reading, display “Error opening file!”, or writing, display “Error writing to file!”.
You can assume that the data file will have a maximum of 100 entries and that customers will purchase no more than 20 items per transaction.
You only need to load the data file into memory once, at the start of the program. You should use an appropriate array of structs for this. The security file should not be loaded into memory.
Your output formatting should match the samples provided. Use these to test your work. The sample output and exe form part of the specification. Your program should match as exactly as possible.
You should create functions as appropriate (using logical function design). E.g. if you need to display the products when listing them and also when purchasing them, you might use a function for this.
You should write good code using the principles taught in class, including things like choosing appropriate data types, use of constants, variable naming conventions, formatting and good commenting. Try not to repeat any mistakes you made in your first assignment.
Sample Output
Run the executable file for more examples of how your system should respond (e.g. if it doesn’t check for invalid characters in the price, then you don’t have to).
Welcome to the CP1200 POS System
Created by Student Name
Please enter your security code: 5044
Security code not found!
Please enter your security code: 50455
Invalid length security code.
Please enter your security code: '123
Invalid character in security code.
Please enter your security code: 5844
Bruce, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
1
List (a)ll, or only within price (r)ange? a
0001 - Fish hook (Useful for catching fish): $0.50*
0110 - Metronome (A device for keeping musical time): $49.00*
1234 - Basil (Bunch of basil): $2.50
Bruce, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
2
You need to be an administrator to add items.
Bruce, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
4
Goodbye, Bruce
Please enter your security code: 1234
Lindsay, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
2
Please enter item details:
Code: 0001
Item code 0001 already exists!
Code: 0002
Name: Bread
Descr:
Description can not be blank!
Descr: Essene Sprouted Bread
Price: 5.20
GST(1/0): 8
GST must be 0 or 1!
GST(1/0): 0
Bread added.
Lindsay, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
1
List (a)ll, or only within price (r)ange? r
Lowest price: $-2
Lowest price must be $0 or more!
Lowest price: $0
Highest price: $0
Highest price must be greater than lowest price!
Highest price: $6
0001 - Fish hook (Useful for catching fish): $0.50*
1234 - Basil (Bunch of basil): $2.50
0002 - Bread (Essene Sprouted Bread): $5.20
Lindsay, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
3
Enter code of item to buy (-1 to finish): 0001
Enter code of item to buy: 0001
Enter code of item to buy: 0003
Invalid item code!
Enter code of item to buy: 0002
Enter code of item to buy: -1
0001 - Fish hook (Useful for catching fish): $0.50*
0001 - Fish hook (Useful for catching fish): $0.50*
0002 - Bread (Essene Sprouted Bread): $5.20
3 items.
Total cost: $6.30
Including GST of: $0.10
Lindsay, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
6
Invalid option!
Lindsay, please choose an option:
1. List items for sale
2. *Add item
3. Purchase items
4. Logout
5. Quit
5
Goodbye, Lindsay