#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <conio.h>
#include <windows.h>
using namespace std;
const int BLACK = 0;
const int BLUE = 1;
const int GREEN = 2;
const int CYAN = 3;
const int RED = 4;
const int MAGENTA = 5;
const int BROWN = 6;
const int LIGHTGRAY = 7;
const int DARKGRAY = 8;
const int LIGHTBLUE = 9;
const int LIGHTGREEN = 10;
const int LIGHTCYAN = 11;
const int LIGHTRED = 12;
const int LIGHTMAGENTA = 13;
const int YELLOW = 14;
const int WHITE = 15;
static int __BACKGROUND = BLACK;
static int __FOREGROUND = LIGHTGRAY;
int xr[100000], yr[100000], licznik, punkty = 10000;
void gotoxy(int x, int y);
void textbackground(int color);
void textcolor(int color);
int wherex();
int wherey();
void cursorOff();
void cursorOn();
string pl(string text);
void center_txt(string text);
void ramka_1(int xp, int yp, int xk, int yk);
void ramka_2(int xp, int yp, int xk, int yk);
void potega();
double oblicz(bool war);
void losuj();
void sprawdz();
void szereg_symulacji();
int main()
{
char c;
do
{
system("CLS");
textcolor(CYAN); gotoxy(2, wherey() + 1);
cout << "------------------------OPIS-----------------------" << endl; gotoxy(2, wherey() + 1); textcolor(LIGHTGRAY);
cout << "Obliczanie prawdopodobienstwa dla losowo wybranego " << endl; gotoxy(2, wherey() + 1);
cout << "punktu okregu, czy wyznaczona za jego pomoca " << endl; gotoxy(2, wherey() + 1);
cout << "cieciwa, jest dluzsza od promienia tego okregu. " << endl; gotoxy(2, wherey() + 1);
cout << "Domyslna ilosc punktow: " << punkty << endl; gotoxy(2, wherey() + 1); textcolor(CYAN);
cout << "---------------------------------------------------" << endl;
ramka_1(1, 1, 54, wherey());
cout << endl << endl;
gotoxy(2, wherey() + 2);
cout << "------------------------MENU-----------------------" << endl; gotoxy(2, wherey() + 1); textcolor(LIGHTGRAY);
cout << "1. Przeprowadz pojedyncza symulacje " << endl; gotoxy(2, wherey() + 1);
cout << "2. Zmien domyslna ilosc punktow {10...10000} " << endl; gotoxy(2, wherey() + 1);
cout << "3. Przeprowadz szereg symulacji " << endl; gotoxy(2, wherey() + 1);
cout << "4. Wyjscie! " << endl; gotoxy(2, wherey() + 1); textcolor(CYAN);
cout << "---------------------------------------------------" << endl;
ramka_1(1, wherey() - 12, 54, wherey());
textcolor(LIGHTGRAY); gotoxy(1, wherey() + 2); cursorOff();
c = getch();
switch (c)
{
case '1': oblicz(false);
break;
case '2': cout << " Wprowadz domyslna ilosc punktow: ";
cin >> punkty;
break;
case '3': szereg_symulacji();
break;
}
} while (c != '4');
return 0;
}
int potega(int a, int n)
{
int wynik = 1;
if (n != 0)
{
for (int i = 0; i<n; i++)
wynik = wynik * a;
return wynik;
}
else
return wynik;
}
void losuj()
{
int x, y, i = 0;
srand(time(NULL));
while (i<punkty)
{
x = rand() % 401;
y = rand() % 401;
double sprawdz = sqrt(potega(200 - x, 2) + potega(200 - y, 2));
if (sprawdz<200)
{
xr[i] = x;
yr[i] = y;
i++;
}
}
return;
}
void sprawdz()
{
licznik = 0;
for (int i = 0; i<punkty; i++)
{
double cieciwa = 2 * (sqrt(potega(200, 2) - potega(200 - xr[i], 2) - potega(200 - yr[i], 2)));
if (cieciwa>200)
licznik++;
}
return;
}
double oblicz(bool war)
{
losuj();
sprawdz();
double(pr) = double(licznik) / double(punkty);
cout << " Prawdopodobienstwo wynosi: " << pr << endl;
if (war == false)
{
cout << " Nacisnij dowolny klawisz, by kontynuowac.." << endl;
while (getch() == '\0');
}
else
return pr;
}
void szereg_symulacji()
{
int n;
int suma = 0, a;
cout << " Podaj ilosc symulacji: ";
cin >> n;
system("CLS");
for (int i = 0; i<n; i++)
{
cout << i + 1 << ".";
suma = suma + oblicz(true);
if (n<100)
Sleep(50);
}
cout << "Nacisnij dowolny klawisz, by kontynuowac.." << endl;
while (getch() == '\0');
return;
}
void gotoxy(int x, int y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void textbackground(int color)
{
__BACKGROUND = color;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
__FOREGROUND + (color << 4));
}
void textcolor(int color)
{
__FOREGROUND = color;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
color + (__BACKGROUND << 4));
}
void textattr(int _attr)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), _attr);
}
int wherex()
{
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.X + 1;
}
int wherey()
{
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.Y + 1;
}
void cursorOff()
{
CONSOLE_CURSOR_INFO Info;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info);
Info.bVisible = 0;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info);
}
void cursorOn()
{
CONSOLE_CURSOR_INFO Info;
GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info);
Info.bVisible = -1;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &Info);
}
string pl(string text)
{
char c;
for (int i = 0; i<text.length(); i++)
{
switch (text[i])
{
case 'ą': c = 165; break;
case 'ć': c = 134; break;
case 'ę': c = 169; break;
case 'ł': c = 136; break;
case 'ń': c = 228; break;
case 'ó': c = 162; break;
case 'ś': c = 152; break;
case 'ż': c = 190; break;
case 'ź': c = 171; break;
case 'Ą': c = 164; break;
case 'Ć': c = 143; break;
case 'Ę': c = 168; break;
case 'Ł': c = 157; break;
case 'Ń': c = 227; break;
case 'Ó': c = 224; break;
case 'Ś': c = 151; break;
case 'Ż': c = 189; break;
case 'Ź': c = 141; break;
default: c = text[i];
}
text[i] = c;
}
return text;
}
void center_txt(string text)
{
gotoxy(1 + (80 - text.length()) / 2, wherey());
cout << text << endl;
}
void ramka_1(int xp, int yp, int xk, int yk)
{
char lg = 218,
ld = 192,
pg = 191,
pd = 217,
linia_poz = 196,
linia_pion = 179;
gotoxy(xp, yp); cout << lg;
gotoxy(xp, yk); cout << ld;
gotoxy(xk, yp); cout << pg;
gotoxy(xk, yk); cout << pd;
for (int i = xp + 1; i <= xk - 1; i++)
{
gotoxy(i, yp); cout << linia_poz;
gotoxy(i, yk); cout << linia_poz;
}
for (int i = yp + 1; i <= yk - 1; i++)
{
gotoxy(xp, i); cout << linia_pion;
gotoxy(xk, i); cout << linia_pion;
}
}
void ramka_2(int xp, int yp, int xk, int yk)
{
char lg = 201,
ld = 200,
pg = 187,
pd = 188,
linia_poz = 205,
linia_pion = 186;
gotoxy(xp, yp); cout << lg;
gotoxy(xp, yk); cout << ld;
gotoxy(xk, yp); cout << pg;
gotoxy(xk, yk); cout << pd;
for (int i = xp + 1; i <= xk - 1; i++)
{
gotoxy(i, yp); cout << linia_poz;
gotoxy(i, yk); cout << linia_poz;
}
for (int i = yp + 1; i <= yk - 1; i++)
{
gotoxy(xp, i); cout << linia_pion;
gotoxy(xk, i); cout << linia_pion;
}
}
Błąd (aktywny) E0349 żaden operator "<<" nie pasuje do tych argumentów operacji (274)
Błąd C4996 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _getch. See online help for details. (174)
Błąd C4996 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _getch. See online help for details. (151)
Błąd C4996 'getch': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _getch. See online help for details. (79)