掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
Erro (ID:55759)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ここにコードだしますね,,,ちょっと長いですけど^−^; #include <iostream> #include <string> #include <stdlib.h> const int buffer = 255; using namespace std; class Neko{// Neko Class Start string name; public: Neko( string s ) : name(s){} void voice(); }; void Neko::voice(){ cout << "\t HaHaHa......!!!" << endl; cout << "\t I am " << name << endl; }// Neko Class Finished //継承するねこ class GainCat : public Neko{ int income; public: GainCat( string s, int x ) : Neko(s), income(x){} int choice(); int YearlyIncome() const {return income*12;} void IncreaseIncome(){income++;} }; int GainCat::choice(){ int select; cout << "\t Please select one number to invoke your cat." << endl; cout << "\t 1 ) To mew." << endl; cout << "\t 2 ) To display your yearly income." << endl; cout << "\t 3 ) To increase your income." << endl; cout << "\t 4 ) To finish this program." << endl << "\n\t"; cin >> select; system("cls"); return select; } int main(){ string cat; int money,num; cout << "\t Please enter your faivorite cat name." << endl; cin >> cat; cout << "\t Please enter your starting income." << endl; cout << "\t Please enter your income more than $100." << endl; cin >> money; system("cls"); GainCat one( string cat , int money ); while ( true ){ num = one.choice(); switch ( num ){ case 1: one.voice(); break; case 2: cout << "\t Your current yearly income is " << one.YearlyIncome() << " ." << endl; break; case 3: cout << "\t Your income has been increased by " << one.IncreaseIncome() << " ." << endl; break; case 4: cout << "\t Thank you so much." << endl; cout << "\t See you again." << endl; break; default: cin.clear(); cin.ignore(buffer, '\n'); cout << "You have selected wrong number." << endl; cout << "Please press enter to reselect." << endl; cin.sync(); cin.get(); system("cls"); break; } cout << endl; if ( num == 4 ){ break; } } return 0; }
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.