When compiling, the program produces the following error:

The first stage of exception handling in "0x00ad169d" in "kursovaya.exe": 0xC0000005: Access violation when reading "0x668f5ee4". Unhandled exception in "0x00ad169d" in "kursovaya.exe": 0xC0000005: Access violation when reading "0x668f5ee4".

Can someone see a mistake? Eye soiled

Code:

#include <iostream> #include <ctime> #include <cmath> using namespace std; int main() { //Задание начальных параметров srand(time(0)); // 15ons const int n = 5, m = 5; int dloch = 0, sost, I, i, circles = 0; double l = 3.1, u = 2.1, dt = 0.001, t = 0, T = 10000, Ppz = dt*l, r, tob, Tob = 0; double tzk[n]={0}; double tzoch[m]={0}; double Q, A, L0 = 0, T0, k, Potk, Potkz, Pobsz, postz = 0, obslz = 0, otkz = 0; double t_next = 0; //Моделирование while (t < (T - dt)) { circles++; //Задание состояний системы sost = 0; for (I = 0; I < n; i++) { if (tzk[i] > 0) { sost++; } } if (sost == n) { sost += dloch; } //Изменение времени пребывания СМО в состояниях с очередью if (sost > n) { for (I = 0; I <= sost - (n + 1); i++) { tzoch[i] += dt; } } //Генерация поступления заявки и определение времени обслуживания заявки r = rand() % 1000; r = r / 1000; tob = ((-1) / u)*log(1 - r); //Определение поступления заявки if (t >= t_next) { postz++; //заявка поступила r = rand() % int(1 / dt); r = r / int(1 / dt); t_next = t + ((-1) / l)*log(1 - r); if (sost < n) //есть свободные каналы { for (i = 0; i < n; i++) { if (tzk[i] <= 0) //помещение заявки на обслуживание в свободный канал { tzk[i] = tob; Tob += tob; obslz++; break; } } } else if (sost < (n + m)) { dloch++; obslz++; } //помещение заявки в очередь else { otkz++; //отказная заявка } } else { //заявка не поступила if (dloch>0) { for (i = 0; i < n; i++) { if (tzk[i] == 0) //помещение заявки из очереди в свободный канал { tzk[i] = tob; Tob += tob; dloch--; break; } } } } //уменьшение времени обслуживания заявки в занятых каналах for (I = 0; I < n; i++) { if (tzk[i] > 0) tzk[i] -= dt; if (tzk[i] < 0) tzk[i] = 0; } t += dt; } //Расчёт показателей эффективности системы Potk = (otkz * dt) / T; Q = 1 - Potk; A = l*Q; for (I = 0; I < m; i++) { L0 += (I + 1)*tzoch[i] / T; } T0 = L0 / l; k = A / u; Potkz = otkz / postz * 100; Pobsz = obslz / postz * 100; //Вывод результатов cout << "T = " << T <<" dt = "<< dt << endl; cout << "Number circles = " << circles << endl; cout << "The number of bids received = " << postz << endl; cout << "The number of served bids = " << obslz << " or " << Pobsz << "%" << endl; cout << "The number of rejected bids = " << otkz << " or " << Potkz << "%" << endl; cout << "Chance of a denial of service bid = " << Potk << endl; cout << "Relative bandwidth = " << Q << endl; cout << "Absolute bandwidth = " << A << endl; cout << "Queue length = " << L0 << endl; cout << "The average time spent in the bid queue = " << T0 << endl; cout << "The average number of occupied channels = " << k << endl; return (0); } 

Closed due to the fact that the question is too common for the participants Vlad from Moscow , αλεχολυτ , HamSter , aleksandr barakin , Harry 24 Nov '16 at 11:57 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Take the debugger and step through the program to determine where it crashes. - Vlad from Moscow

1 answer 1

To begin with, the variable i not initialized.

 int dloch = 0, sost, I, i, circles = 0; ^^ 

Therefore, it has an indefinite meaning. As a result, already in this cycle

  for (I = 0; I < n; i++) { if (tzk[i] > 0) { sost++; } ^^^^^^ } 

The program has undefined behavior.

But even if the variable were initialized, it is doubtful that its value before entering the next cycle and using it to access the elements of the tzoch array is correct.

  if (sost > n) { for (I = 0; I <= sost - (n + 1); i++) { tzoch[i] += dt; ^^^^^^^^ } } 

Keep in mind that the person who will read your code will not understand at all what the program does.