


<code>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
class Book | |
{ | |
string title; | |
int price=0; | |
public: | |
Book(string title, int price) { | |
this->title = title; | |
this->price = price; | |
} | |
~Book() {}; | |
void set(string title, int price) { | |
this->title = title; | |
this->price = price; | |
} | |
void show() { cout << title << ' ' << price << "원" << endl; } | |
//Book& book(const Book&b) { | |
// this->title = b.title; | |
// this->price = b.price; | |
//} | |
}; | |
int main() { | |
Book cpp("명품 C++", 10000); | |
Book java = cpp; | |
java.set("명품자바", 12000); | |
cpp.show(); | |
java.show(); | |
} |
const char*를 쓸때보다 확실히 string 클래스를 사용하니 좀더 수월하게 코드를 짤 수 있었음
'C++ > 명품 c++ programming' 카테고리의 다른 글
명품 Programming C++ chapter 6 챕터 6장 실습 문제 1번 (0) | 2020.08.05 |
---|---|
명품 Programming C++ chapter 5 챕터 5장 실습 문제 12번 (0) | 2020.08.04 |
명품 Programming C++ chapter 5 챕터 5장 실습 문제 10번 (0) | 2020.08.04 |
명품 Programming C++ chapter 5 챕터 5장 실습 문제 9번 (0) | 2020.08.04 |
명품 Programming C++ chapter 5 챕터 5장 실습 문제 8번 (0) | 2020.08.03 |