MACROMEDIA COLDFUSION 4.5-CFML LANGUAGE Uživatelský manuál Strana 31

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 44
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 30
31Writing CFX Tags with Visual C++
Listing 30.5 (continued)
// Add this value to the total
dTotal += atof(thisVal);
// Increment the counter of non-null values
iValueCount++;
// Include optional debug messages for skipped rows
} else if ( pRequest->Debug() ) {
char buffer[50];
sprintf(buffer, “Skipping row %i because value is empty/NULL.”, Row);
pRequest->WriteDebug(buffer);
}
}
// The rest of the computations will be dividing by iValueCount,
// so check it to protect ourselves against a divide-by-zero situation
if ( iValueCount > 0 ) {
// Compute the mean (average) of the numbers
dMean = dTotal / iValueCount;
// Begin calculating the variance
for ( Row = 1; Row <= pQuery->GetRowCount(); Row++) {
// Get the value (as a string) from the query
LPCSTR thisVal = pQuery->GetData(Row, colIndex);
// Assuming the value is not an empty string
if ( strlen(thisVal) > 0) {
dSumSq += pow( dMean - atof(thisVal), 2);
}
}
// Finish computing the variance
dVariance = dSumSq / iValueCount;
// The standard deviation is the square root of the variance
dStdDev = sqrt(dVariance);
}
// Convert the standard deviation to a string,
// then return it to the calling ColdFusion page
char result[20];
gcvt(dStdDev, 10, result);
pRequest->SetVariable( lpszVariable, result);
}
// Catch Cold Fusion exceptions & re-raise them
catch( CCFXException* e )
{
pRequest->ReThrowException( e ) ;
}
// Catch ALL other exceptions and throw them as
// Cold Fusion exceptions (DO NOT REMOVE! --
// this prevents the server from crashing in
Zobrazit stránku 30
1 2 ... 26 27 28 29 30 31 32 33 34 35 36 ... 43 44

Komentáře k této Příručce

Žádné komentáře