数据挖掘实验二(WIndows下CLion调用WSL环境编译)如果在MINGW或者VIsualStudio环境下可能不能直接运行需要修改很多小东西
代码预览
运行结果
写在这里了
全部代码
#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<unistd.h>
#include<iomanip>
using namespace std;
class Sales
{
public:
string serial;
int market{};
string date;
int sn{};
int id{};
float num{};
float price{};
};
class cube_txt{
public:
double ware_10010;
double ware_10020;
double ware_10030;
double ware_10088;
double ware_Sum_InOneDay;
};
string current_working_directory()
{
char *path;
path = get_current_dir_name();
string Path = path;
return Path;
}
void construct_Cube();
ifstream get_infile(string path_from);
bool isConstructedAll();
void queryInOperation();
void queryInCube();
void queryInCube_M(string market);
void queryInCube_S(string species);
void queryInCube_D(string date);
void queryInCube_MD(string market,string date);
void queryInCube_MS(string market,string species);
void queryInCube_DS(string date,string species);
void queryInCube_MDS(string market,string date,string species);
int main()
{
int number = 1;
while(number) {
cout << "******************************选择操作**********************************" << endl;
cout << "**************************construct the cube***************************" << endl;
cout << "**************************query from cube******************************" << endl;
cout <<"********************************exit************************************" << endl;
string instruction;
getline(cin,instruction);
if(instruction == "construct the cube"){
construct_Cube();
} else if(instruction == "query from cube"){
bool symbol = false;
symbol = isConstructedAll();
if(!symbol){
cout << "三个Cube.txt未全部构造完,请继续执行construct the cube" << endl;
}
else {
queryInOperation();
}
}else if(instruction == "exit"){
break;
}
}
return 0;
}
void queryInOperation(){
string query_string_first;
{
cout << "Now select the first parameter of query Or Now query" << endl;
cout << "1、Select the market,please input: 1019、1020、1021" << endl;
cout << "2、Select the date,please input: 13、14、15、16、17、18、19" << endl;
cout << "3、Select the species,please input: 10010、10020、10030、10088" << endl;
cout << "4、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "5、Give Up And Exit please input: exit" << endl;
}
getline(cin,query_string_first);
if(query_string_first == "Now query"){
queryInCube();
}else if(query_string_first == "1019" || query_string_first == "1020" || query_string_first == "1021"){
string query_string_M;
{
cout << "Now select the second parameter of query Or Now query" << endl;
cout << "1、Select the date: 13、14、15、16、17、18、19" << endl;
cout << "2、Select the species,please input: 10010、10020、10030、10088" << endl;
cout << "3、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "4、Give Up And Exit please input: exit" << endl;
}
getline(cin,query_string_M);
if(query_string_M == "Now query") {
queryInCube_M(query_string_first);
}
else if(query_string_M == "13" || query_string_M == "14" || query_string_M == "15" || query_string_M == "16" || query_string_M == "17" || query_string_M == "18" || query_string_M == "19"){
{
cout << "Now select the third parameter of query Or Now query" << endl;
cout << "1、Select the species: 10010、10020、10030、10088" << endl;
cout << "2、Not select, Based on the Current situation And Begin query : Now query" << endl;
cout << "3、Give Up And Exit please input: exit" << endl;
}
string query_string_MD;
getline(cin,query_string_MD);
if(query_string_MD == "Now query"){
queryInCube_MD(query_string_first,query_string_M);
}
else if(query_string_MD == "10010" || query_string_MD == "10020" || query_string_MD == "10030" || query_string_MD == "10088"){
{
cout << "1、All parameters are selected, Now query ?" << endl;
cout << "2、Give Up And Exit please input: exit" << endl;
}
string query_string_end;
getline(cin,query_string_end);
if(query_string_end == "Now query"){
queryInCube_MDS(query_string_first,query_string_M,query_string_MD);
}
else if(query_string_end == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_MD == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_M == "10010" || query_string_M == "10020" || query_string_M == "10030" || query_string_M == "10088"){
{
cout << "Now select the third parameter of query Or Now query" << endl;
cout << "1、Select the date,please input: 13、14、15、16、17、18、19" << endl;
cout << "2、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "3、Give Up And Exit please input: exit" << endl;
}
string query_string_MD;
getline(cin,query_string_MD);
if(query_string_MD == "Now query"){
queryInCube_MS(query_string_first,query_string_M);
}
else if(query_string_MD == "13" || query_string_MD == "14" || query_string_MD == "15" || query_string_MD == "16" || query_string_MD == "17" || query_string_MD == "18" || query_string_MD == "19"){
{
cout << "1、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "2、Give Up And Exit please input: exit" << endl;
}
string query_string_end;
getline(cin,query_string_end);
if(query_string_end == "Now query"){
queryInCube_MDS(query_string_first,query_string_MD,query_string_M);
}
else if(query_string_end == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_MD == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
}else if(query_string_first == "13" || query_string_first == "14" || query_string_first == "15" || query_string_first == "16" ||query_string_first == "17" || query_string_first == "18" || query_string_first == "19" ) {
{
cout << "Now select the second parameter of query Or Now query" << endl;
cout << "1、Select the market,please input: 1019、1020、1021" << endl;
cout << "2、Select the species,please input: 10010、10020、10030、10088" << endl;
cout << "3、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "4、Give Up And Exit please input: exit" << endl;
}
string query_string_D;
getline(cin,query_string_D);
if(query_string_D == "Now query"){
queryInCube_D(query_string_first);
}
else if(query_string_D == "1019" || query_string_D == "1020" || query_string_D == "1021") {
{
cout << "Now select the third parameter of query Or Now query" << endl;
cout << "1、Select the species,please input: 10010、10020、10030、10088" << endl;
cout << "2、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "3、Give Up And Exit please input: exit" << endl;
}
string query_string_DM;
getline(cin,query_string_DM);
if(query_string_DM == "Now query"){
queryInCube_MD(query_string_D,query_string_first);
}
else if(query_string_DM == "10010" || query_string_DM == "10020" || query_string_DM == "10030" || query_string_DM == "10088"){
{
cout << "1、All parameters are selected, Now query ?" << endl;
cout << "2、Give Up And Exit please input: exit" << endl;
}
string query_string_end;
getline(cin,query_string_end);
if(query_string_end == "Now query"){
queryInCube_MDS(query_string_D,query_string_first,query_string_DM);
}
else if(query_string_end == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_DM == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_D == "10010" || query_string_D == "10020" || query_string_D == "10030" || query_string_D == "10088"){
{
cout << "Now select the third parameter of query Or Now query" << endl;
cout << "1、Select the market,please input: 1019、1020、1021" << endl;
cout << "2、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "3、Give Up And Exit please input: exit" << endl;
}
string query_string_DS;
getline(cin,query_string_DS);
if(query_string_DS == "Now query"){
queryInCube_DS(query_string_first,query_string_D);
}
else if(query_string_DS == "1019" || query_string_DS == "1020" || query_string_DS == "1021"){
{
cout << "1、All parameters are selected, Now query ?" << endl;
cout << "2、Give Up And Exit please input: exit" << endl;
}
string query_string_end;
getline(cin,query_string_end);
if(query_string_end == "Now query"){
queryInCube_MDS(query_string_DS,query_string_first,query_string_D);
}
if(query_string_end == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_DS == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_D == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}else if(query_string_first == "10010" || query_string_first == "10020" || query_string_first == "10030" || query_string_first == "10088"){
{
cout << "Now select the second parameter of query Or Now query" << endl;
cout << "1、Select the market,please input: 1019、1020、1021" << endl;
cout << "2、Select the date,please input: 13、14、15、16、17、18、19" << endl;
cout << "3、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "4、Give Up And Exit please input: exit" << endl;
}
string query_string_S;
getline(cin,query_string_S);
if(query_string_S == "Now query"){
queryInCube_S(query_string_first);
}
else if(query_string_S == "1019" || query_string_S == "1020" || query_string_S == "1021"){
{
cout << "Now select the third parameter of query Or Now query" << endl;
cout << "1、Select the date,please input: 13、14、15、16、17、18、19" << endl;
cout << "2、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "3、Give Up And Exit please input: exit" << endl;
}
string query_string_SM;
getline(cin,query_string_SM);
if(query_string_SM == "Now query"){
queryInCube_MS(query_string_S,query_string_first);
}
else if(query_string_SM == "13" || query_string_SM == "14" || query_string_SM == "15" || query_string_SM == "16" || query_string_SM == "17" || query_string_SM == "18" || query_string_SM == "19"){
{
cout << "1、All parameters are selected, Now query ?" << endl;
cout << "2、Give Up And Exit please input: exit" << endl;
}
string query_string_end;
getline(cin,query_string_end);
if(query_string_end == "Now query"){
queryInCube_MDS(query_string_S,query_string_SM,query_string_first);
}
if(query_string_end == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_SM == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_S == "13" || query_string_S == "14" || query_string_S == "15" || query_string_S == "16" || query_string_S == "17" || query_string_S == "18" || query_string_S == "19"){
{
cout << "Now select the third parameter of query Or Now query" << endl;
cout << "1、Select the market,please input: 1019、1020、1021" << endl;
cout << "2、Not select, Based on the Current situation And Begin query please input: Now query" << endl;
cout << "3、Give Up And Exit please input: exit" << endl;
}
string query_string_SD;
getline(cin,query_string_SD);
if(query_string_SD == "Now query"){
queryInCube_DS(query_string_S,query_string_first);
}
if(query_string_SD == "1019" || query_string_SD == "1020" || query_string_SD == "1021"){
{
cout << "1、All parameters are selected, Now query ?" << endl;
cout << "2、Give Up And Exit please input: exit" << endl;
}
string query_string_end;
getline(cin,query_string_end);
if(query_string_end == "Now query"){
queryInCube_MDS(query_string_SD,query_string_S,query_string_first);
}
if(query_string_end == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
if(query_string_SD == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}
else if(query_string_S == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
}else if(query_string_first == "exit"){
cout << "Now exit from the queryInOperation()" << endl;
return;
}
else {
cout << "输入非法!!!退出查询" << endl;
}
}
bool isConstructedAll(){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string from_txt_1019 = "cube_1019.txt";
string from_txt_1020 = "cube_1020.txt";
string from_txt_1021 = "cube_1021.txt";
string path_from_1019 = path_first + from_txt_1019;
string path_from_1020 = path_first + from_txt_1020;
string path_from_1021 = path_first + from_txt_1021;
ifstream infile_1019 = get_infile(path_from_1019);
ifstream infile_1020 = get_infile(path_from_1020);
ifstream infile_1021 = get_infile(path_from_1021);
string head_txt[4]={};
if(!infile_1019.eof()){
infile_1019 >> head_txt[0];
}
if(!infile_1020.eof()){
infile_1020 >> head_txt[1];
}
if(!infile_1021.eof()){
infile_1021 >> head_txt[2];
}
if(head_txt[0].empty() || head_txt[1].empty() || head_txt[2].empty()){
return false;
}
else{
return true;
}
}
ifstream get_infile(string path_from){
ifstream infile(path_from, ios::in);
if (infile.fail()) {
cout << "error open!" << path_from << "打开发生错误,无法正常打开" << endl;
exit(1);
}
else{
return infile;
}
}
void queryInCube(){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string from_txt_1019 = "cube_1019.txt";
string from_txt_1020 = "cube_1020.txt";
string from_txt_1021 = "cube_1021.txt";
string path_from_1019 = path_first + from_txt_1019;
string path_from_1020 = path_first + from_txt_1020;
string path_from_1021 = path_first + from_txt_1021;
ifstream infile_1019 = get_infile(path_from_1019);
ifstream infile_1020 = get_infile(path_from_1020);
ifstream infile_1021 = get_infile(path_from_1021);
cube_txt cubeTxt_1019[32];
cube_txt cubeTxt_1020[32];
cube_txt cubeTxt_1021[32];
int cubeTxt_num_1019 = 0;
int cubeTxt_num_1020 = 0;
int cubeTxt_num_1021 = 0;
string head_txt[4];
if(infile_1019.fail()){
cout << from_txt_1019 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1020.fail()){
cout << from_txt_1020 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1021.fail()){
cout << from_txt_1021 << "文件打开失败,查询失败" << endl;
return;
}
if(!infile_1019.eof()){
infile_1019 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while(!infile_1019.eof()){
infile_1019 >> cubeTxt_1019[cubeTxt_num_1019].ware_10010 >> cubeTxt_1019[cubeTxt_num_1019].ware_10020 >>
cubeTxt_1019[cubeTxt_num_1019].ware_10030 >> cubeTxt_1019[cubeTxt_num_1019].ware_10088 >>
cubeTxt_1019[cubeTxt_num_1019].ware_Sum_InOneDay;
cubeTxt_num_1019++;
}
if(!infile_1020.eof()){
infile_1020 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while(!infile_1020.eof()){
infile_1020 >> cubeTxt_1020[cubeTxt_num_1020].ware_10010 >> cubeTxt_1020[cubeTxt_num_1020].ware_10020 >>
cubeTxt_1020[cubeTxt_num_1020].ware_10030 >> cubeTxt_1020[cubeTxt_num_1020].ware_10088 >>
cubeTxt_1020[cubeTxt_num_1020].ware_Sum_InOneDay;
cubeTxt_num_1020++;
}
if(!infile_1021.eof()){
infile_1021 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while(!infile_1021.eof()){
infile_1021 >> cubeTxt_1021[cubeTxt_num_1021].ware_10010 >> cubeTxt_1021[cubeTxt_num_1021].ware_10020 >>
cubeTxt_1021[cubeTxt_num_1021].ware_10030 >> cubeTxt_1021[cubeTxt_num_1021].ware_10088 >>
cubeTxt_1021[cubeTxt_num_1021].ware_Sum_InOneDay;
cubeTxt_num_1021++;
}
cubeTxt_num_1019 = cubeTxt_num_1019 - 2;
cubeTxt_num_1020 = cubeTxt_num_1020 - 2;
cubeTxt_num_1021 = cubeTxt_num_1021 - 2;
double total_All;
total_All = cubeTxt_1019[cubeTxt_num_1019].ware_Sum_InOneDay + cubeTxt_1020[cubeTxt_num_1020].ware_Sum_InOneDay
+ cubeTxt_1021[cubeTxt_num_1021].ware_Sum_InOneDay;
cout << "1019、1020、1021三家店,在13-19七天的总销售额为:" << fixed << setprecision(2) << total_All << endl;
}
void queryInCube_M(string market){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string path_from = "cube_" + market + ".txt";
ifstream infile = get_infile(path_from);
cube_txt cubeTxt[32];
int cubeTxt_num = 0;
string head_txt[4];
if(infile.fail()){
cout << market << "文件打开失败,查询失败" << endl;
return;
}
if(!infile.eof()){
infile >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while(!infile.eof()){
infile >> cubeTxt[cubeTxt_num].ware_10010 >> cubeTxt[cubeTxt_num].ware_10020 >>
cubeTxt[cubeTxt_num].ware_10030 >> cubeTxt[cubeTxt_num].ware_10088 >>cubeTxt[cubeTxt_num].ware_Sum_InOneDay;
cubeTxt_num++;
}
cubeTxt_num = cubeTxt_num - 2;
double total = cubeTxt[cubeTxt_num].ware_Sum_InOneDay;
cout << market << "这家店13-19七天里商品10010、10020、10030、10088的销售总额为:" << total << endl;
}
void queryInCube_S(string species){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string from_txt_1019 = "cube_1019.txt";
string from_txt_1020 = "cube_1020.txt";
string from_txt_1021 = "cube_1021.txt";
string path_from_1019 = path_first + from_txt_1019;
string path_from_1020 = path_first + from_txt_1020;
string path_from_1021 = path_first + from_txt_1021;
ifstream infile_1019 = get_infile(path_from_1019);
ifstream infile_1020 = get_infile(path_from_1020);
ifstream infile_1021 = get_infile(path_from_1021);
cube_txt cubeTxt_1019[32];
cube_txt cubeTxt_1020[32];
cube_txt cubeTxt_1021[32];
int cubeTxt_num_1019 = 0;
int cubeTxt_num_1020 = 0;
int cubeTxt_num_1021 = 0;
string head_txt[4];
if(infile_1019.fail()){
cout << from_txt_1019 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1020.fail()){
cout << from_txt_1020 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1021.fail()){
cout << from_txt_1021 << "文件打开失败,查询失败" << endl;
return;
}
if (!infile_1019.eof()) {
infile_1019 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1019.eof()) {
infile_1019 >> cubeTxt_1019[cubeTxt_num_1019].ware_10010 >> cubeTxt_1019[cubeTxt_num_1019].ware_10020 >>
cubeTxt_1019[cubeTxt_num_1019].ware_10030 >> cubeTxt_1019[cubeTxt_num_1019].ware_10088 >>
cubeTxt_1019[cubeTxt_num_1019].ware_Sum_InOneDay;
cubeTxt_num_1019++;
}
if (!infile_1020.eof()) {
infile_1020 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1020.eof()) {
infile_1020 >> cubeTxt_1020[cubeTxt_num_1020].ware_10010 >> cubeTxt_1020[cubeTxt_num_1020].ware_10020 >>
cubeTxt_1020[cubeTxt_num_1020].ware_10030 >> cubeTxt_1020[cubeTxt_num_1020].ware_10088 >>
cubeTxt_1020[cubeTxt_num_1020].ware_Sum_InOneDay;
cubeTxt_num_1020++;
}
if (!infile_1021.eof()) {
infile_1021 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1021.eof()) {
infile_1021 >> cubeTxt_1021[cubeTxt_num_1021].ware_10010 >> cubeTxt_1021[cubeTxt_num_1021].ware_10020 >>
cubeTxt_1021[cubeTxt_num_1021].ware_10030 >> cubeTxt_1021[cubeTxt_num_1021].ware_10088 >>
cubeTxt_1021[cubeTxt_num_1021].ware_Sum_InOneDay;
cubeTxt_num_1021++;
}
cubeTxt_num_1019 = cubeTxt_num_1019 - 2;
cubeTxt_num_1020 = cubeTxt_num_1020 - 2;
cubeTxt_num_1021 = cubeTxt_num_1021 - 2;
double total = 0;
if(species == "10010"){
total = cubeTxt_1019[cubeTxt_num_1019].ware_10010 + cubeTxt_1020[cubeTxt_num_1020].ware_10010 + cubeTxt_1021[cubeTxt_num_1021].ware_10010;
cout << "商品:" << species << "在1019、1020、1021三家店,从13-19七天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10020"){
total = cubeTxt_1019[cubeTxt_num_1019].ware_10020 + cubeTxt_1020[cubeTxt_num_1020].ware_10020 + cubeTxt_1021[cubeTxt_num_1021].ware_10020;
cout << "商品:" << species << "在1019、1020、1021三家店,从13-19七天的销售总额为:" << fixed << setprecision(2) << total << endl;
}
else if(species == "10030"){
total = cubeTxt_1019[cubeTxt_num_1019].ware_10030 + cubeTxt_1020[cubeTxt_num_1020].ware_10030 + cubeTxt_1021[cubeTxt_num_1021].ware_10030;
cout << "商品:" << species << "在1019、1020、1021三家店,从13-19七天的销售总额为:" << fixed << setprecision(2) << total << endl;
}
else if(species == "10088"){
total = cubeTxt_1019[cubeTxt_num_1019].ware_10088 + cubeTxt_1020[cubeTxt_num_1020].ware_10088 + cubeTxt_1021[cubeTxt_num_1021].ware_10088;
cout << "商品:" << species << "在1019、1020、1021三家店,从13-19七天的销售总额为:" << fixed << setprecision(2) << total << endl;
}
else{
cout << "species输入非法" << endl;
}
}
void queryInCube_D(string date){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string from_txt_1019 = "cube_1019.txt";
string from_txt_1020 = "cube_1020.txt";
string from_txt_1021 = "cube_1021.txt";
string path_from_1019 = path_first + from_txt_1019;
string path_from_1020 = path_first + from_txt_1020;
string path_from_1021 = path_first + from_txt_1021;
ifstream infile_1019 = get_infile(path_from_1019);
ifstream infile_1020 = get_infile(path_from_1020);
ifstream infile_1021 = get_infile(path_from_1021);
cube_txt cubeTxt_1019[32];
cube_txt cubeTxt_1020[32];
cube_txt cubeTxt_1021[32];
int cubeTxt_num_1019 = 0;
int cubeTxt_num_1020 = 0;
int cubeTxt_num_1021 = 0;
string head_txt[4];
if(infile_1019.fail()){
cout << from_txt_1019 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1020.fail()){
cout << from_txt_1020 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1021.fail()){
cout << from_txt_1021 << "文件打开失败,查询失败" << endl;
return;
}
if (!infile_1019.eof()) {
infile_1019 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1019.eof()) {
infile_1019 >> cubeTxt_1019[cubeTxt_num_1019].ware_10010 >> cubeTxt_1019[cubeTxt_num_1019].ware_10020 >>
cubeTxt_1019[cubeTxt_num_1019].ware_10030 >> cubeTxt_1019[cubeTxt_num_1019].ware_10088 >>
cubeTxt_1019[cubeTxt_num_1019].ware_Sum_InOneDay;
cubeTxt_num_1019++;
}
if (!infile_1020.eof()) {
infile_1020 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1020.eof()) {
infile_1020 >> cubeTxt_1020[cubeTxt_num_1020].ware_10010 >> cubeTxt_1020[cubeTxt_num_1020].ware_10020 >>
cubeTxt_1020[cubeTxt_num_1020].ware_10030 >> cubeTxt_1020[cubeTxt_num_1020].ware_10088 >>
cubeTxt_1020[cubeTxt_num_1020].ware_Sum_InOneDay;
cubeTxt_num_1020++;
}
if (!infile_1021.eof()) {
infile_1021 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1021.eof()) {
infile_1021 >> cubeTxt_1021[cubeTxt_num_1021].ware_10010 >> cubeTxt_1021[cubeTxt_num_1021].ware_10020 >>
cubeTxt_1021[cubeTxt_num_1021].ware_10030 >> cubeTxt_1021[cubeTxt_num_1021].ware_10088 >>
cubeTxt_1021[cubeTxt_num_1021].ware_Sum_InOneDay;
cubeTxt_num_1021++;
}
cubeTxt_num_1019 = cubeTxt_num_1019 - 2;
cubeTxt_num_1020 = cubeTxt_num_1020 - 2;
cubeTxt_num_1021 = cubeTxt_num_1021 - 2;
double total = 0;
if(!date.empty() && date.size()==2) {
char weekday = date[1];
int week_day_num = (int)(weekday - '0');
if(week_day_num >=3 && week_day_num <=9){
week_day_num = week_day_num - 3;
total = cubeTxt_1019[week_day_num].ware_Sum_InOneDay + cubeTxt_1020[week_day_num].ware_Sum_InOneDay + cubeTxt_1021[week_day_num].ware_Sum_InOneDay;
cout << "在" << date << "这天,1019、1020、1021三家店的10010、10020、10030、10088四种商品的销售总额为:" << fixed << setprecision(2) << total << endl;
}
else{
cout << "date输入非法" << endl;
}
}
else{
cout << "date输入非法" << endl;
}
}
void queryInCube_MD(string market,string date){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string path_from = "cube_" + market + ".txt";
ifstream infile = get_infile(path_from);
if(infile.fail()){
cout << market << "文件打开失败,查询失败" << endl;
return;
}
cube_txt cubeTxt[32];
int cubeTxt_num = 0;
string head_txt[4];
if (!infile.eof()) {
infile >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile.eof()) {
infile >> cubeTxt[cubeTxt_num].ware_10010 >> cubeTxt[cubeTxt_num].ware_10020 >>
cubeTxt[cubeTxt_num].ware_10030 >> cubeTxt[cubeTxt_num].ware_10088
>> cubeTxt[cubeTxt_num].ware_Sum_InOneDay;
cubeTxt_num++;
}
cubeTxt_num = cubeTxt_num - 2;
double total = 0;
if(!date.empty() && date.size()==2) {
char weekday = date[1];
int week_day_num = (int)(weekday - '0');
if(week_day_num >=3 && week_day_num <=9){
week_day_num = week_day_num - 3;
total = cubeTxt[week_day_num].ware_Sum_InOneDay;
cout << "在" << date << "这天," << market <<"这家店的10010、10020、10030、10088四种商品的销售总额为:" << fixed << setprecision(2) << total << endl;
}
else{
cout << "date输入非法" << endl;
}
}
else{
cout << "date输入非法" << endl;
}
}
void queryInCube_MS(string market,string species){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string path_from = "cube_" + market + ".txt";
ifstream infile = get_infile(path_from);
if(infile.fail()){
cout << market << "文件打开失败,查询失败" << endl;
return;
}
cube_txt cubeTxt[32];
int cubeTxt_num = 0;
string head_txt[4];
if (!infile.eof()) {
infile >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile.eof()) {
infile >> cubeTxt[cubeTxt_num].ware_10010 >> cubeTxt[cubeTxt_num].ware_10020 >>
cubeTxt[cubeTxt_num].ware_10030 >> cubeTxt[cubeTxt_num].ware_10088
>> cubeTxt[cubeTxt_num].ware_Sum_InOneDay;
cubeTxt_num++;
}
cubeTxt_num = cubeTxt_num - 2;
double total = 0;
if(species == "10010"){
total = cubeTxt[cubeTxt_num].ware_10010;
cout << "商品:" << species << "在" << market <<"这家店,从13-19七天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10020"){
total = cubeTxt[cubeTxt_num].ware_10020;
cout << "商品:" << species << "在" << market <<"这家店,从13-19七天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10030"){
total = cubeTxt[cubeTxt_num].ware_10030;
cout << "商品:" << species << "在" << market <<"这家店,从13-19七天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10088"){
total = cubeTxt[cubeTxt_num].ware_10088;
cout << "商品:" << species << "在" << market <<"这家店,从13-19七天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else{
cout << "species输入非法" << endl;
return;
}
}
void queryInCube_DS(string date,string species){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string from_txt_1019 = "cube_1019.txt";
string from_txt_1020 = "cube_1020.txt";
string from_txt_1021 = "cube_1021.txt";
string path_from_1019 = path_first + from_txt_1019;
string path_from_1020 = path_first + from_txt_1020;
string path_from_1021 = path_first + from_txt_1021;
ifstream infile_1019 = get_infile(path_from_1019);
ifstream infile_1020 = get_infile(path_from_1020);
ifstream infile_1021 = get_infile(path_from_1021);
cube_txt cubeTxt_1019[32];
cube_txt cubeTxt_1020[32];
cube_txt cubeTxt_1021[32];
int cubeTxt_num_1019 = 0;
int cubeTxt_num_1020 = 0;
int cubeTxt_num_1021 = 0;
string head_txt[4];
if(infile_1019.fail()){
cout << from_txt_1019 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1020.fail()){
cout << from_txt_1020 << "文件打开失败,查询失败" << endl;
return;
}
if(infile_1021.fail()){
cout << from_txt_1021 << "文件打开失败,查询失败" << endl;
return;
}
if (!infile_1019.eof()) {
infile_1019 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1019.eof()) {
infile_1019 >> cubeTxt_1019[cubeTxt_num_1019].ware_10010 >> cubeTxt_1019[cubeTxt_num_1019].ware_10020 >>
cubeTxt_1019[cubeTxt_num_1019].ware_10030 >> cubeTxt_1019[cubeTxt_num_1019].ware_10088 >>
cubeTxt_1019[cubeTxt_num_1019].ware_Sum_InOneDay;
cubeTxt_num_1019++;
}
if (!infile_1020.eof()) {
infile_1020 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1020.eof()) {
infile_1020 >> cubeTxt_1020[cubeTxt_num_1020].ware_10010 >> cubeTxt_1020[cubeTxt_num_1020].ware_10020 >>
cubeTxt_1020[cubeTxt_num_1020].ware_10030 >> cubeTxt_1020[cubeTxt_num_1020].ware_10088 >>
cubeTxt_1020[cubeTxt_num_1020].ware_Sum_InOneDay;
cubeTxt_num_1020++;
}
if (!infile_1021.eof()) {
infile_1021 >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile_1021.eof()) {
infile_1021 >> cubeTxt_1021[cubeTxt_num_1021].ware_10010 >> cubeTxt_1021[cubeTxt_num_1021].ware_10020 >>
cubeTxt_1021[cubeTxt_num_1021].ware_10030 >> cubeTxt_1021[cubeTxt_num_1021].ware_10088 >>
cubeTxt_1021[cubeTxt_num_1021].ware_Sum_InOneDay;
cubeTxt_num_1021++;
}
cubeTxt_num_1019 = cubeTxt_num_1019 - 2;
cubeTxt_num_1020 = cubeTxt_num_1020 - 2;
cubeTxt_num_1021 = cubeTxt_num_1021 - 2;
double total = 0;
char weekday;
int week_day_num;
if(!date.empty() && date.size()==2) {
weekday = date[1];
week_day_num = (int)(weekday - '0');
if(week_day_num >=3 && week_day_num <=9){
week_day_num = week_day_num - 3;
}
else{
cout << "date输入非法" << endl;
return;
}
}
else{
cout << "date输入非法" << endl;
return;
}
if(species == "10010"){
total = cubeTxt_1019[week_day_num].ware_10010 + cubeTxt_1020[week_day_num].ware_10010 + cubeTxt_1021[week_day_num].ware_10010;
cout << "商品:" << species << "在" <<"1019、1020、1021三家店," << date << "日这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10020"){
total = cubeTxt_1019[week_day_num].ware_10020 + cubeTxt_1020[week_day_num].ware_10020 + cubeTxt_1021[week_day_num].ware_10020;
cout << "商品:" << species << "在" <<"1019、1020、1021三家店," << date << "日这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10030"){
total = cubeTxt_1019[week_day_num].ware_10030 + cubeTxt_1020[week_day_num].ware_10030 + cubeTxt_1021[week_day_num].ware_10030;
cout << "商品:" << species << "在" <<"1019、1020、1021三家店," << date << "日这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10088"){
total = cubeTxt_1019[week_day_num].ware_10088 + cubeTxt_1020[week_day_num].ware_10088 + cubeTxt_1021[week_day_num].ware_10088;
cout << "商品:" << species << "在" <<"1019、1020、1021三家店," << date << "日这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else{
cout << "species输入非法" << endl;
}
}
void queryInCube_MDS(string market,string date,string species){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string path_from = "cube_" + market + ".txt";
ifstream infile = get_infile(path_from);
if(infile.fail()){
cout << market << "文件打开失败,查询失败" << endl;
return;
}
cube_txt cubeTxt[32];
int cubeTxt_num = 0;
string head_txt[4];
if (!infile.eof()) {
infile >> head_txt[0] >> head_txt[1] >> head_txt[2] >> head_txt[3];
}
while (!infile.eof()) {
infile >> cubeTxt[cubeTxt_num].ware_10010 >> cubeTxt[cubeTxt_num].ware_10020 >>
cubeTxt[cubeTxt_num].ware_10030 >> cubeTxt[cubeTxt_num].ware_10088
>> cubeTxt[cubeTxt_num].ware_Sum_InOneDay;
cubeTxt_num++;
}
cubeTxt_num = cubeTxt_num - 2;
double total = 0;
char weekday;
int week_day_num;
if(!date.empty() && date.size()==2) {
weekday = date[1];
week_day_num = (int)(weekday - '0');
if(week_day_num >=3 && week_day_num <=9){
week_day_num = week_day_num - 3;
}
else{
cout << "date输入非法" << endl;
return;
}
}
else{
cout << "date输入非法" << endl;
return;
}
if(species == "10010"){
total = cubeTxt[week_day_num].ware_10010;
cout << "商品:" << species << "在" << market <<"这家店,在" << date << "这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10020"){
total = cubeTxt[week_day_num].ware_10020;
cout << "商品:" << species << "在" << market <<"这家店,在" << date << "这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10030"){
total = cubeTxt[week_day_num].ware_10030;
cout << "商品:" << species << "在" << market << "这家店,在" << date << "这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else if(species == "10088"){
total = cubeTxt[week_day_num].ware_10088;
cout << "商品:" << species << "在" << market << "这家店,在" << date << "这天的销售总额为:" <<fixed << setprecision(2) << total << endl;
}
else{
cout << "species输入非法" << endl;
return;
}
}
void construct_Cube(){
string path_first = current_working_directory();
string x = "\\";
path_first = path_first + "/";
string path_from;
string path_to;
string from_txt;
string to_txt;
cout << "请输入获取源数据的txt文件的文件名(fl_1019.txt、fl_1020.txt、fl_1021.txt):“xxx.txt” \n";
getline(cin, from_txt);
if (!from_txt.empty()) {
path_from = path_first + from_txt;
cout << "获取数据的文件名为:" << path_from << endl;
} else {
cout << "输入获取数据的文件名时:存在非法输入";
exit(1);
}
cout << "请输入存放cube数据的的txt文件的文件名(cube_1019.txt,cube_1020.txt,cube_1021.txt):“xxx.txt” \n";
getline(cin, to_txt);
if (!to_txt.empty()) {
path_to = path_first + to_txt;
cout << "存放数据文件的绝对路径为:" << path_to << endl;
} else {
cout << "输入存放数据文件名时:存在非法输入";
exit(1);
}
ifstream infile(path_from, ios::in);
if (infile.fail()) {
cout << "error open!" << from_txt << "打开发生错误,无法正常打开" << endl;
exit(1);
}
ofstream outfile(path_to, ios::out);
if (!outfile) {
cout << "open error!" << to_txt << "打开发生错误,无法正常打开" << endl;
exit(1);
}
Sales sal[10000];
int sal_size = 0;
string table_head[7];
if (!infile.eof()) {
infile >> table_head[0] >> table_head[1] >> table_head[2] >> table_head[3] >> table_head[4] >> table_head[5]
>> table_head[6];
printf("先读出第一行表头如下:\n");
for (int i = 0; i < 7; i++) {
printf("%s\t", table_head[i].c_str());
}
printf("\n");
}
while (!infile.eof()) {
if (sal_size == 10000) {
cout << "默认处理数据10000条,而此数据文件有大于10000条数据,只处理到前10000条,后面数据不读入不处理\n";
break;
}
infile >> sal[sal_size].serial >> sal[sal_size].market >> sal[sal_size].date >> sal[sal_size].sn
>> sal[sal_size].id >> sal[sal_size].num >> sal[sal_size].price;
sal_size++;
}
double total[8][5] = {0};
sal_size = sal_size - 1;
cout << "构建该cube的源数据文件为:" << path_from << ",其共有" << sal_size << "行数据记录\n";
for (int i = 0; i < sal_size; i++) {
char p = sal[i].date[7];
if (sal[i].id / 100 == 10010) {
switch (p) {
case '3': {
total[0][0] += sal[i].num * sal[i].price;
break;
}
case '4': {
total[1][0] += sal[i].num * sal[i].price;
break;
}
case '5': {
total[2][0] += sal[i].num * sal[i].price;
break;
}
case '6': {
total[3][0] += sal[i].num * sal[i].price;
break;
}
case '7': {
total[4][0] += sal[i].num * sal[i].price;
break;
}
case '8': {
total[5][0] += sal[i].num * sal[i].price;
break;
}
case '9': {
total[6][0] += sal[i].num * sal[i].price;
break;
}
default:
break;
}
} else if (sal[i].id / 100 == 10020) {
switch (p) {
case '3': {
total[0][1] += sal[i].num * sal[i].price;
break;
}
case '4': {
total[1][1] += sal[i].num * sal[i].price;
break;
}
case '5': {
total[2][1] += sal[i].num * sal[i].price;
break;
}
case '6': {
total[3][1] += sal[i].num * sal[i].price;
break;
}
case '7': {
total[4][1] += sal[i].num * sal[i].price;
break;
}
case '8': {
total[5][1] += sal[i].num * sal[i].price;
break;
}
case '9': {
total[6][1] += sal[i].num * sal[i].price;
break;
}
default:
break;
}
} else if (sal[i].id / 100 == 10030) {
switch (p) {
case '3': {
total[0][2] += sal[i].num * sal[i].price;
break;
}
case '4': {
total[1][2] += sal[i].num * sal[i].price;
break;
}
case '5': {
total[2][2] += sal[i].num * sal[i].price;
break;
}
case '6': {
total[3][2] += sal[i].num * sal[i].price;
break;
}
case '7': {
total[4][2] += sal[i].num * sal[i].price;
break;
}
case '8': {
total[5][2] += sal[i].num * sal[i].price;
break;
}
case '9': {
total[6][2] += sal[i].num * sal[i].price;
break;
}
default:
break;
}
} else if (sal[i].id / 100 == 10088) {
switch (p) {
case '3': {
total[0][3] += sal[i].num * sal[i].price;
break;
}
case '4': {
total[1][3] += sal[i].num * sal[i].price;
break;
}
case '5': {
total[2][3] += sal[i].num * sal[i].price;
break;
}
case '6': {
total[3][3] += sal[i].num * sal[i].price;
break;
}
case '7': {
total[4][3] += sal[i].num * sal[i].price;
break;
}
case '8': {
total[5][3] += sal[i].num * sal[i].price;
break;
}
case '9': {
total[6][3] += sal[i].num * sal[i].price;
break;
}
default:
break;
}
}
}
double total_day_In_AllId = 0;
for (int i = 0; i < 7; i++) {
total_day_In_AllId = 0;
for (int j = 0; j < 4; j++) {
total_day_In_AllId += total[i][j];
if (j == 3) {
total[i][j + 1] = total_day_In_AllId;
break;
}
}
}
for (int j = 0; j < 4; j++) {
double total_week_In_OneId = 0;
for (int i = 0; i < 7; i++) {
total_week_In_OneId += total[i][j];
if (i == 6) {
total[i + 1][j] = total_week_In_OneId;
break;
}
}
}
double total_1 = 0;
double total_2 = 0;
for (int i = 0; i < 7; i++) {
total_1 += total[i][4];
}
for (int j = 0; j < 4; j++) {
total_2 += total[7][j];
}
total[7][4] = (total_1 + total_2) / 2.0;
outfile << "10010油 \t" << "10020面制品 \t" << "10030米和粉 \t" << "10088其他粮油 \t" << endl;
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 5; j++) {
outfile << fixed << setprecision(2) << total[i][j] << " \t";
}
outfile << endl;
}
cout << path_to <<"的cube构建完毕" << endl;
infile.close();
outfile.close();
}
|