Загрузка...

Перевести один файл в проект

Тема в разделе C/C++ создана пользователем Mag1str 13 дек 2020. (поднята 13 дек 2020) 165 просмотров

  1. Mag1str
    Mag1str Автор темы 13 дек 2020 нужно вовремя ценить 273 28 июл 2020
    Нужно с одного файла .cpp сделать main.cpp и class.h
    Соответственно нужно создать класс
    Буду очень благодарен)

    Код
    #include <iostream>
    #include <conio.h>
    #include <string>
    #include <time.h>
    using namespace std;

    int m;
    int count=0;
    int res=0;
    int minimum;
    int index=9999999999;
    int new_count;
    int mincount;

    int alg(string *m1,int *scores, int n)
    {
    mincount=0;
    minimum=9999999;
    if (n==1)
    {
    cout<<"Переможець турніру: "<<m1[0];
    getch();
    exit(0);
    }


    cout<<" "<<count+1<<" тур"<<endl;

    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
    {
    cout<<m1[i]<<" грає з "<<m1[j]<<endl;
    res=rand()%3;
    if (res==0)
    cout<<"Нічия"<<endl;
    if (res==1)
    {
    cout<<"Виграє "<<m1[i]<<endl;
    scores[i]+=2;
    }
    if (res==2)
    {
    cout<<"Виграє "<<m1[j]<<endl;
    scores[j]+=2;
    }

    }

    cout<<endl<<"Очки за "<<count+1<<" тур: "<<endl;

    for(int i=0;i<n;i++)
    {
    cout<<m1[i]<<" "<<scores[i]<<endl;
    }

    for(int i=0;i<n;i++)
    if(scores[i]<minimum)
    {
    minimum=scores[i];
    index=i;
    }
    for(int i=0;i<n;i++)
    if (scores[i]==minimum)
    mincount++;
    cout<<endl<<"|||||||||||||||||"<<endl<<endl;
    if (mincount>1)
    {
    count++;
    alg(m1,scores,n);
    }
    else
    new_count--;

    //////////////////////////
    string *m2;
    m2 = new string [n];
    int *new_scores;
    new_scores = new int [n];

    ////////////////////////////
    for(int i=0,j=0;i<n;i++)
    if (i!=index)
    {
    m2[j]=m1[i];
    j++;
    }
    for(int i=0,j=0;i<n;i++)
    if (i!=index)
    {
    new_scores[j]=scores[i];
    j++;
    }
    ////////////////////////////
    cout<<"Через найменшу кількість очок вибуває команда з іменем: "<<m1[index]<<endl<<endl;
    count++;

    alg(m2,new_scores,new_count);

    }

    int main()
    {
    system("chcp 1251 > null");
    srand(time(NULL));
    cout<<"Введіть число команд: ";
    cin>>m;
    string *m1; // объявляем целочисленный массив
    m1 = new string[m];
    cout << "Введиіть імена команд: " << endl;
    for ( int i = 0; i < m; i++ ) // цикл для считывания чисел
    cin >> m1[i]; // считываем вводимые с клавиатуры числа
    cout << "Учасники = ";
    for ( int i = 0; i < m; i++ ) // цикл для вывода элементов массива
    cout<< "| " << m1[i] << " | "; // выводим элементы массива на стандартное устройство вывода
    cout<<endl;
    srand((unsigned int)time(NULL));
    int *scores = new int[m];
    for(int i=0;i<m;i++)
    scores[i]=0;
    cout<<endl;
    new_count=m;
    alg(m1,scores,m);
    return 0;
    }
     
  2. Yoplik
    Yoplik 13 дек 2020 Страшно 137 9 сен 2020
    А я собака:flexing_cat:
     
  3. Shadie_inactive2979844
    Shadie_inactive2979844 13 дек 2020 Заблокирован(а) 39 9 фев 2020
    Зачем ты функции и переменные сделал глобальными?
     
    1. Mag1str Автор темы
Загрузка...
Top