#include #include using namespace std; struct robot { float x, y, vx, vy; }; bool nelCerchio( robot ); robot nuovaSit( robot, float ); void stampa( robot ); int main() { ifstream in; in.open( "robot.in" ); if ( !in ) { cout << endl << "File di input inesistente!" << endl; return -1; } ofstream out; out.open( "robot.out" ); string s; int k = 0; getline( in, s ); while ( !in.eof() ) { k++; getline( in, s ); } in.clear(); in.seekg(0); robot *A = new robot[ k ]; robot *B = new robot[ k ]; int nct0 = 0, nctd = 0, nin = 0, nout = 0; system("clear"); cout << "Ci sono " << k << " robot cosi' distribuiti:" << endl << endl; for ( int i = 0; i < k; i++ ) { in >> A[i].x >> A[i].y >> A[i].vx >> A[i].vy; stampa( A[i] ); B[i] = nuovaSit( A[i], 1.0 ); nout += (nelCerchio( A[i] ) && !nelCerchio( B[i] ) ? 1 : 0); nin += (!nelCerchio( A[i] ) && nelCerchio( B[i] ) ? 1 : 0); nct0 += nelCerchio( A[i] ) ? 1 : 0; nctd += nelCerchio( B[i] ) ? 1 : 0; if ( nelCerchio( B[i] ) ) { out << B[i].x << "\t" << B[i].y << "\t" << B[i].vx; out << "\t" << B[i].vy << endl; } } cout << endl << "Robot nel cerchio al tempo iniziale " << nct0 << "," << " dopo 1 secondo " << nctd << endl; cout << "Flusso netto " << nin - nout << endl << endl; in.close(); out.close(); return 0; } // Funzioni bool nelCerchio( robot a ) { return a.x*a.x + a.y*a.y <= 1; } robot nuovaSit( robot a, float d ) { robot n = { a.x + a.vx*d, a.y + a.vy*d, a.vx, a.vy }; return n; } void stampa( robot a ) { cout << "Robot alla posizione (" << a.x << "," << a.y << ") con componenti velocita' vx = " << a.vx << " e vy = " << a.vy << endl; }