- 901 名前:デフォルトの名無しさん [2008/06/18(水) 15:56:29 ]
- const int CODE_NOT_FOUND = -1;
const int MASTER_ERROR = -1; const int MASTER_SUCCESS = 0; static int master[] = {1, 2, 3, 4, 5, CODE_NOT_FOUND}; static int checkCode(int code){ for(int i = 0; master[i] != CODE_NOT_FOUND; i++) if(code == master[i]) return code; return CODE_NOT_FOUND; } class Manager{ private: int *merchandise; public: Manager(){ merchandise = new int[100]; for(int i=0; i<100; merchandise[i++] = 0); } virtual ~Manager(){ delete[] merchandise; } int add(int code, int n){ if(checkCode(code) == CODE_NOT_FOUND) return MASTER_ERROR; else {merchandise[code] += n; return MASTER_SUCCESS; } } int get(int code){ if(checkCode(code) == CODE_NOT_FOUND) return MASTER_ERROR; if(merchandise[code] == 0) return -1; else return merchandise[code]; } }; こんな感じ
|

|