728x90
#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; }
};
int main() {
cout << "2018305065 전유정" << endl;
Book cpp("명품 C++", 10000);
Book java = cpp;
java.set("명품자바", 12000);
cpp.show();
java.show();
}
반응형
'전공 공부 > C++' 카테고리의 다른 글
전위(프렌드) 후위 연산자 중복 (0) | 2021.06.03 |
---|---|
연산자 중복 (0) | 2021.06.02 |
디폴트 매개 변수를 이용하여 중복 함수 간소화 (0) | 2021.05.27 |
클래스 Person 깊은 복사 생성자 (0) | 2021.05.27 |
클래스 Person 얕은 복사 생성자 (프로그램 비정상 종료) (0) | 2021.05.27 |