windchill.cpp
来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 60 行
CPP
60 行
#include <iostream>#include <iomanip> // for setw#include <cmath> // for sqrtusing namespace std;// Owen Astrachan// nested loops to print wind-chill chart//// idea: Programming with Class by Kamin and Reingold, McGraw-Hill// formula for wind-chill from// UMAP Module 658, COMAP, Inc., Lexington, MA 1984, Bosch and Cobbdouble WindChill(double temperature, double windSpeed);int main(){ const int WIDTH = 5; const int MIN_TEMP = -40; const int MAX_TEMP = 50; const string LABEL = "deg. F: "; int temp,wind; // print column headings cout << LABEL; for(temp = MAX_TEMP; temp >= MIN_TEMP; temp -=10) { cout << setw(WIDTH) << temp; } cout << endl << endl; // print table of wind chill temperatures for(wind = 0; wind <= MAX_TEMP; wind += 5) // row heading { cout << wind << " mph:\t"; for (temp = MAX_TEMP; temp >= MIN_TEMP; temp -= 10) // print the row { cout << setw(WIDTH) << int(WindChill(temp,wind)); } cout << endl; } return 0;}double WindChill(double temperature, double windSpeed)// precondition: temperature in degrees Fahrenheit// postcondition: returns wind-chill index/comparable temperature{ if (windSpeed <= 4) // low wind, temperature unaltered { return temperature; } else if (windSpeed <= 45) // high wind { return 91.4 - (10.45 + 6.69*sqrt(windSpeed) - 0.447 * windSpeed) * (91.4 - temperature)/22.0; } else { return (1.6 * temperature - 55.0); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?