この課題はプログラムAをもとにしてプログラムBのクラス定義を完成させることです
条件としてmain関数は同じで出力結果も同じです
//出力結果
AIFLの貸出高は2000億円
TADANOの製造物はcrane
クラスCompanyのインスタンス変数nameをどうやって使えばいいのかが分かりません
lang
1**プログラムA** 2#include <iostream> 3#include <string> //文字列操作用クラス 4using namespace std; 5 6//金融業クラス定義 7class Finance { 8 string name; //会社名 9 int loan; //貸出高(億円) 10public: 11 Finance(string fname = "", int floan = 0) 12 : name(fname), loan(floan){} 13 string getName()const{ return name; } 14 int getLoan()const{ return loan; } 15}; 16///////////////////////////////////////////////////// 17//製造業クラス定義 18class Production { 19 string name; //会社名 20 string product; //製造物 21public: 22 Production(string pname = "", string pproduct = "") 23 : name(pname),product(pproduct){} 24 string getName()const{ return name; } 25 string getProduct()const{ return product; } 26}; 27///////////////////////////////////////////////////// 28int main() 29{ 30 Finance* financeP(new Finance("AIFL", 2000)); 31 Production* productionP(new Production("TADANO", "crane")); 32 33 cout << financeP->getName() << "の貸出高は" 34 << financeP->getLoan() << "億円" << endl; 35 cout << productionP->getName() << "の製造物は" 36 << productionP->getProduct() << endl; 37 38 delete financeP; 39 delete productionP; 40 return 0; 41}
lang
1**プログラムB** 2#include <iostream> 3#include <string> //文字列操作用クラス 4using namespace std; 5 6//会社クラス定義 7class Company { 8 string name; //会社名 9public: 10 11 12 13}; 14//金融業クラス定義 15class Finance : public Company { 16 int loan; //貸出高(億円) 17public: 18 19 20 21}; 22///////////////////////////////////////////////////// 23//製造業クラス定義 24class Production : public Company { 25 string product; //製造物 26public: 27 28 29 30}; 31///////////////////////////////////////////////////// 32int main() 33{ 34 Finance* financeP(new Finance("AIFL", 2000)); 35 Production* productionP(new Production("TADANO", "crane")); 36 37 cout << financeP->getName() << "の貸出高は" 38 << financeP->getLoan() << "億円" << endl; 39 cout << productionP->getName() << "の製造物は" 40 << productionP->getProduct() << endl; 41 42 delete financeP; 43 delete productionP; 44 return 0; 45}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。