[cpp] проект

Viewer

copydownloadembedprintName: проект
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. struct Date {
  8.     int day;
  9.     int month;
  10.     int year;
  11. };
  12.  
  13. struct Prod {
  14.     char* company = nullptr;
  15.     char* prod_name = nullptr;
  16.     int price = 1;
  17.     int quantity = 1;
  18.     Date date;
  19.     char* country = nullptr;
  20. };
  21.  
  22. struct CompanyYearData {
  23.     char* company= nullptr;
  24.     int year2013 = 0;
  25.     int year2014 = 0;
  26.     int year2015 = 0;
  27.     int year2016 = 0;
  28.     int year2017 = 0;
  29. };
  30.  
  31. const char* company_country_matrix[30][2]; 
  32.  
  33.  
  34. const char* company_prefix[5] = { "Big""GIG""Tech""BEST","Prog"};
  35. const char* company_suffix[6] = { "Corp""Company""Org""Market","Industry","Mall"};
  36. const char* postfixes[5] = { "_228","_1337","_9090","_100","_001"};
  37. const char* alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  38.  
  39. const char* countries[5] = {
  40.     "Україна""США""Нідерланди""Великобританія""Франція"
  41. };
  42.  
  43. const char* products_names[10] = {
  44.     "книга""чоботи""м'яч""монітори""шампунь",
  45.     "стіл""телефон""комп'ютер""ноутбуки""кавоварка"
  46. };
  47.  
  48. CompanyYearData year_data[30] = {};
  49.  
  50. void GenerateDate(Date* date_ptr) {
  51.     int d = rand() % 32;
  52.     int m = rand() % 13 + 1;
  53.     int y = 2012 + rand() % 6;
  54.     date_ptr->day = d;
  55.     date_ptr->month = m;
  56.     date_ptr->year = y;
  57. }
  58.  
  59. int supply_count_2015_2017;
  60. int company_scores[30] = {};
  61.  
  62. void GenerateRandomProduct(Prod* pr) {
  63.     int random = rand() % 30;
  64.     char* company_name = (char*) company_country_matrix[random][0];
  65.     pr->company = new char[strlen(company_name) + 1];
  66.     strcpy(pr->company, company_country_matrix[random][0]);
  67.     pr->country = new char[strlen(company_country_matrix[random][1]) + 1];
  68.     strcpy(pr->country, company_country_matrix[random][1]);
  69.     int random_product_name_index = rand() % 10;
  70.     char* rand_prod_name = (char*)products_names[random_product_name_index];
  71.     pr->prod_name = new char[strlen(rand_prod_name) + 1];
  72.     strcpy(pr->prod_name,rand_prod_name);
  73.     pr->price = rand() % 3000;
  74.     pr->quantity = rand() % 10 + 1;
  75.     GenerateDate(&(pr->date));
  76.     if (pr->date.year >= 2015 && pr->date.year <= 2017) {
  77.             ++supply_count_2015_2017;
  78.     }
  79.     if (pr->date.year == 2013) {
  80.         year_data[random].year2013 += pr->price;
  81.     }
  82.     else if (pr->date.year == 2014) {
  83.         year_data[random].year2014 += pr->price;
  84.     }
  85.     else if (pr->date.year == 2015) {
  86.         year_data[random].year2015 += pr->price;
  87.     }
  88.     else if (pr->date.year == 2016) {
  89.         year_data[random].year2016 += pr->price;
  90.     }
  91.     else if (pr->date.year == 2017) {
  92.         year_data[random].year2017 += pr->price;
  93.     }
  94.     ++company_scores[random];
  95. }
  96.  
  97.  
  98. int main() {
  99.     SetConsoleCP(1251);
  100.     SetConsoleOutputCP(1251);
  101.     srand(time(0));
  102.  
  103.     Prod products[100] = {};
  104.  
  105.     CompanyYearData* year_data_ptr = nullptr;
  106.  
  107.     for (int i = 0; i < 30; ++i) {
  108.         int rand_pref = rand() % 5;
  109.         int rand_suf = rand() % 6;
  110.         int rand_post = rand() % 5;
  111.         char *full_name = new char[50]();
  112.         strcat(full_name, company_prefix[rand_pref]);
  113.         strcat(full_name, company_suffix[rand_suf]);
  114.         strcat(full_name, postfixes[rand_post]);
  115.         char random_char[3] = { alphabet[rand() % 26],alphabet[rand() % 26]'\0' };
  116.         strcat(full_name, random_char);
  117.         int rand_country = rand() % 5;
  118.         company_country_matrix[i][0] = new char[23];
  119.         company_country_matrix[i][1] = new char[21];
  120.         strcpy((char*)company_country_matrix[i][0], full_name);
  121.         strcpy((char*)company_country_matrix[i][1], countries[rand_country]);
  122.         year_data_ptr = &year_data[i];
  123.         year_data_ptr->company = new char[strlen(full_name) + 1];
  124.         strcpy(year_data_ptr->company, full_name);
  125.         delete[] full_name;
  126.     }
  127.     Prod* prod_ptr;
  128.     for (int i = 0; i < 100; ++i) {
  129.         prod_ptr = &products[i];
  130.         GenerateRandomProduct(prod_ptr);
  131.     }
  132.  
  133.     
  134.     int TOTAL_2016_2017 = 0;
  135.     char* UK_2013 = new char[80]();
  136.     int supply_count_2015_2017[30]{};
  137.     char* req_6 = new char[80]();
  138.     int country_revenue_2016[5] = {};
  139.     char* uk_pc_suppliers = new char[200]();
  140.  
  141.     for (int i = 0; i < 100; ++i) {
  142.         if (strcmp(products[i].prod_name"комп'ютер") == 0 && strcmp(products[i].country"Україна") && products[i].date.year == 2016) {
  143.             if (strstr(uk_pc_suppliers, products[i].company) == NULL) {
  144.                 strcat(uk_pc_suppliers, " ");
  145.                 strcat(uk_pc_suppliers, products[i].company);
  146.             }
  147.         }
  148.         if (strcmp(products[i].prod_name"монітори") == 0 && products[i].price < 1500 && products[i].date.month == 3 && products[i].date.year == 2015) {
  149.             if (strstr(req_6, products[i].company) == NULL) {
  150.                 strcat(req_6, " ");
  151.                 strcat(req_6, products[i].company);
  152.             }
  153.         }
  154.         if (products[i].date.year == 2016 || products[i].date.year == 2017) {
  155.             TOTAL_2016_2017 += products[i].price;
  156.         }
  157.         if (strcmp(products[i].country"Україна") == 0 && products[i].price > 2000 && products[i].date.year == 2013) {
  158.             if (strstr(UK_2013, products[i].company) == NULL) {
  159.                 strcat(UK_2013, " ");
  160.                 strcat(UK_2013, products[i].company);
  161.             }
  162.         }
  163.  
  164.         if (products[i].date.year == 2016) {
  165.             if (strcmp(products[i].country"Україна") == 0) {
  166.                 country_revenue_2016[0] += products[i].price;
  167.             }
  168.             else if (strcmp(products[i].country"США") == 0) {
  169.                 country_revenue_2016[1] += products[i].price;
  170.             }
  171.             else if (strcmp(products[i].country"Нідерланди") == 0) {
  172.                 country_revenue_2016[2] += products[i].price;
  173.             }
  174.             else if (strcmp(products[i].country"Великобританія") == 0) {
  175.                 country_revenue_2016[3] += products[i].price;
  176.             }
  177.             else if (strcmp(products[i].country"Франція") == 0) {
  178.                 country_revenue_2016[4] += products[i].price;
  179.             }
  180.         }
  181.     }
  182.  
  183.     int HIGHEST_SCORE_I = 0;
  184.     int LOWEST_SCORE_I = 0;
  185.     int best_supplier_2015_2016_index = 0;
  186.  
  187.     for (int i = 0; i < 30; ++i) {
  188.         if (company_scores[i] > company_scores[HIGHEST_SCORE_I]) {
  189.             HIGHEST_SCORE_I = i;
  190.         }
  191.         if (company_scores[i] < company_scores[LOWEST_SCORE_I]) {
  192.             LOWEST_SCORE_I = i;
  193.         }
  194.         if (supply_count_2015_2017[best_supplier_2015_2016_index] < supply_count_2015_2017[i]) {
  195.             best_supplier_2015_2016_index = i;
  196.         }
  197.         cout << company_country_matrix[i][0] << " - " << company_scores[i] << " бал" << endl;
  198.     }
  199.  
  200.     cout << "Компанія, яка постачає найбільше кількість продуктів: " << company_country_matrix[HIGHEST_SCORE_I][0] << " із кількістю постачальних разів: " << company_scores[HIGHEST_SCORE_I] << endl;
  201.     cout << "Компанія, яка постачає найменше кількість продуктів: " << company_country_matrix[LOWEST_SCORE_I][0] << " із кількістю постачальних разів: " << company_scores[LOWEST_SCORE_I] << endl;
  202.     cout << "суму вартості всіх товарів, що були поставлені за 2016-2017 роки: " << TOTAL_2016_2017 << endl;
  203.     cout << "Назви постачальників, держава яких – «Україна», рік постачання – 2013, вартість товару більше 2000:" << UK_2013 << endl;
  204.     cout << "Найбільш розповсюджена країна постачальник за 2015-2017 роки: " << company_country_matrix[best_supplier_2015_2016_index][1] << endl;
  205.     cout << "Фірми постачальники, в назві товарів яких є слово «монітори», вартість товару не перевищує 1500, а дата постачання – березень 2015 року:" << req_6 << endl;
  206.  
  207.     for (int i = 0; i < 5; i++) {
  208.         cout << "Сума вартості всіх товарів країни " << countries[i] << ": " << country_revenue_2016[i] << endl;
  209.     }
  210.     int best_2013_i = 0;
  211.     int best_2014_i = 0;
  212.     int best_2015_i = 0;
  213.     int best_2016_i = 0;
  214.     int best_2017_i = 0;
  215.  
  216.     for (int i = 0; i < 30; ++i) {
  217.         if (year_data[i].year2013 > year_data[best_2013_i].year2013) {
  218.             best_2013_i = i;
  219.         }
  220.         if (year_data[i].year2014 > year_data[best_2014_i].year2014) {
  221.             best_2014_i = i;
  222.         }
  223.         if (year_data[i].year2015 > year_data[best_2015_i].year2015) {
  224.             best_2015_i = i;
  225.         }
  226.         if (year_data[i].year2016 > year_data[best_2016_i].year2016) {
  227.             best_2016_i = i;
  228.         }
  229.         if (year_data[i].year2017 > year_data[best_2017_i].year2017) {
  230.             best_2017_i = i;
  231.         }
  232.     }
  233.     puts("--------------------------------------------------------------------");
  234.     cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2013 році: " << year_data[best_2013_i].company << " із сумою: " << year_data[best_2013_i].year2013 << "\n";
  235.     puts("--------------------------------------------------------------------");
  236.     cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2014 році: " << year_data[best_2014_i].company << " із сумою: " << year_data[best_2014_i].year2014 << "\n";
  237.     puts("--------------------------------------------------------------------");
  238.     cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2015 році: " << year_data[best_2015_i].company << " із сумою: " << year_data[best_2015_i].year2015 << "\n" ;
  239.     puts("--------------------------------------------------------------------");
  240.     cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2016 році: " << year_data[best_2016_i].company << " із сумою: " << year_data[best_2016_i].year2016 << "\n" ;
  241.     puts("--------------------------------------------------------------------");
  242.     cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2017 році: " << year_data[best_2017_i].company << " із сумою: " << year_data[best_2017_i].year2017 << "\n" ;
  243.     puts("--------------------------------------------------------------------");
  244.     cout << "Постачальників з України, що продавали комп’ютери, у 2016 році:" << uk_pc_suppliers << endl;
  245.     puts("--------------------------------------------------------------------");
  246.     for (int i = 0; i < 30; ++i) {
  247.         delete[] company_country_matrix[i][0];
  248.         delete[] company_country_matrix[i][1];
  249.         delete[] year_data[i].company;
  250.     }
  251.  
  252.     for (int i = 0; i < 100; ++i) {
  253.         delete[] products[i].company;
  254.         delete[] products[i].country;
  255.         delete[] products[i].prod_name;
  256.     }
  257.  
  258.     delete[] UK_2013;
  259.     delete[] req_6;
  260.     delete[] uk_pc_suppliers;
  261.     return 0;
  262. }
  263.  

Editor

You can edit this paste and save as new:


File Description
  • проект
  • Paste Code
  • 08 May-2024
  • 11.64 Kb
You can Share it: