void ToolsRhoEstimator::on_valueChanged(double newval) { newval++; // hack to avoid the "unused parameter" g++ warning. // scrape the field values, convert to metric if needed. double temp = tempSpinBox->value(); double press = pressSpinBox->value(); double dewp = dewpSpinBox->value(); if (impBut->isChecked()) { // yup, convert to metric. temp = fahrenheit_to_celsius(temp); press = inchesmercury_to_hectopascals(press); dewp = fahrenheit_to_celsius(dewp); } // calculate rho, in (kg/m^3) double rho_met = calculate_rho(temp, press, dewp); // calculate rho in imperial units. double rho_imp = rho_met_to_imp(rho_met); // display the calculated Rho's. std::stringstream ss_met, ss_imp; ss_met.precision(6); ss_met << rho_met; txtRhoMet->setText(tr(ss_met.str().c_str())); ss_imp.precision(6); ss_imp << rho_imp; txtRhoImp->setText(tr(ss_imp.str().c_str())); }
void ToolsRhoEstimator::on_radio_toggled(bool checked) { checked = true; // hack to avoid the "unused parameter" g++ warning if (impBut->isChecked()) { // we just changed from metric --> imperial, so relabel and do the // field conversions for the user. tempSpinBox->setValue(celsius_to_fahrenheit(tempSpinBox->value())); tempLabel->setText(tr("Temperature (F):")); pressSpinBox->setValue( hectopascals_to_inchesmercury(pressSpinBox->value())); pressLabel->setText(tr("Air Pressure (inHg):")); dewpSpinBox->setValue(celsius_to_fahrenheit(dewpSpinBox->value())); dewpLabel->setText(tr("Dewpoint (F):")); } else { // we just changed from imperial --> metric, so relabel and do the // field conversions for the user. tempSpinBox->setValue(fahrenheit_to_celsius(tempSpinBox->value())); tempLabel->setText(tr("Temperature (C):")); pressSpinBox->setValue( inchesmercury_to_hectopascals(pressSpinBox->value())); pressLabel->setText(tr("Air Pressure (hPa):")); dewpSpinBox->setValue(fahrenheit_to_celsius(dewpSpinBox->value())); dewpLabel->setText(tr("Dewpoint (C):")); } // Relay the "something has changed" signal to // on_valueChanged(double). this->on_valueChanged(0.0); }
int main(int argc, char *argv[], char **envp) { float start = 100.0, end = 600.0, step = 50.0, fahr; float temp; char garbage[80]; int rv = 0; start = ask_for_float("give me a start: "); end = ask_for_float("give me an end: "); step = ask_for_float("give me a step size: "); if ( start > end && step > 0 ) { step = -step; /* negative step */ } /* a <= b <=> c*a <= c*b -a >= -b a <= b */ for(fahr = start; step*fahr <= step*end; fahr = fahr + step) { printf("%g°F => %5.1f°C\n", fahr, fahrenheit_to_celsius(fahr)); } }
int main(void) { int fahrenheit; for (fahrenheit = 0; fahrenheit <= 300; fahrenheit = fahrenheit + 20) printf("%3d %6.1f\n", fahrenheit, fahrenheit_to_celsius(fahrenheit)); return 0; }
int main() { float fahrenheit; float lower, upper, step_size; lower = 0; upper = 300; step_size = 20; for (fahrenheit = lower; fahrenheit <= upper; fahrenheit += step_size) { printf("%3.0f F = %6.1f C\n", fahrenheit, fahrenheit_to_celsius(fahrenheit)); } return 0; }
int main() { int result = plus_one(5); printf("%d\n", result); char sign = get_sign(-5); printf("Sign of %d is %c\n", -5, sign); printf("Celius: %.2f\n", fahrenheit_to_celsius(44)); printf("%.2f^%d = %.2f\n", 3.0, 3, power(3.0, 3)); double triangleArea = calc_triangle_area(3, 4); printf("Area: %.2f", triangleArea); return (EXIT_SUCCESS); }