前提・実現したいこと
現在c++の問題を解いています。
Person
- name : string
- Person(name:string):
- getName():string
- setName(n:string):void
Publication
- count:static int
- pubNumber:int
- title:string
- borrower:Person
- Publication(title:string):
- getBorrower():Person
- setBorrower(p:Person):void
- display():void
上記のUMLのclass diagramを使用して下記のoutputを得たいです。
Publication Number Title Borrower Name
1 War and Peace Lady Gaga
2 Object-Oriented Programming Albert Einstein
3 Grapes of Wrath Muhammed Ali
問題文に、Publicationのコンストラクタでは、countを増加させて、それを使用してpubNumberの値を設定する。display関数を用いて上記のoutputを表示すると書かれています。
該当のソースコード
C++
1#include <iostream> 2#include <string> 3#include <iomanip> 4 5using namespace std; 6 7class Person { 8private: 9 string name; 10 11public: 12 13 14 Person (){ 15 {name = "Lady Gaga"}, 16 {"Albert Einstein"}, 17 {"Muhammed Ali"}; 18 } 19 20 Person (string name) { 21 setName(" "); 22 } 23 24 Person(const string& pName) { 25 setName(pName); 26 } 27 28 void setName (const string& pName) { 29 name = pName; 30 } 31 32 string getName() const { 33 return name; 34 } 35}; 36 37 38 39class Publication { 40private: 41 static int count; 42 int pubNumber; 43 string title; 44 Person loaner; 45 //Person(); 46 47 48public: 49 Publication() { 50 51 {title = "War and Peace"}, 52 {"Object-Oriented Programming"}, 53 {"Grapes of Wrath"}; 54 55 } 56 57 58 59 60/* 61 Publication (int pub) { 62 pubNumber = pub; count++; 63 } 64 ここの部分これで良いのでしょうか? 65 int getPubNumber() const { 66 return pubNumber; 67 } 68*/ 69 70 71 72 73 74 Publication (string title) { 75 this->title = title; 76 } 77 78 79 80 void setBorrower(Person p) { 81 this->loaner = p; 82 } 83 84 Person getBorrower() const { 85 return loaner; 86 } 87 88 void display(); 89 90}; 91 92int Publication::count = 0; 93 94int main() { 95 96 //Person person1("Lady gaga"); 97 98 //person1. 99 100 cout << "Publication Number" << setw(5) << "Title" << setw(15) << "Borrower Name" << endl; 101 102 cout << "------------------" << setw(5) << "-----" << setw(15) << "-------------" <<endl; 103 104 return 0; 105} 106
display関数内にどのようなコードを書いてそれをどの様にmain関数でcoutするのか教えて頂けると嬉しいです。
Person (){
{name = "Lady Gaga"},
{"Albert Einstein"},
{"Muhammed Ali"};
}
Publication() {
{title = "War and Peace"}, {"Object-Oriented Programming"}, {"Grapes of Wrath"}; }
また、上記の部分、
error: expected ';' after expression
error: expected expression
とエラーが出るのでそれも教えていただきたいです。
ありがとうございます。よろしくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/10 22:24
2018/10/11 00:18
2018/10/11 00:54
2018/10/11 04:19
2018/10/11 04:45 編集
2018/10/11 04:58
2018/10/11 05:35 編集
2018/10/11 07:58
2018/10/11 08:21
2018/10/11 09:41 編集
2018/10/11 20:30