#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <string>
#include <ctime>
#include <algorithm>
using namespace std;
/*
//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();
}
*/
/*
//370p NO.10
class Statistics{
int* arr;
int cnt;
public:
Statistics(){ arr= new int[100]; cnt=0;}
bool operator!(){return(!arr);}
Statistics& operator<<(int x){
arr[cnt]=x;
cnt++;
return* this;
}
void operator~(){
for(int i=0; i< cnt; i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
void operator>>(int& op2){2
op2=0;
for(int i=0; i<cnt; i++){
op2+=arr[i];
}
op2/=cnt;
}
};
int main(){
Statistics stat;
if(!stat) cout << "현재 통계 데이타가 없습니다." << endl;
int x[5];
cout<< "5 개의 정수를 입력하라>>";
for(int i=0; i<5; i++) cin >> x[i];
for(int i=0; i<5; i++) stat << x[i];
stat << 100 << 200;
~stat;
int avg;
stat >> avg;
cout << "agv=" << avg << endl;
}
*/
/*
//371p NO.11
class Stack{
int* arr;
int cnt;
public:
Stack(){arr= new int[100]; cnt=0;}
~Stack() {if(arr) delete[] arr;}
Stack& operator<<(int op2){
arr[cnt]=op2;
cnt++;
return* this;
}
bool operator!(){
return(!arr[0]);
}
void operator>>(int& op2){
op2=arr[--cnt];
arr[cnt] = false;
}
};
int main(){
Stack Stack;
Stack << 3 << 5 << 10;
while(true){
if(!Stack) break;
int x;
Stack >> x;
cout << x << ' ';
}
cout << endl;
}
*/
/*
//8장 상속 설명
class Parents{
public:
int a, b, c;
Parents() { cout<<"Parents Normal\n"; }
Parents(int a, int b, int c) {
cout << "Parents More\n";
}
void show();
};
class Children : Parents{
public:
Children() { cout << "child\n"; }
int x, y, z;
void run();
};
int main() {
Parents p(10, 20, 30);
cout << "-----------------\n";
Children c;
// casting
// up
p = c;
// down
c = (Children)p;
}
*/
/*
//379p NO.8-1
class Point{
int x,y;
public:
void set(int x, int y){ this->x=x; this->y=y;}
void showPoint(){
cout<<"(" << x << ","<< y<< ")"<< endl;
}
};
class ColorPoint : public Point{
string color;
public:
void setColor(string color){this->color=color;}
void showColorPoint();
};
void ColorPoint::showColorPoint(){
cout<< color << ":";
showPoint();
}
int main() {
Point p;
ColorPoint cp;
cp.set(3,4);
cp.setColor("Red");
cp.showColorPoint();
}
*/
/*
//388p NO.8-2
class Point{
protected:
int x,y;
public:
void set(int x, int y) {this->x=x; this->y=y; }
void showPoint(){
cout << "(" << x << "," << y << ")" << endl;
}
};
class ColorPoint : public Point {
string color;
public:
void setColor(string color) {this->color=color; }
void showColorPoint();
bool equals(ColorPoint p);
};
void ColorPoint::showColorPoint(){
cout<< color << ":";
showPoint();
}
bool ColorPoint::equals(ColorPoint p) {
if(x==p.x && y==p.y&& color==p.color)
return true;
else
return false;
}
int main() {
Point p;
p.set(2,3);
p.x =5;
p.y =5;
p.showPoint();
ColorPoint cp;
cp.x = 10;
cp.y = 10;
cp.set(3,4);
cp.setColor("Red");
ColorPoint cp2;
cp2.set(3,4);
cp2.setColor("Red");
cout<<((cp.equals(cp2))?"true":"false");
}
*/
/*
//395p NO.8-3
class TV{
int size;
public:
TV() {size = 20;}
TV(int size) {this->size=size;}
int getSize() {return size;}
};
class WideTV : public TV{
bool videoIn;
public:
WideTV(int size, bool videoIn ) : TV(size){
this->videoIn=videoIn;
}
bool getVideoIn() {return videoIn;}
};
class SmartTv : public WideTV{
string ipAddr;
public:
SmartTv(string ipAddr, int size) : WideTV(size, true){
this->ipAddr=ipAddr;
}
string getIpAddr() { return ipAddr;}
};
int main(){
SmartTv htv("192.0.0.1", 32);
cout << "size="<< htv.getSize()<< endl;
cout << "videoIn=" << boolalpha << htv.getVideoIn() << endl;
cout << "IP=" << htv.getIpAddr()<<endl;
}
*/
/*
//399p NO.8-4
class Base{
int a;
protected:
void setA(int a) {this->a=a;}
public:
void showA() {cout << a;}
};
class Derived : private Base{
int b;
protected:
void setB(int b) { this->b=b;}
public:
void showB(){cout<<b;}
};
int main(){
Derived x;
x.a=5;
x.setA(10);
x.showA();
x.b=10;
x.setB(10);
x.showB()
;}
*/
/*
//400p NO.8-5
class Base{
int a;
protected:
void setA(int a){this->a=a;}
public:
void showA(){cout<< a; }
};
class Derived : protected Base {
int b;
protected:
void setB(int b) {this->b =b;}
public:
void showB() {cout << b;}
};
int main(){
Derived x;
x.a=5;
x.setA(10);
x.showA();
x.b=10;
x.setB(10);
x.showB();
}
*/
/*
//401p NO.8-6
class Base{
int a;
protected:
void setA(int a){this->a=a;}
public:
void showA(){cout << a;}
};
class Derived : private Base{
int b;
protected:
void setB(int b) {this->b=b;}
public:
void showB(){
setA(5);
showA();
cout << b;
}
};
class GrandDerived : private Derived{
int c;
protected:
void setAB(int x){
setA(x);
showA();
setB(x);
}
};
*/
/*
//404p NO.8-7
class Adder{
protected:
int add(int a, int b) {return a+b;}
};
class Subtractor{
protected:
int minus(int a, int b) {return a-b;}
};
class Calculator : public Adder, public Subtractor{
public:
int calc(char op, int a, int b);
};
int Calculator::calc(char op, int a, int b){
int res=0;
switch(op){
case '+' : res = add(a,b); break;
case '-' : res =minus(a,b); break;
}
return res;
}
int main(){
Calculator handCalculator;
cout<<"2 + 4 = "<< handCalculator.calc('+', 2, 4) << endl;
cout<< "100 - 8 = "<< handCalculator.calc('-', 100, 8) << endl;
}
*/
/*
//411p open challenge_다시
class Product{
protected:
int id[100];
string
};
int main(){
cout<< "***** 상품 관리 프로그램을 작동합니다 *****" << endl;
for(;;){
cout<<"상품 추가(1), 모든 상품 조회(2), 끝내기(3) ?";
cin >>a;
switch(a){
case '1':
cout << "상품 종류 책(1), 음악CD(2), 회화팩(3) ?";
cin >> b;
switch
case '2':
case '3':
return 0;
}
}
}
*/
/*
//418p NO.01
class Circle{
public:
int radius;
Circle(int radius=0) {this->radius=radius; }
int getRadius() {return radius;}
void setRaius(int radius) {this->radius= radius;}
double gerArea() {return 3.14*radius*radius;}
};
class NamedCircle: public Circle{
string name;
public:
NamedCircle(int radius, string name);
void show();
};
NamedCircle::NamedCircle(int radius, string name): Circle(radius) {
this->name = name;
}
void NamedCircle::show(){
cout<< "반지름이 " <<getRadius() << "인 " << name<<endl;
}
int main() {
NamedCircle waffle(3, "waffle");
waffle.show();
}
*/
//418p NO.2_다시
class Circle{
public:
int radius;
Circle(int radius=0) {this->radius=radius; }
int getRadius() {return radius;}
void setRaius(int radius) {this->radius= radius;}
double gerArea() {return 3.14*radius*radius;}
};
class NamedCircle: public Circle{
string name;
public:
NamedCircle(int radius, string name);
void show();
};
NamedCircle::NamedCircle(int radius, string name): Circle(radius) {
this->name = name;
}
void NamedCircle::show(){
cout<< "반지름이 " <<getRadius() << "인 " << name<<endl;
}
int main() {
NamedCircle pizza[5];
cout<< "5 개의 정수 반지름과 원의 이름을 입력하세요"<<endl;
for(i=0; i<5; i++){
cout << i << ">> ";
cin >>
}
NamedCircle waffle(3, "waffle");
waffle.show();
}