Skip to content

Instantly share code, notes, and snippets.

@torazuka
Created September 25, 2011 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torazuka/1240700 to your computer and use it in GitHub Desktop.
Save torazuka/1240700 to your computer and use it in GitHub Desktop.
Chapter11_drill_PPPC++
/*
11章 ドリル
*/
#include "../../std_lib_facilities.h"
int main()
{
int birth_year = 1940; // ;-P
cout << showbase;
cout << birth_year << "\t: 10進\n"
<< hex << birth_year << "\t: 16進\n"
<< oct << birth_year << "\t: 8進\n";
// ドリル(5)
cout << "age == " << dec << 2011 - birth_year << endl;
// ドリル(8)
int a, b, c, d;
cin >> a >> oct >> b >> hex >> c >> d;
cout << a << '\t' << b << '\t' << c << '\t' << d <<endl;
// 1234 1234 1234 1234 という入力を与えると,
// 1234 668 4660 4660 と出力される.
// 理由は,aは10進,bは8進,cとdは16進として読み込まれた1234を
// 10進表現で出力するため.
// ドリル(9)
cout << general << 1234567.89 << '\t'
<< fixed << 1234567.89 << '\t'
<< scientific << 1234567.89 << endl;
// この場合,fixed(固定小数点)のフォーマットで出力した値が最も正確である.
// generalでは,6桁の制限内でfixedよりも正確な値を得るために,
// scientificが内部的に選択された.
// しかし,6桁の制限により,小数点以下5桁で丸められる.
// scientificは,小数点以下の桁数がデフォルトの6桁で丸められる.
// ドリル(10)
cout << setw(6) << "虎塚" << '|' << setw(6) << "ぬるぽ" << '|' << "08012345678" << '|' << setw(32) << "tora+nullpo@gmail.com" << "|\n"
<< setw(6) << "山田" << '|' << setw(6) << "智子" << '|' << "09012345678" << '|' << setw(32) << "yamada_zabuton1mai@hoge.com" << "|\n"
<< setw(6) << "吉田" << '|' << setw(6) << "雅夫" << '|' << "09012345678" << '|' << setw(32) << "masaotan@hoge.ne.jp" << "|\n"
<< setw(6) << "鈴木" << '|' << setw(6) << "ハルカ" << '|' << "09012345678" << '|' << setw(32) << "haruka.haruka@hoge.org" << "|\n"
<< setw(6) << "渡辺" << '|' << setw(6) << "誠一郎" << '|' << "09012345678" << '|' << setw(32) << "sett@hoge.co.jp" << "|\n"
<< setw(6) << "佐々木" << '|' << setw(6) << "恵" << '|' << "09012345678" << '|' << setw(32) << "sasaki_moga_sasaki@hogege.co.jp" << "|\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment