[cpp] проект
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- using namespace std;
- struct Date {
- int day;
- int month;
- int year;
- };
- struct Prod {
- char* company = nullptr;
- char* prod_name = nullptr;
- int price = 1;
- int quantity = 1;
- Date date;
- char* country = nullptr;
- };
- struct CompanyYearData {
- char* company= nullptr;
- int year2013 = 0;
- int year2014 = 0;
- int year2015 = 0;
- int year2016 = 0;
- int year2017 = 0;
- };
- const char* company_country_matrix[30][2];
- const char* company_prefix[5] = { "Big", "GIG", "Tech", "BEST","Prog"};
- const char* company_suffix[6] = { "Corp", "Company", "Org", "Market","Industry","Mall"};
- const char* postfixes[5] = { "_228","_1337","_9090","_100","_001"};
- const char* alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- const char* countries[5] = {
- "Україна", "США", "Нідерланди", "Великобританія", "Франція"
- };
- const char* products_names[10] = {
- "книга", "чоботи", "м'яч", "монітори", "шампунь",
- "стіл", "телефон", "комп'ютер", "ноутбуки", "кавоварка"
- };
- CompanyYearData year_data[30] = {};
- void GenerateDate(Date* date_ptr) {
- int d = rand() % 32;
- int m = rand() % 13 + 1;
- int y = 2012 + rand() % 6;
- date_ptr->day = d;
- date_ptr->month = m;
- date_ptr->year = y;
- }
- int supply_count_2015_2017;
- int company_scores[30] = {};
- void GenerateRandomProduct(Prod* pr) {
- int random = rand() % 30;
- char* company_name = (char*) company_country_matrix[random][0];
- pr->company = new char[strlen(company_name) + 1];
- strcpy(pr->company, company_country_matrix[random][0]);
- pr->country = new char[strlen(company_country_matrix[random][1]) + 1];
- strcpy(pr->country, company_country_matrix[random][1]);
- int random_product_name_index = rand() % 10;
- char* rand_prod_name = (char*)products_names[random_product_name_index];
- pr->prod_name = new char[strlen(rand_prod_name) + 1];
- strcpy(pr->prod_name,rand_prod_name);
- pr->price = rand() % 3000;
- pr->quantity = rand() % 10 + 1;
- GenerateDate(&(pr->date));
- if (pr->date.year >= 2015 && pr->date.year <= 2017) {
- ++supply_count_2015_2017;
- }
- if (pr->date.year == 2013) {
- year_data[random].year2013 += pr->price;
- }
- else if (pr->date.year == 2014) {
- year_data[random].year2014 += pr->price;
- }
- else if (pr->date.year == 2015) {
- year_data[random].year2015 += pr->price;
- }
- else if (pr->date.year == 2016) {
- year_data[random].year2016 += pr->price;
- }
- else if (pr->date.year == 2017) {
- year_data[random].year2017 += pr->price;
- }
- ++company_scores[random];
- }
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- srand(time(0));
- Prod products[100] = {};
- CompanyYearData* year_data_ptr = nullptr;
- for (int i = 0; i < 30; ++i) {
- int rand_pref = rand() % 5;
- int rand_suf = rand() % 6;
- int rand_post = rand() % 5;
- char *full_name = new char[50]();
- strcat(full_name, company_prefix[rand_pref]);
- strcat(full_name, company_suffix[rand_suf]);
- strcat(full_name, postfixes[rand_post]);
- char random_char[3] = { alphabet[rand() % 26],alphabet[rand() % 26], '\0' };
- strcat(full_name, random_char);
- int rand_country = rand() % 5;
- company_country_matrix[i][0] = new char[23];
- company_country_matrix[i][1] = new char[21];
- strcpy((char*)company_country_matrix[i][0], full_name);
- strcpy((char*)company_country_matrix[i][1], countries[rand_country]);
- year_data_ptr = &year_data[i];
- year_data_ptr->company = new char[strlen(full_name) + 1];
- strcpy(year_data_ptr->company, full_name);
- delete[] full_name;
- }
- Prod* prod_ptr;
- for (int i = 0; i < 100; ++i) {
- prod_ptr = &products[i];
- GenerateRandomProduct(prod_ptr);
- }
- int TOTAL_2016_2017 = 0;
- char* UK_2013 = new char[80]();
- int supply_count_2015_2017[30]{};
- char* req_6 = new char[80]();
- int country_revenue_2016[5] = {};
- char* uk_pc_suppliers = new char[200]();
- for (int i = 0; i < 100; ++i) {
- if (strcmp(products[i].prod_name, "комп'ютер") == 0 && strcmp(products[i].country, "Україна") && products[i].date.year == 2016) {
- if (strstr(uk_pc_suppliers, products[i].company) == NULL) {
- strcat(uk_pc_suppliers, " ");
- strcat(uk_pc_suppliers, products[i].company);
- }
- }
- if (strcmp(products[i].prod_name, "монітори") == 0 && products[i].price < 1500 && products[i].date.month == 3 && products[i].date.year == 2015) {
- if (strstr(req_6, products[i].company) == NULL) {
- strcat(req_6, " ");
- strcat(req_6, products[i].company);
- }
- }
- if (products[i].date.year == 2016 || products[i].date.year == 2017) {
- TOTAL_2016_2017 += products[i].price;
- }
- if (strcmp(products[i].country, "Україна") == 0 && products[i].price > 2000 && products[i].date.year == 2013) {
- if (strstr(UK_2013, products[i].company) == NULL) {
- strcat(UK_2013, " ");
- strcat(UK_2013, products[i].company);
- }
- }
- if (products[i].date.year == 2016) {
- if (strcmp(products[i].country, "Україна") == 0) {
- country_revenue_2016[0] += products[i].price;
- }
- else if (strcmp(products[i].country, "США") == 0) {
- country_revenue_2016[1] += products[i].price;
- }
- else if (strcmp(products[i].country, "Нідерланди") == 0) {
- country_revenue_2016[2] += products[i].price;
- }
- else if (strcmp(products[i].country, "Великобританія") == 0) {
- country_revenue_2016[3] += products[i].price;
- }
- else if (strcmp(products[i].country, "Франція") == 0) {
- country_revenue_2016[4] += products[i].price;
- }
- }
- }
- int HIGHEST_SCORE_I = 0;
- int LOWEST_SCORE_I = 0;
- int best_supplier_2015_2016_index = 0;
- for (int i = 0; i < 30; ++i) {
- if (company_scores[i] > company_scores[HIGHEST_SCORE_I]) {
- HIGHEST_SCORE_I = i;
- }
- if (company_scores[i] < company_scores[LOWEST_SCORE_I]) {
- LOWEST_SCORE_I = i;
- }
- if (supply_count_2015_2017[best_supplier_2015_2016_index] < supply_count_2015_2017[i]) {
- best_supplier_2015_2016_index = i;
- }
- cout << company_country_matrix[i][0] << " - " << company_scores[i] << " бал" << endl;
- }
- cout << "Компанія, яка постачає найбільше кількість продуктів: " << company_country_matrix[HIGHEST_SCORE_I][0] << " із кількістю постачальних разів: " << company_scores[HIGHEST_SCORE_I] << endl;
- cout << "Компанія, яка постачає найменше кількість продуктів: " << company_country_matrix[LOWEST_SCORE_I][0] << " із кількістю постачальних разів: " << company_scores[LOWEST_SCORE_I] << endl;
- cout << "суму вартості всіх товарів, що були поставлені за 2016-2017 роки: " << TOTAL_2016_2017 << endl;
- cout << "Назви постачальників, держава яких – «Україна», рік постачання – 2013, вартість товару більше 2000:" << UK_2013 << endl;
- cout << "Найбільш розповсюджена країна постачальник за 2015-2017 роки: " << company_country_matrix[best_supplier_2015_2016_index][1] << endl;
- cout << "Фірми постачальники, в назві товарів яких є слово «монітори», вартість товару не перевищує 1500, а дата постачання – березень 2015 року:" << req_6 << endl;
- for (int i = 0; i < 5; i++) {
- cout << "Сума вартості всіх товарів країни " << countries[i] << ": " << country_revenue_2016[i] << endl;
- }
- int best_2013_i = 0;
- int best_2014_i = 0;
- int best_2015_i = 0;
- int best_2016_i = 0;
- int best_2017_i = 0;
- for (int i = 0; i < 30; ++i) {
- if (year_data[i].year2013 > year_data[best_2013_i].year2013) {
- best_2013_i = i;
- }
- if (year_data[i].year2014 > year_data[best_2014_i].year2014) {
- best_2014_i = i;
- }
- if (year_data[i].year2015 > year_data[best_2015_i].year2015) {
- best_2015_i = i;
- }
- if (year_data[i].year2016 > year_data[best_2016_i].year2016) {
- best_2016_i = i;
- }
- if (year_data[i].year2017 > year_data[best_2017_i].year2017) {
- best_2017_i = i;
- }
- }
- puts("--------------------------------------------------------------------");
- cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2013 році: " << year_data[best_2013_i].company << " із сумою: " << year_data[best_2013_i].year2013 << "\n";
- puts("--------------------------------------------------------------------");
- cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2014 році: " << year_data[best_2014_i].company << " із сумою: " << year_data[best_2014_i].year2014 << "\n";
- puts("--------------------------------------------------------------------");
- cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2015 році: " << year_data[best_2015_i].company << " із сумою: " << year_data[best_2015_i].year2015 << "\n" ;
- puts("--------------------------------------------------------------------");
- cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2016 році: " << year_data[best_2016_i].company << " із сумою: " << year_data[best_2016_i].year2016 << "\n" ;
- puts("--------------------------------------------------------------------");
- cout << "Фірма постачальник, з максимальною сумою вартості товарів, що були поставлені у 2017 році: " << year_data[best_2017_i].company << " із сумою: " << year_data[best_2017_i].year2017 << "\n" ;
- puts("--------------------------------------------------------------------");
- cout << "Постачальників з України, що продавали комп’ютери, у 2016 році:" << uk_pc_suppliers << endl;
- puts("--------------------------------------------------------------------");
- for (int i = 0; i < 30; ++i) {
- delete[] company_country_matrix[i][0];
- delete[] company_country_matrix[i][1];
- delete[] year_data[i].company;
- }
- for (int i = 0; i < 100; ++i) {
- delete[] products[i].company;
- delete[] products[i].country;
- delete[] products[i].prod_name;
- }
- delete[] UK_2013;
- delete[] req_6;
- delete[] uk_pc_suppliers;
- return 0;
- }
Editor
You can edit this paste and save as new: