当前位置:   article > 正文

【C++】2023年数学建模国赛C题87万条数据处理(附源码)_2023数学建模c题代码

2023数学建模c题代码


代码只有输出结果使用了C++语法,修改头文件与输出后及为纯C代码

一.设计思路

表格转txt文本文件

第一步,我打算将excel表格的文件转化成.txt的文本文件,方便我们对文件数据的读取。在这里插入图片描述

文件读取

第二步,既然获得了数据的txt文件,那在编程中读取文件信息即可。

//打开文件,只读
	FILE* pf = fopen("test.txt", "r");
	if (pf == NULL)
	{
		printf("打开文件失败\n");
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

用fopen函数打开文件,该函数在库中的声明为FILE * fopen ( const char * filename, const char * mode );
函数作用是打开参数filename中指定其名称的文件,并将其与可在将来的操作中由返回的FILE 指针标识的流相关联。流上允许的操作及其执行方式由 mode 参数定义。
通俗的话说就是,打开第一个参数名的文件,你能对这个文件进行的操作由第二个参数决定,最后函数会返回该文件的FILE*文件指针,其中第二个参数选择如下:

“r” :打开文件进行输入操作。该文件必须存在。
“w” :为输出操作创建一个空文件。如果已存在同名文件,则会丢弃其内容,并将该文件视为新的空文件。
“一” 附加:在文件末尾打开文件进行输出。输出操作始终将数据写入文件末尾,并对其进行扩展。重新定位操作(fseek、fsetpos、rewind)将被忽略。如果文件不存在,则创建该文件。
“r+” 读取/更新:打开文件进行更新(输入和输出)。该文件必须存在。
“w+” 写入/更新:创建一个空文件并打开它进行更新(用于输入和输出)。如果已存在同名文件,则会丢弃其内容,并将该文件视为新的空文件。
“A+” 追加/更新:打开一个文件进行更新(输入和输出),所有输出操作都在文件末尾写入数据。重新定位操作(fseek、fsetpos、rewind)会影响下一个输入操作,但输出操作会将位置移回文件末尾。如果文件不存在,则创建该文件。

整理数据

第三步自然就是文件数据的处理。

typedef struct Data
{
	char Date[20]; //日期
	char Time[20];  //时间
	char Encoding[20];  //编码
	int SalesVolume;  //销量
	char UnitPrice[20];  //单价
	char SalesType[20];  //销售类型
	char DiscountSale[20];  //打折销售
	char SingleCategory[20];  //单品类
	char BroadCategory[20];  //大类
	char WholesalePrice[20];  //批发价格
	char ItemLossRate[20];  //单品损耗率
	char CostPlusPricing[20];  //成本加成定价
}Data;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
for (Data* New = Initdata(); 12 == fscanf(pf, "%s%s%s%lf%s%s%s%s%s%s%s%s", &New->Date, &New->Time, &New->Encoding, &n, &New->UnitPrice, &New->SalesType, &New->DiscountSale, &New->SingleCategory, &New->BroadCategory, &New->WholesalePrice, &New->ItemLossRate, &New->CostPlusPricing);)
  • 1

创建一个存储数据用的结构体用于储存从文件中读取的数据,使用fscanf函数将读取到的数据存到结构体中。
fscanf函数在库中的声明为int fscanf ( FILE * stream, const char * format, … );
函数作用是从流中读取数据,并根据参数格式将其存储到附加参数指向的位置。其他参数应指向格式字符串中相应格式说明符指定的类型的已分配对象。成功后,该函数返回成功填充的参数列表的项数。
通俗的话说就是,读取第一个参数对应的文件数据,读取数据的类型和个数由第二个参数决定,之后写上对应读取数据数量的存放地址。该函数会返回你读取数据的个数。所以在该代码的循环中,一次循环读取12个数据,当读取完所有数据后,fscanf返回值为0,循环结束。

//判断时间段(共10个判断)
		if (New->Date[3] == '0' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 4 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 10)
		{
			//判断大类(共6个判断)
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS1->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS1->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS1->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS1->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS1->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS1->solanacea += New->SalesVolume;
			}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

最后就是处理读取到的数据了,在for循环中用判断语句筛选即可。
该代码则是对一段时间中各大类的销量进行分类,第一层if判断时间段,第二层if判断大类。

遇到的问题

在调试过程中发现,小数会在小数点后17位有2的误差,在87万分数据中可能会放大误差,所以我将读取到的浮点数*100+0.1后在转化为整形,这样可以消除因此产生误差的可能性。在这里插入图片描述

二.程序源码

源.cpp

#pragma warning(disable:4996)
#include<iostream>
#include <iomanip>
#include"definition.h"
using namespace std;

int main()
{
	double n;   //记销量
	//int i = 50;  //测试查看前i个销量数据
	BroadCategory* BC = InitBroadCategory();//大类字符串

	//各时间段各大类销量
	BroadCategorySalesVolume* BCS1 = InitBroadCategorySalesVolume();//20年7到10
	BroadCategorySalesVolume* BCS2 = InitBroadCategorySalesVolume();//    11到12
	BroadCategorySalesVolume* BCS3 = InitBroadCategorySalesVolume();// 21年1到3
	BroadCategorySalesVolume* BCS4 = InitBroadCategorySalesVolume();//    4到10
	BroadCategorySalesVolume* BCS5 = InitBroadCategorySalesVolume();//    11到12
	BroadCategorySalesVolume* BCS6 = InitBroadCategorySalesVolume();// 22年1到3
	BroadCategorySalesVolume* BCS7 = InitBroadCategorySalesVolume();//    4到10
	BroadCategorySalesVolume* BCS8 = InitBroadCategorySalesVolume();//    11到12
	BroadCategorySalesVolume* BCS9 = InitBroadCategorySalesVolume();// 23年1到3
	BroadCategorySalesVolume* BCS10 = InitBroadCategorySalesVolume();//    4到6


	//录入
	FILE* pf = fopen("test.txt", "r");
	if (pf == NULL)
	{
		printf("打开文件失败\n");
	}
	//读取大类名
	fscanf(pf, "%s%s%s%s%s%s", BC->capsicum, BC->anthophyllum, BC->AquaticRhizomes, BC->EdibleMushroom, BC->cauliflower, BC->solanacea);
	//读取数据
	for (Data* New = Initdata(); 12 == fscanf(pf, "%s%s%s%lf%s%s%s%s%s%s%s%s", &New->Date, &New->Time, &New->Encoding, &n, &New->UnitPrice, &New->SalesType, &New->DiscountSale, &New->SingleCategory, &New->BroadCategory, &New->WholesalePrice, &New->ItemLossRate, &New->CostPlusPricing);)
	{
		New->SalesVolume = n * 1000 + 0.1;

		//测试查看前i个销量数据
		/*for (i--; i >= 0; )
		{
			cout << New->SalesVolume << endl;
			break;
		}*/


		//判断时间段(共10个判断)
		if (New->Date[3] == '0' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 4 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 10)
		{
			//判断大类(共6个判断)
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS1->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS1->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS1->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS1->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS1->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS1->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '0' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 11 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 12)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS2->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS2->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS2->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS2->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS2->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS2->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '1' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 1 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 3)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS3->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS3->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS3->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS3->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS3->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS3->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '1' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 4 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 10)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS4->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS4->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS4->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS4->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS4->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS4->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '1' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 11 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 12)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS5->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS5->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS5->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS5->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS5->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS5->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '2' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 1 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 3)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS6->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS6->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS6->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS6->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS6->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS6->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '2' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 4 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 10)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS7->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS7->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS7->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS7->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS7->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS7->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '2' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 11 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 12)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS8->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS8->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS8->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS8->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS8->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS8->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '3' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 1 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 3)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS9->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS9->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS9->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS9->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS9->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS9->solanacea += New->SalesVolume;
			}
		}
		else if (New->Date[3] == '3' && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) >= 4 && ((New->Date[5] - 48) * 10 + New->Date[6] - 48) <= 10)
		{
			if (strcmp(New->BroadCategory, BC->capsicum) == 0)
			{
				BCS10->capsicum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->anthophyllum) == 0)
			{
				BCS10->anthophyllum += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->AquaticRhizomes) == 0)
			{
				BCS10->AquaticRhizomes += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->EdibleMushroom) == 0)
			{
				BCS10->EdibleMushroom += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->cauliflower) == 0)
			{
				BCS10->cauliflower += New->SalesVolume;
			}
			else if (strcmp(New->BroadCategory, BC->solanacea) == 0)
			{
				BCS10->solanacea += New->SalesVolume;
			}
		}
		New = Initdata();
	}

	//输出
	cout << "20年7到10月" << endl << "辣椒类:" /*<< fixed << setprecision(3)*/ << BCS1->capsicum << endl << "花叶类:" << BCS1->anthophyllum << endl << "水生根茎类:" << BCS1->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS1->EdibleMushroom << endl << "花菜类:" << BCS1->cauliflower << endl << "茄类:" << BCS1->solanacea << endl << endl;
	cout << "20年11到21年3月" << endl << "辣椒类:" << BCS2->capsicum + BCS3->capsicum << endl << "花叶类:" << BCS2->anthophyllum + BCS3->anthophyllum << endl << "水生根茎类:" << BCS2->AquaticRhizomes + BCS3->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS2->EdibleMushroom + BCS3->EdibleMushroom << endl << "花菜类:" << BCS2->cauliflower + BCS3->cauliflower << endl << "茄类:" << BCS2->solanacea + BCS3->solanacea << endl << endl;
	/*cout << "21年1到3月" << endl << "辣椒类:" << BCS3->capsicum << endl << "花叶类:" << BCS3->anthophyllum << endl << "水生根茎类:" << BCS3->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS3->EdibleMushroom << endl << "花菜类:" << BCS3->cauliflower << endl << "茄类:" << BCS3->solanacea << endl << endl;*/
	cout << "21年4到10月" << endl << "辣椒类:" << BCS4->capsicum << endl << "花叶类:" << BCS4->anthophyllum << endl << "水生根茎类:" << BCS4->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS4->EdibleMushroom << endl << "花菜类:" << BCS4->cauliflower << endl << "茄类:" << BCS4->solanacea << endl << endl;
	cout << "21年11到22年3月" << endl << "辣椒类:" << BCS5->capsicum + BCS6->capsicum << endl << "花叶类:" << BCS5->anthophyllum + BCS6->anthophyllum << endl << "水生根茎类:" << BCS5->AquaticRhizomes + BCS6->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS5->EdibleMushroom + BCS6->EdibleMushroom << endl << "花菜类:" << BCS5->cauliflower + BCS6->cauliflower << endl << "茄类:" << BCS5->solanacea + BCS6->solanacea << endl << endl;
	/*cout << "22年1到3月" << endl << "辣椒类:" << BCS6->capsicum << endl << "花叶类:" << BCS6->anthophyllum << endl << "水生根茎类:" << BCS6->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS6->EdibleMushroom << endl << "花菜类:" << BCS6->cauliflower << endl << "茄类:" << BCS6->solanacea << endl << endl;*/
	cout << "22年4到10月" << endl << "辣椒类:" << BCS7->capsicum << endl << "花叶类:" << BCS7->anthophyllum << endl << "水生根茎类:" << BCS7->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS7->EdibleMushroom << endl << "花菜类:" << BCS7->cauliflower << endl << "茄类:" << BCS7->solanacea << endl << endl;
	cout << "22年11到23年3月" << endl << "辣椒类:" << BCS8->capsicum + BCS9->capsicum << endl << "花叶类:" << BCS8->anthophyllum + BCS9->anthophyllum << endl << "水生根茎类:" << BCS8->AquaticRhizomes + BCS9->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS8->EdibleMushroom + BCS9->EdibleMushroom << endl << "花菜类:" << BCS8->cauliflower + BCS9->cauliflower << endl << "茄类:" << BCS8->solanacea + BCS9->solanacea << endl << endl;
	/*cout << "23年1到3月" << endl << "辣椒类:" << BCS9->capsicum << endl << "花叶类:" << BCS9->anthophyllum << endl << "水生根茎类:" << BCS9->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS9->EdibleMushroom << endl << "花菜类:" << BCS9->cauliflower << endl << "茄类:" << BCS9->solanacea << endl << endl;*/
	cout << "23年4到6月" << endl << "辣椒类:" << BCS10->capsicum << endl << "花叶类:" << BCS10->anthophyllum << endl << "水生根茎类:" << BCS10->AquaticRhizomes << endl;
	cout << "食用菌:" << BCS10->EdibleMushroom << endl << "花菜类:" << BCS10->cauliflower << endl << "茄类:" << BCS10->solanacea << endl << endl;

	fclose(pf);
	return 0;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347

definiti.h

#pragma once
#include<iostream>
#include<string>
using namespace std;

typedef struct Data
{
	char Date[20]; //日期
	char Time[20];  //时间
	char Encoding[20];  //编码
	int SalesVolume;  //销量
	char UnitPrice[20];  //单价
	char SalesType[20];  //销售类型
	char DiscountSale[20];  //打折销售
	char SingleCategory[20];  //单品类
	char BroadCategory[20];  //大类
	char WholesalePrice[20];  //批发价格
	char ItemLossRate[20];  //单品损耗率
	char CostPlusPricing[20];  //成本加成定价
}Data;

typedef struct BroadCategory
{
	char capsicum[20];//辣椒类
	char anthophyllum[20];//花叶类
	char AquaticRhizomes[20];//水生根茎类
	char EdibleMushroom[20];//食用菌
	char cauliflower[20];//花菜类
	char solanacea[20];//茄类

}BroadCategory;

typedef struct BroadCategorySalesVolume
{
	int capsicum;//辣椒类
	int anthophyllum;//花叶类
	int AquaticRhizomes;//水生根茎类
	int EdibleMushroom;//食用菌
	int cauliflower;//花菜类
	int solanacea;//茄类

}BroadCategorySalesVolume;




//初始化数据
Data* Initdata()
{
	Data* New = (Data*)malloc(sizeof(Data));
	if (New == NULL)
	{
		printf("数据创建失败");
		return NULL;
	}
	New->SalesVolume = 0;
	return New;
}

//初始化大类字符串
BroadCategory* InitBroadCategory()
{
	BroadCategory* New = (BroadCategory*)malloc(sizeof(BroadCategory));
	if (New == NULL)
	{
		printf("数据创建失败");
		return NULL;
	}
	return New;
}

//初始化大类销量
BroadCategorySalesVolume* InitBroadCategorySalesVolume()
{
	BroadCategorySalesVolume* New = (BroadCategorySalesVolume*)malloc(sizeof(BroadCategorySalesVolume));
	if (New == NULL)
	{
		printf("数据创建失败");
		return NULL;
	}
	New->capsicum = 0;//辣椒类
	New->anthophyllum = 0;//花叶类
	New->AquaticRhizomes = 0;//水生根茎类
	New->EdibleMushroom = 0;//食用菌
	New->cauliflower = 0;//花菜类
	New->solanacea = 0;//茄类
	return New;
}







  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/165332
推荐阅读
相关标签
  

闽ICP备14008679号