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


...全文
170 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
o1n 2008-12-19
  • 打赏
  • 举报
回复
自己搞了下,搞完了。
谢谢各位捧场啦。
Leejun527 2008-12-18
  • 打赏
  • 举报
回复
jf
就呆在云上 2008-12-18
  • 打赏
  • 举报
回复

把分加到200以上再来
toadzw 2008-12-18
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
#include <map>
using namespace std;

class user_info
{
public:
string name;
string curity_code;
int purview;
};

class item
{
string Code;
string Item_name;
string Description;
float Price;
int GST;
};

typedef map<string, item> Items;

int Login(user_info& user)
{
return 0;
}


int show_inter_face(user_info& user)
{
cout << user.name << ", please choose an option:" << endl;

cout << "1. List items for sale " << endl;

cout << "2. *Add item " << endl;

cout << "3. Purchase items " << endl;

cout << "4. Logout " << endl;

cout << "5. Quit " << endl;

return 0;
}

int List_item()
{
return 0;
}

int Add_item()
{
return 0;
}

int Purchase_item()
{
return 0;
}

int transfer(user_info& user)
{
char input;
int error_flag = 0;

cin >> input;

do
{
switch(input)
{
case '1': break;
case '2': break;
case '3': break;
case '4':
case '5': cout << "Goodbye, " << user.name << endl; break;
default: cout << "Invalid option!" << endl; error_flag = 1; break;
}

} while (error_flag);


return input;
}

int main(int argc, char argv[])
{
user_info user;

cout << "Welcome to the CP1200 POS System " << endl;
cout << "Created by Student Name " << endl;

Login(user);

do
{
show_inter_face(user);
char ret = transfer(user);

if (ret == '4')
{
Login(user);
}
else if (ret == '5')
{
break;
}

}while(1);

return 0;
}

kingstarer 2008-12-18
  • 打赏
  • 举报
回复
晕,写了半天才发现是一个作业贴(Created by Student Name)

谁有兴趣接着写下去吧~

#include <iostream>
#include <string>
#include <map>
using namespace std;

class user_info
{
public:
string name;
string curity_code;
int purview;
};

class item
{
string Code;
string Item_name;
string Description;
float Price;
int GST;
};

typedef map<string, item> Items;

int Login(user_info& user)
{
return 0;
}


int show_inter_face(user_info& user)
{
cout << user.name << ", please choose an option:" << endl;

cout << "1. List items for sale " << endl;

cout << "2. *Add item " << endl;

cout << "3. Purchase items " << endl;

cout << "4. Logout " << endl;

cout << "5. Quit " << endl;

return 0;
}

int List_item()
{
return 0;
}

int Add_item()
{
return 0;
}

int Purchase_item()
{
return 0;
}

int transfer(user_info& user)
{
char input;
int error_flag = 0;

cin >> input;

do
{
switch(input)
{
case '1': break;
case '2': break;
case '3': break;
case '4':
case '5': cout << "Goodbye, " << user.name << endl; break;
default: cout << "Invalid option!" << endl; error_flag = 1; break;
}

} while (error_flag);


return input;
}

int main(int argc, char argv[])
{
user_info user;

cout << "Welcome to the CP1200 POS System " << endl;
cout << "Created by Student Name " << endl;

Login(user);

do
{
show_inter_face(user);
char ret = transfer(user);

if (ret == '4')
{
Login(user);
}
else if (ret == '5')
{
break;
}

}while(1);

return 0;
}
帅得不敢出门 2008-12-18
  • 打赏
  • 举报
回复
up
bitwwzhang130 2008-12-18
  • 打赏
  • 举报
回复
这个应该放到项目交易里去
  • 打赏
  • 举报
回复
zhuxueling 2008-12-18
  • 打赏
  • 举报
回复
RMB....
SearchLife 2008-12-18
  • 打赏
  • 举报
回复
up
kampan 2008-12-18
  • 打赏
  • 举报
回复
楼主可以,我帮你顶吧!

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧