Esempio n. 1
0
int Dice::Roll()
// postcondition: number of rolls updated
//                random 'die' roll returned
{
    RandGen gen;    // random number generator

    myRollCount_= myRollCount_ + 1;         // update # of times die rolled
    return gen.RandInt(1,mySides_);        // in range [1..mySides_]
}
Esempio n. 2
0
void drawLandscape(window &w, color skycolor, color groundcolor) { // creates landscape. only called once
    setBrushAndPenColor(w, skycolor);
    w.DrawRectangle(0, 0, w.GetWidth(), w.GetHeight(), FILLED);
    RandGen r;
    int ystart = r.RandInt((double) w.GetHeight() * 0.666, (double) w.GetHeight() * 0.75); // semi random height of ground near bottom of screen
    setBrushAndPenColor(w, groundcolor);
    for (double x = 0; x < w.GetWidth(); x++) {
        int yval = ystart + sin((double) (x / 60)) * 15; // ground will be sin curve
        w.DrawLine(x, yval, x, w.GetHeight());    // draws line from ground level to bottom of screen
    }
}
//--------------
// medPing_Main \
//----------------------------------------------------------------------
// called from iPhone runSim-tab
int medPing_Main()
{
	// print a message to the cell phone
	mP.CELL_PrintF("Hello medPing patient ...\n\n");
	
	//======= DATA STRUCTURE ======================================
	// to hold patient's history of vital signs
	oneVitalHistoryRecord	vitalHistory[MAX_HISTORY];	
	
	// hmr (how many really) vital signs  0 <= hmr < MAX_HISTORY
	long hmr = 0;  
	//=============================================================
	
	RandGen		randGenerator;	// i need a random number generator
	time_t		start, now;		// keep track of time in simulation

	
	// ask user at CELL to input length of simulation
	mP.CELL_PrintF("How many SECONDS would you like to simulate?\n");
	double simulationTime = mP.CELL_fetchReal();
	time(&start);
	
	// simulation loop ....
	time(&now);
	while ( difftime(now,start) < simulationTime )		// while still time to simulate ...
	{
		long waitThisLongSEC = randGenerator.RandInt(1, MAX_WAIT_SEC);
		mP.CELL_PrintF("\n--------------------------\n");
		mP.CELL_PrintF("\n[PAUSE ... (%d seconds) ]\n", waitThisLongSEC);
		sleep(waitThisLongSEC);	// ZZzzzz.....
		// WINDOWS uses the function called: Sleep( milliseconds ) 
		// Sleep(waitThisLongSEC*1000);	// ZZzzzz.....

		
		
		// check our watch ...
		long nSecs = time(&now);
		
		// fetch vital signs from the medPing chip HERE (use mP object, right?)
		double newTemp;
		newTemp = mP.getBodyTemperature_F();
		// :
		// :
		
		
		// now ADD these new vital signs to our history DATA STRUCTURE
		//AddHistoryRecord(nSecs, newTemp, /* ... more here ... ,*/ vitalHistory, hmr);
		
		// PRINT ALL of the series of vital signs so far
		printAllVitalRecords(mP, vitalHistory, hmr);
		

		
	} // while still more to simulate ...
		
		
	mP.CELL_PrintF("\n\nSIMULATION OVER.\n\n");
	
	// prompt for a record to delete HERE,
    
    
    
    // find it (using your Find function)
    
    
    
    // and delete it if found (using your Delete function)
	
	
	
	
	
	mP.CELL_PrintF("\n\nDONE.\n");
	
	// WINDOWS
	// system("PAUSE");
	
	return 0;
	
} // end medPing_Main()