sales-reporter

1.使用前需要把数据文件放置在exe程序同一文件夹内。
2.数据文件内容可修改,有且仅有8对数据,否则会报错(已预置sales.txt文件,格式可参照修改,第一列为itemNumber,第二列为对应的unitePrice)
3.双击exe运行,根据提示输入数据文件名称,存放结果数据文件名称,salesperson lastname(内置z1-z10),item number,quantity。
4.salesperson lastname不得超出z1-z10,否则报错。
5.程序作用:
<span style="white-space: pre;">	</span>根据销售项目及单价(文件形式),输入相应的销售项目和数量,自动生成每个人的销售报告(文件形式)。
#include<iostream>
#include<string>
#include<fstream>

using namespace std;

enum lastname																		/*声明salesperson的姓名*/
{
	z1,z2,z3,z4,z5,z6,z7,z8,z9,z10
};

void main()
{																					/*提示终止方式*/
	cout << "********************the program is used to generate sales-reporter***********************" << endl;				
	cout << "                                    ------------please press \"enter\" twice to stop" << endl;			    

	ifstream salesFile;
	ofstream outFile;

	string filename;																/*获得输入的文件名*/
	cout << "please enter the filename(attention:don't use space to seperate)" << endl;
	getline(cin, filename, '\n');
	salesFile.open(filename);

	if (!salesFile)																	/*判断文件是否存在*/
	{
		cout << "please correct the file has been set in the same content with the program" << endl;
		return;
	}

	int PN[8], i = 0;																/*读取文件数据*/
	double UP[8];
	while (salesFile)
	{
		salesFile >> PN[i] >> UP[i];
		i++;
	}

	string outFileName;																/*获取输出文件名*/
	cout << "please enter the outFileName(attention:don't use space to seperate)" << endl;
	getline(cin, outFileName, '\n');
	outFile.open(outFileName);

	if (!outFile)																	/*判断文件名是否合法*/
	{
		cout << "please correct the file name is league" << endl;
		return;
	}

	string LN;																		/*读取用户姓名*/
	cout << "please enter the lastname of the salesperson" << endl;
	cin >> LN;

	if (LN != "z1"&& LN != "z2"&& LN != "z3"&& LN != "z4"&& LN != "z5"&& LN != "z6"&& LN != "z7"&& LN != "z8"&& LN != "z9"&& LN != "z10")																	/*判断姓名是否存在*/
	{
		cout << "please correct the name is extence" << endl;
		return;
	}
	outFile << LN << "'s sales reporter" << endl;									/*打印标头*/
	outFile << "itemNum" << '\t' << "quantity" << endl<<'\t';	

	char item1,item2;
	int  qua,item;
	double sum=0;
	int temp = 8;
	do
	{
		cout << "please enter the item number" << endl;								/*接收数据*/
		cin.get();
		item1=cin.get();
		item2 = cin.get();

		if (item1 == '\n')
			break;
		else if (item2 != '\n')
			item = (item1 - '0') * 10 + (item2 - '0');
		else
			item = (item1-'0');

		cout << "please enter the quantity" << endl;
		cin >> qua;

		outFile << item;															/*数据处理*/
		outFile << '\t';
		outFile << qua;
		outFile << endl;
		outFile << '\t';
	
		for (int i = 0; i <8; i++)													/*匹配item*/
		{
			if (item == PN[i])
			{
				temp = i;
				sum += UP[temp]*qua;
				break;
			}
		}

		if (temp == 8)																/*判断输入item是否存在*/
		{
			cout << "please correct the item number" << endl;
			return;
		}

		if (qua<0)																	/*判断输入quantity是否合法*/
		{
			cout << "please correct the qua is league" << endl;
			return;
		}

		temp = 8;
	} while (item != 0);

	outFile << endl;
	outFile << sum << endl;

	salesFile.close();
	outFile.close();
}

你可能感兴趣的:(sales-reporter)