// =========================================================================== // method definitions // =========================================================================== void AGHousehold::generatePeople() { AGDataAndStatistics* ds = &(myCity->statData); //the first adult AGAdult pers(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitEndAge)); adults.push_back(pers); //the second adult if (decisionProba(ds->secondPersProb)) { if (pers.getAge() < ds->limitAgeRetirement) { AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitAgeRetirement)); adults.push_back(pers2); } else { AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge)); adults.push_back(pers2); } } //Children if (pers.getAge() < ds->limitAgeRetirement) { int numChild = ds->getPoissonsNumberOfChildren(ds->meanNbrChildren); while (numChild > 0) { AGChild chl(ds->getRandomPopDistributed(0, ds->limitAgeChildren)); children.push_back(chl); --numChild; } } }
void TextureBuilder::createModules() { QSharedPointer<ModuleDescriptor> mod; foreach (mod,_modDesc) { auto modPtr = mod.data(); if (this->useRandomFactors() && modPtr->enableRandom() ) { modPtr->setBias(this->applyRandomFactor(modPtr->bias()) ); modPtr->setDispl(this->applyRandomFactor(modPtr->displ()) ); modPtr->setExp(this->applyRandomFactor(modPtr->exp()) ); modPtr->setFreq(this->applyRandomFactor(modPtr->freq()) ); modPtr->setLac(this->applyRandomFactor(modPtr->lac()) ); modPtr->setLbound(this->applyRandomFactor(modPtr->lBound()) ); modPtr->setPers(this->applyRandomFactor(modPtr->pers()) ); modPtr->setPow(this->applyRandomFactor(modPtr->pow()) ); modPtr->setRough(this->applyRandomFactor(modPtr->rough()) ); modPtr->setScale(this->applyRandomFactor(modPtr->scale()) ); modPtr->setValue(this->applyRandomFactor(modPtr->value()) ); modPtr->setX(this->applyRandomFactor(modPtr->x()) ); modPtr->setY(this->applyRandomFactor(modPtr->y()) ); modPtr->setZ(this->applyRandomFactor(modPtr->z()) ); } mod.data()->setModules(_modules); auto ptr = mod.data()->makeModule(); qDebug() << "Module " << modPtr->name() << " After module creation..."; modPtr->dumpModule(); _modules.insert(mod.data()->name(), ptr); }
// =========================================================================== // method definitions // =========================================================================== void AGHousehold::generatePeople(int numAdults, int numChilds, bool firstRetired) { AGDataAndStatistics* ds = &(myCity->statData); //the first adult AGAdult pers(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitEndAge)); if (firstRetired) { pers = AGAdult(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge)); } myAdults.push_back(pers); //further adults while (static_cast<int>(myAdults.size()) < numAdults) { if (firstRetired) { AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeRetirement, ds->limitEndAge)); myAdults.push_back(pers2); } else { AGAdult pers2(ds->getRandomPopDistributed(ds->limitAgeChildren, ds->limitAgeRetirement)); myAdults.push_back(pers2); } } //Children while (static_cast<int>(myChildren.size()) < numChilds) { AGChild chl(ds->getRandomPopDistributed(0, ds->limitAgeChildren)); myChildren.push_back(chl); } }
int pers( int n, int count ) { count++ ; if( n == 0 ) return ( count / 2 ) ; return( pers( ( ( n % 10 ) * ( n / 10 ) ), count ) ) ; }
int main(int argc,char* argv[]){ int x, b, i; printf("Please enter the bunch number for percistence \n"); i = 0; while((scanf("%d", &x))!= EOF){ b = pers(x); printf("The persistence number is %d \n",b); i++; } return 0; }
TEST (test_person, person_test) { Person pers("BC"); EXPECT_STREQ(pers.getPosition().c_str(), "no money"); EXPECT_STREQ(pers.getEmployer().c_str(), "loser"); Employer emp("Nivis", "IT"); Position pos("programmer", "Linux programming"); EXPECT_TRUE(emp.hire(pers, pos)); EXPECT_STREQ(pers.getPosition().c_str(), "programmer"); EXPECT_STREQ(pers.getEmployer().c_str(), "Nivis"); }
int main( int argc, char *argv[] ) { int per, number ; printf( "Please enter an integer. \n" ) ; while( ( scanf( "%d", &number ) ) !=EOF ) { per = pers( number ) ; printf( "The persistence of %d is %d. ", number, per ) ; } return 0 ; }
int main( int argc, char *argv[] ) { int per, number, count = 0 ; printf( "Please enter an integer. \n" ) ; while( ( scanf( "%d", &number ) ) !=EOF ) { if( number <= 9 ) printf( "The persistence of %d is 0. \n", number ) ; else { per = pers( number, count ) ; printf( "The persistence of %d is %d. \n", number, per ) ; } } return 0 ; }