C++

[C++]명품 C++ 프로그래밍 실습문제 10장 8번

Hs’s Coding vlog 2023. 1. 25. 21:37

[C++]명품 C++ 프로그래밍 실습문제 10장 8번

[C++]명품 C++ programming 실습문제 10장 8번

명품 C++ 프로그래밍실습문제/연습문제 /C++

#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include<cstdlib>
using namespace std;

class Comparable{
    public:
    virtual bool operator >(Comparable& op2)=0; //순수가상함수
    virtual bool operator <(Comparable& op2)=0; //순수가상함수
    virtual bool operator ==(Comparable& op2)=0; //순수가상함수

};

class Circle : public Comparable {
    int radious;
    public:
    Circle(int radious=1){this-> radious =radious;}
    int getRadious(){return radious;}

    bool operator >(Comparable &op){
        Circle *p = (Circle *)&op;
        if(this->radious > p->getRadious())return true;
        else return false;
    }

    bool operator <(Comparable &op){
        Circle *p = (Circle *)&op;
        if(this->radious < p->getRadious())return true;
        else return false;
    }
    bool operator ==(Comparable &op){
        Circle *p = (Circle *)&op;
        if(this->radious == p->getRadious())return true;
        else return false;
    }
    
};

template<class T>
T bigger(T a, T b){
    if(a>b) return a;
    else return b;
}

int main(){
    int a=20,b=50 ,c;
    c=bigger(a,b);
    cout << "20과 50중 큰값은" << c << endl;
    Circle waffle(10),pizza(20),y;
    y = bigger(waffle,pizza);
    cout << "waffle과 pizza중 큰것의 반지름은 " << y.getRadious() << endl;


    return 0;
}