#include #include #include #include #include #include "person.h" #include "walker.h" #include "drunkard.h" int main() { const int npeople = 1000; person *x[npeople]; int steps, i; double totaldistance = 0; const int nsteps = 10; extern void seed(); seed(); for (i = 0; i < 800; i++) x[i] = new drunkard; for (; i < 900; i++) x[i] = new walker; for (; i < npeople; i++) x[i] = new stroller; for (steps = 0; steps < nsteps; steps++) for (i = 0; i < npeople; i++) x[i]->lurch(); for (i = 0; i < npeople; i++) totaldistance += x[i]->distance(); printf("a person taking %d steps seems to achieve a distance of %g\n", nsteps, totaldistance / npeople); return 0; } void seed() { struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); srand(tv.tv_sec + tv.tv_usec); }