落書きノート

ふと自分が気になった事を書いてます

慣習 C++で問題を解く

#include <iostream>
#include <iomanip>

using namespace std;

int main(void){
  for(int i = 0; i <= 1000; i++){
    float x = static_cast<float>(i) / 1000;
    cout << fixed << setprecision(3) << x <<
    "\t" << setprecision(6) << x * x << endl;
  }
  return 0;
}

#include <iostream>

using namespace std;

int main(void){
  enum trump { Diamond, Heart, Club, Spade, Invalid };
  int type;

  do{
    cout << "0:ダイヤ 1:ハート 2:クラブ 3:スペード 4:終了";     cin >> type;
  }while(type < Diamond || type > Invalid);

  if(type != Invalid){
    cout << "あなたが選んだのは";
    trump selected = static_cast<trump>(type);
    switch(selected){
      case Diamond: cout << "ダイヤ"; break;
      case Heart: cout << "ハート"; break;
      case Club: cout << "クラブ"; break;
      case Spade: cout << "スペード"; break;
    }
    cout << "でした。" << endl;
  }

  return 0;
}

#include <iostream>

using namespace std;

int main(void){
  enum season { spring, summer, autumn, winter, invalid };
  int type;

  do{
    cout << "0:春 " << "1:夏 " << "2:秋 " << "3:冬 "
    << "4:終了 ";     cin >> type;
  }while(type < spring || type > invalid);

  if(type != invalid){
    season selected = static_cast<season>(type);
    switch(selected){
      case spring: cout << "春はあけぼの" << endl; break;
      case summer: cout << "夏は夜" << endl; break;
      case autumn: cout << "秋は夕暮れ" << endl; break;
      case winter: cout << "冬はつとめて" << endl; break;
    }
  }

  return 0;
}