#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <ctime>
#include <algorithm>
using namespace std;
//367p NO.01-1
/*
class Book{
string title;
int price, pages;
public:
Book(string title="", int price=0, int pages=0){
this->title = title; this-> price = price; this->pages = pages;
}
void show(){
cout << title << ' '<< price << "원 " << pages << " 페이지" << endl;
}
string getTitle() {return title; }
Book& operator +=(int price);
Book& operator -=(int price);
};
Book& Book::operator +=(int price) {
this->price += price;
return *this;
}
Book& Book::operator -=(int price) {
this->price -= price;
return *this;
}
int main() {
Book a("청춘", 20000, 300), b("미래", 30000, 500);
a += 500;
b -= 500;
a.show();
b.show();
}
*/
/*
//367p NO.01-2
class Book{
string title;
int price, pages;
public:
Book(string title="", int price=0, int pages=0){
this->title = title; this-> price = price; this->pages = pages;
}
void show(){
cout << title << ' '<< price << "원 " << pages << " 페이지" << endl;
}
string getTitle() {return title; }
friend Book& operator +=(Book& book,int price);
friend Book& operator -=(Book& book ,int price);
};
Book& operator +=(Book& book, int price) {
book.price += price;
return book;
}
Book& operator -=(Book& book, int price) {
book.price -= price;
return book;
}
int main() {
Book a("청춘", 20000, 300), b("미래", 30000, 500);
a += 500;
b -= 500;
a.show();
b.show();
}
*/
/*
//367p NO.2-2
class Book{
public:
string title;
int price, pages;
Book(string title="", int price=0, int pages=0){
this->title = title; this-> price = price; this->pages = pages;
}
void show(){
cout << title << ' '<< price << "원 " << pages << " 페이지" << endl;
}
string getTitle() {return title; }
friend bool operator==(Book a, int b);
friend bool operator==(Book a, string str);
friend bool operator==(Book a, Book b);
};
bool operator==(Book a, int b)
{
if (a.price == b)
return true;
else
return false;
}
bool operator==(Book a, string str)
{
if (a.title == str)
return true;
else
return false;
}
bool operator==(Book a, Book b)
{
if (a.price == b.price && a.title == b.title && a.pages == b.pages)
return true;
else
return false;
}
int main(){
Book a("명품 C++", 30000, 500), b("고품 C++", 30000, 500);
if(a == 30000) cout << "정가 30000원" << endl;
if(a == "명품 C++") cout << "명품 C++입니다." << endl;
if(a == b) cout << "두 책이 같은 책입니다." << endl;
}
*/
/*
//367p NO.03_다시
class Book{
public:
string title;
int price, pages;
Book(string title="", int price=0, int pages=0){
this->title = title; this-> price = price; this->pages = pages;
}
void show(){
cout << title << ' '<< price << "원 " << pages << " 페이지" << endl;
}
string getTitle() {return title; }
friend bool operator==(Book a, int b);
};
bool operator==(Book a, int b)
{
if (a.price == 0)
return true;
else
return false;
}
int main() {
Book book("벼룩시장", 0, 50);
if(!book) cout << "공짜다" << endl;
}
*/
/*
//367p NO.04
class Book{
int price, pages;
public:
string title;
Book(string title= "", int price=0, int pages=0){
this->title = title; this->price = price; this->pages =pages;
}
void show(){
cout << title << ' '<< price << "원 " << pages << " 페이지"<< endl;
}
string getTitle() {return title; }
friend bool operator<( Book a, string str);
};
bool operator<( Book a, string str)
{
if (a.title < str)
return !true;
else
return !false;
}
int main(){
Book a("청춘", 20000, 300);
string b;
cout << "책 이름을 입력하세요>>";
getline(cin, b);
if(a < b)
cout << a.getTitle() << "이 " << b << "보다 뒤에 있구나!" << endl;
}
*/
/*
//368p NO.05-1
class Color{
public:
int red, blue, green;
Color(int red=0, int green=0, int blue=0){
this->red = red; this->green = green; this->blue=blue;
}
void show(){
cout << red << ' ' << green << ' ' << blue<< endl;
}
Color operator +(Color op2);
bool operator==(Color op2);
};
Color Color::operator +(Color op2){
Color tmp;
tmp.red = this->red + op2.red;
tmp.green = this->green + op2.green;
tmp.blue = this->blue + op2.blue;
return tmp;
}
bool Color::operator==(Color op2)
{
if (red == op2.red&&green==op2.green&&blue==op2.blue)
return true;
else
return false;
}
int main(){
Color red(255, 0, 0), blue (0, 0, 255), c;
c = red + blue;
c.show();
Color fuchsia(255, 0, 255);
if( c == fuchsia)
cout << "보라색 맞음";
else
cout << "보라색 아님";
}
*/
/*
//368p NO.06-2
class Matrix{
int ar[4];
public:
Matrix() { for(int i=0; i<4; i++) ar[i] = 0; }
Matrix(int a1, int a2, int b1, int b2) {
ar[0] = a1;
ar[1] = a2;
ar[2] = b1;
ar[3] = b2;
}
void show() {cout << "Matrix = { ";
for(int i=0; i<4; i++) cout << ar[i] << ' ';
cout << "}" << endl;}
friend Matrix operator+(Matrix matrix1, Matrix matrix2);
friend Matrix& operator+=(Matrix& matrix1, Matrix matrix2);
friend bool operator==(Matrix matrix1, Matrix matrix2);
};
Matrix operator+(Matrix matrix1, Matrix matrix2){
Matrix tmp;
for(int i=0; i<4; i++)
tmp.ar[i] = matrix1.ar[i] + matrix2.ar[i];
return tmp;
}
Matrix& operator+=(Matrix& matrix1, Matrix matrix2){
for(int i=0; i<4; i++)
matrix1.ar[i] += matrix2.ar[i];
return matrix1;
}
bool operator==(Matrix matrix1, Matrix matrix2) {
for(int i=0; i<4; i++) {
if(matrix1.ar[i] != matrix2.ar[i])
return false;
}
return true;
}
int main() {
Martix a(1,2,3,4), b(2,3,4,5), c;
c = a + b;
a +=b;
a.show(); b.show(); c.show();
if(a == c)
cout << "a and c are the same" << endl;
}
*/
//369p NO.07-1_다시
class Matrix{
int ar[4];
public:
Matrix() { for(int i=0; i<4; i++) ar[i] = 0; }
Matrix(int a1, int a2, int b1, int b2) {
ar[0] = a1;
ar[1] = a2;
ar[2] = b1;
ar[3] = b2;
}
void show() {cout << "Matrix = { ";
for(int i=0; i<4; i++) cout << ar[i] << ' ';
cout << "}" << endl;}
Matrix& operator >>(int n);
Matrix& operator << (int n);
}
Matrix& Matrix::operator>>(int n){
for(int i=0; i<4; i++){
ar[i]==n[i]
}
}
Matrix& Matrix::operator<<(){
for(int i=0; i<4; i++){
ar[i]==n[i]
}
}
int main() {
Matrix a (4,3,2,1), b;
int x[4], y[4] = {1, 2, 3, 4};
a >> x;
b << y;
for(int i=0; i<4; i++)
cout << x[i]<< ' ';
cout << endl;
b.show();
}