Problem:
์ฑ
์ ๋
๋, ์ฑ
์ด๋ฆ, ์ ์ ์ด๋ฆ์ ๋ด์ Book ํด๋์ค๋ฅผ ๋ง๋ค๊ณ , vector v;๋ก ์์ฑํ ๋ฒกํฐ๋ฅผ ์ด์ฉํ์ฌ ์ฑ
์ ์
๊ณ ํ๊ณ , ์ ์์ ๋
๋๋ก ๊ฒ์ํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ผ.
Execution Result:
Objective & Hints:
vector์ ๊ฐ์ฒด์ ์ฝ์
, ๊ฒ์ ์์ฉ ์ฐ์ต
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 #include #include #include using namespace std; class Book{ int year; string b_name; string p_name; public: void set(int year, string b_name, string p_name){ this->year = year; this->b_name = b_name; this->p_name = p_name; } string getP(){ return p_name; } int getY(){ return year; } void show(){ cout << year << "๋
๋, " << b_name << ", " << p_name << endl; } }; int main() { vector v; Book b; int year; string b_name; string p_name; cout << "์
๊ณ ํ ์ฑ
์ ์
๋ ฅํ์ธ์. ๋
๋์ -1์ ์
๋ ฅํ๋ฉด ์
๊ณ ๋ฅผ ์ข
๋ฃํฉ๋๋ค.\n"; while(true){ cout << "๋
๋>>"; cin >> year; if(year==-1) break; fflush(stdin); cout << "์ฑ
์ด๋ฆ>>"; getline(cin, b_name); cout << "์ ์>>"; getline(cin, p_name); b.set(year, b_name, p_name); v.push_back(b); } cout << "์ด ์
๊ณ ๋ ์ฑ
์ " << v.size() << "๊ถ ์
๋๋ค.\n"; cout << "๊ฒ์ํ๊ณ ์ ํ๋ ์ ์ ์ด๋ฆ์ ์
๋ ฅํ์ธ์>>"; fflush(stdin); getline(cin, p_name); for(int i=0; i<v.size(); i++){ if(v[i].getP() == p_name) v[i].show(); } cout << "๊ฒ์ํ๊ณ ์ ํ๋ ๋
๋๋ฅผ ์
๋ ฅํ์ธ์>>"; cin >> year; for(int i=0; i<v.size(); i++){ if(v[i].getY() == year) v[i].show(); } } Explanation:
...