/* Collaborating Class Header */ #include "Complex6.h" /* C++ Headers */ #include #include using namespace std; /* ====================================================================== */ bool cerchio(double x, double y) { if (x*x+y*y > 1) return false; return true; } bool mandel(double x, double y) { Complex point(x,y); Complex z; int maxIter = 1000; int iter = 0; while(z.mod()<100) { z = z*z+point; iter++; if (iter>maxIter) return true; } return false; } int main() { Complex c(1,2); Complex c1(2,4); //Complex s = c.somma(c1); Complex s1 = c+c1; //Complex s1 = c.operator+(c1); double a=1; Complex sa(a); Complex s2 = c+a; //Complex s2 = c.operator+(a); //Complex s2 = operator+(c,a); //Complex s2 = c.operator+(Complex(a)); Complex s3 = a+c; //Complex s3 = a.operator+(c); //Complex s3 = operator+(a,c); cout << "a : " << a << endl; Complex p = c*s1; Complex minus = -p; //Complex minus = operator-(p); Complex minus1 = s1-s2; //Complex minus1 = operator-(s1,s2); cout << "c : " << c << endl; cout << "s1 : " << s1 << endl; cout << "s2 : " << s2 << endl; cout << "s3 : " << s3 << endl; cout << "stupido : " << Complex(1,-1) << endl; cout << "p : " << p << endl; // int a = ( 1>2 ? 1 : 2 ); // int a ; // if (1>2) a=1; // else a=2; const int lanci = 100000; double minx = -2.5; double maxx = 1.5; double miny = -2; double maxy = 2; double areaRettangolo = (maxx-minx)*(maxy-miny); int sassiDentro = 0; int sassiDentroMandel = 0; for (int i=0; i < lanci; ++i) { // creo x,y random tra 0 e 1 double x = (double)(1.*rand()/RAND_MAX*(maxx-minx)+minx); double y = (double)(1.*rand()/RAND_MAX*(maxy-miny)+miny); // controllo se (x,y) e' dentro al cerchio //if (cerchio(x,y)) sassiDentro++; if (mandel(x,y)) sassiDentroMandel++; // se si => incremento sassi nel cerchio } double area = (4.*sassiDentro/lanci); cout << "sassiDentro " << sassiDentro << endl; cout << "Area " << area << endl; double areaMandel = (1.*sassiDentroMandel/lanci)*areaRettangolo; cout << "sassiDentroMandel " << sassiDentroMandel << endl; cout << "Area Mandel " << areaMandel << endl; }