myweatherprediction.cpp

来自「C++高级编程这本书所附的源代码」· C++ 代码 · 共 51 行

CPP
51
字号
#include <iostream>

#include "MyWeatherPrediction.h"

using namespace std;

void MyWeatherPrediction::setCurrentTempCelsius(int inTemp)
{
  int fahrenheitTemp = convertCelsiusToFahrenheit(inTemp);
  setCurrentTempFahrenheit(fahrenheitTemp);
}

int MyWeatherPrediction::getTomorrowTempCelsius()
{
  int fahrenheitTemp = getTomorrowTempFahrenheit();
  return convertFahrenheitToCelsius(fahrenheitTemp);
}

void MyWeatherPrediction::showResult()
{
  cout << "Tomorrow's temperature will be " << 
    getTomorrowTempCelsius() << " degrees Celsius (" <<
    getTomorrowTempFahrenheit() << " degrees Fahrenheit)" << endl;

  cout << "The chance of rain is " << (getChanceOfRain() * 100) << " percent"
       << endl;

  if (getChanceOfRain() > 0.5) {
    cout << "Bring an umbrella!" << endl;
  }
}

int MyWeatherPrediction::convertCelsiusToFahrenheit(int inCelsius)
{
  return (int)((9.0/5.0) * (inCelsius + 32));
}

int MyWeatherPrediction::convertFahrenheitToCelsius(int inFahrenheit)
{
  return (int)((5.0/9.0) * (inFahrenheit-32));
}


int main()
{
  MyWeatherPrediction p;
  p.setCurrentTempCelsius(33);
  p.setPositionOfJupiter(80);
  p.showResult();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?