Example #1
0
void SolveAccelerationProblems1()
{
  //1. A flower pot falls from a windowsill 25.0 m above the sidewalk.   
  //   How much time does a person below have to move out of the way?  
  //   How fast is the flower pot moving when it strikes the ground? 
  Meter const potfalls( 25. );
  SquareSecond const falloffsquaretime = (potfalls * 2.) / Acceleration3( 9.8 );
  Second const rep1 = sqrt( falloffsquaretime );
  Velocity const rep1_2 = potfalls / rep1;
  Scalar const _rep1 = rep1.GetValue();
  Scalar const _rep1_2 = rep1_2.GetValue();
  Assert( fequal( _rep1, 2.2587697572631282 ) );
  Assert( fequal( _rep1_2, 11.067971810589327  ) );

  //2. A plane, starting from rest at one end of a runway, undergoes a 
  //   constant acceleration of 1.6 m/s2 for a distance of 1600 m before 
  //   takeoff.  What is its speed upon takeoff?  What is the time required 
  //   for takeoff?
  Meter const planedistance( 1600. );
  SquareSecond const squaretime2 = (planedistance * 2.) / Acceleration3( 1.6 );
  Second const rep2 = sqrt( squaretime2 );
  Velocity const rep2_2 = planedistance / rep2;
  Scalar const _rep2 = rep2.GetValue();
  Scalar const _rep2_2 = rep2_2.GetValue(); 
  Assert( fequal( _rep2, 44.721359549995796 ) );
  Assert( fequal( _rep2_2, 35.777087639996637 ) );

}
Example #2
0
void PrintPerformance( clock_t const rawdiff, clock_t const unitdiff )
{
  Second const rawtime( Scalar( rawdiff ) / CLOCKS_PER_SEC );
  Second const unittime( Scalar( unitdiff ) / CLOCKS_PER_SEC ); 
  Second const difftime = unittime - rawtime;

  OutputLine( L"Raw time: " + ToString( rawtime.GetValue() ) + rawtime.GetSuffix() );
  OutputLine( L"Unit time: " + ToString( unittime.GetValue() )  + unittime.GetSuffix() );
  OutputLine( L"Time difference: " + ToString( difftime.GetValue() ) + difftime.GetSuffix() );

  OutputLine( L"Performance factor: " + ToString( unittime / rawtime) );
}