Skip to content

Instantly share code, notes, and snippets.

@torazuka
Created August 19, 2011 18:53
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/1157676 to your computer and use it in GitHub Desktop.
Save torazuka/1157676 to your computer and use it in GitHub Desktop.
Chapter03_drill_PPPC++
#include "../../std_lib_facilities.h" // from http://www.stroustrup.com/Programming/
int main(){
cout << ">>>> あなたの名前を入力してください ";
string first_name;
cin >> first_name;
if(cin.fail()){
cout << "input error.";
return 1;
}
cout << "こんにちは," << first_name << '\n';
cout << "\n>>>> 手紙を書きたい人の名前を入力してください ";
string dear_first_name;
cin >> dear_first_name;
if(cin.fail()){
cout << "input error.";
return 1;
}
cout << "拝啓.親愛なる " << dear_first_name << "さん,\n";
cout << "\n お元気ですか? わたしは元気です。ネコに会えなくてさびしいです。"
<< "ネコは元気でしょうか? ちゃんとエサをやってくれていますか? "
<< "キャットフードとカリカリ以外は与えないようにしてくださいね。";
string friend_name;
cout << "\n>>>> 別の友人の名前を入力してください ";
cin >> friend_name;
if(cin.fail()){
cout << "input error.";
return 1;
}
cout << "\n " << friend_name << "さんには最近会いましたか?";
char friend_gender = '0';
cout << "\n>>>> もしその別の友人が男性であれば[m],女性であれば[f]を入力してください ";
cin >> friend_gender;
if(cin.fail()){
cout << "input error.";
return 1;
} else if((friend_gender == 'm' || friend_gender == 'f') == false){
cout << "input error. (please enter m or f!)";
return 1;
}
cout << "\n もし" << friend_name << "さんに会ったら,私に電話するように";
if(friend_gender == 'm'){
cout << "彼";
}else if(friend_gender == 'f'){
cout << "彼女";
}
cout << "に伝えてください.あいつはネコを持ち逃げしたふてえやつだ!";
cout << "\n>>>> 手紙の受取人の年齢を入力してください: ";
int age = 0;
cin >> age;
if(cin.fail()){
cout << "input error.";
return 1;
}
if(age < 1 || 109 < age){
simple_error("\nふざけないでちょうだい!!!");
}else{
cout << "\n あなたが誕生日を迎えて" << age << "歳になったと聞きました.";
}
if(age < 12){
cout << "来年は" << age + 1 << "歳になりますね.";
}else if(age == 19){
cout << "来年には選挙に行けますね.";
}else if(70 == age){
cout << "リタイア生活を楽しまれることを願っています.";
}
cout << "\n 敬具.\n\n\n" << first_name;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment