教室とプロジェクターを集約を使ってプログラムを完成させよという課題なのですが集約がいまいち理解していないので教えてください。
出力結果は
プロジェクターはHITEC製
となるそうです。
lang
1#include <iostream> 2#include <string> //文字列操作用 3using namespace std; 4 5//プロジェクタークラス定義 6class Projector { 7 string maker; //メーカー 8public: 9 Projector(string pmaker = "") : maker(pmaker){} 10 string getMaker()const{ return maker; } 11}; 12/////////////////////////////////////////////////////////// 13//教室クラス定義 14class Room { 15 Projector* projectorP; //プロジェクターオブジェクトを参照するポインタ 16public: 17 //プロジェクター設置 18 void setProjector(string smaker) 19 { 20 21 } 22 //プロジェクターをはずす 23 void removeProjector() 24 { 25 26 27 28 29 } 30 //プロジェクターのメーカー取得 31 string getProjectorMaker()const 32 { 33 if(projectorP != NULL) 34 { 35 return projectorP->getMaker(); 36 } 37 } 38 39 ~Room() 40 { 41 42 43 } 44}; 45/////////////////////////////////////////////////////////// 46int main() 47{ 48 Room* roomP(new Room); 49 50 roomP->setProjector("HITEC"); 51 cout << "プロジェクターは" << roomP->getProjectorMaker() << "製" << endl; 52 roomP->removeProjector(); 53 54 delete roomP; 55 return 0; 56} 57
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。