• 목록
  • 아래로
  • 위로
  • 쓰기
  • 검색

C언어 실습

너에게제공 너에게제공
427 0 0

#include <iostream>
#include<string>
#include <fstream>
using namespace std;
/*
class Manager public Employee {   // public으로 상속 받음
        int bonus;
public:
 Manager(int b=0) {bonus=b; }
        void modify(int s, int b);
        void display();
};

void Manager::modify(int s, int b) {
        salary = s;        
        bonus = b;
}

void Manager::display() {
    cout << "봉급: " <<   salary << " 보너스: " << bonus << endl;}

int main() {
        Manager m;

        m.salary(2000)   // 객체 m의  급여를 2000으로 저장
        m.display();
        m.modify(1000, 500);
        m.display();
}
*/
/*
class Shape
{
        int x, y;
public:
    Shape() { cout << "Shape 생성자() " << endl; }
    ~Shape() { cout << "Shape 소멸자() " << endl;        }
};

class Rectangle :public Shape {   // public으로 상속받음
        int width, height;
public:
    Rectangle() { cout << "Rectangle 생성자()" << endl; }
    ~Rectangle() {  cout << "Rectangle 소멸자()" << endl;  }
};

int main()
{
    Rectangle r;
}
*/
/*
class Shape
{
    int x, y;
public:
    Shape() { cout << "Shape 생성자() " << endl;  }

    Shape(int xloc, int yloc) : x(xloc),y(yloc)
    { cout << "Shape 생성자(xloc, yloc) " << endl;  }

    ~Shape() { cout << "Shape 소멸자() " << endl;        }
};

class Rectangle : public Shape
{
    int width, height;
public:
    Rectangle(int x=0, int y=0, int w=0, int h=0);
    ~Rectangle() { cout << "Rectangle 소멸자()" << endl;  }
};

Rectangle::Rectangle(int x, int y, int w, int h) : Shape(x, y)
{       
    width = w; height = h;
    cout << "Rectangle 생성자(x, y, w, h)" << endl;
}

int main()

    Rectangle r(0, 0, 100, 100);
}
*/
/*
class ParentClass{
private: int x;
protected: int y;
public: int z;
};

class ChildClass1 : public ParentClass {};
class ChildClass2 : protected ParentClass {};
class ChildClass3 : private ParentClass {};

int main() {
 ChildClass1 obj1; ChildClass2 obj2; ChildClass3 obj3;

 

 cout<<obj1.z<<endl;

 

 

}
*/
/*

class Base

     int x; 
  public: 
     void setx(int n) { x = n; } 
     void showx() { cout << "x:" << x << 'n'; } 
}; 

class Derived : public Base // public 으로 상속
{       
    int y; 
  public: 
    void sety(int n) { y = n; } 
    void showy() { cout << "y:" << y << 'n'; } 
}; 

int main() 

     Derived ob;

     ob.setx(10);  
     ob.sety(20); 
     ob.showx();  
     ob.showy();  
}
*/
/*
class Base

     int x; 
  public: 
     void setx(int n) { x = n; } 
     void showx() { cout << x << 'n'; }

     int getx(){return x;}   // x 값을 반환하는 getx 함수
}; 

class Derived : public Base

    int y; 
  public: 
     void sety(int n) { y = n; }
     void show_sum() { cout << "x + y =" <<  getx()+y << 'n'; }
     void showy() { cout << y << 'n'; } 
}; 

int main()

    Derived ob;  

    ob.setx(10);
    ob.sety(20); 
    ob.show_sum(); 
}


*/
/*
class Base

     int x; 
  public: 
     void setx(int n) { x = n; } 
     void showx() { cout << "x :" << x << 'n'; } 
}; 

class Derived : public Base {  
     int y; 
  public: 
     void sety(int n) { y = n; } 
     void showy() { cout << "y : " << y << 'n'; } 
}; 

int main()
{
    Derived ob; 

    ob.setx(10);
    ob.sety(20);
    ob.showx();  
    ob.showy(); 
}
*/
/*
class Base { 
     int x; 
  public: 
     void setx(int n) { x = n; } 
     void showx() { cout << "x: " << x << 'n'; } 
}; 
 
class Derived : private Base  { 
     int y; 
  public: 
     void setxy(int n, int m) {  setx(n); y=m; } 

     void showxy() { showx(); cout<<"y:"<<y<<'n';} 
}; 

int main()

    Derived ob;

    ob.setxy(10, 20); 
    ob.showxy(); 
}

*/
/*
class Base

  protected:  
     int a, b;  
  public: 
     void setab(int n, int m) { a = n; b = m; } 
  void showab()  { cout << "a: " << a << "tb:" << b << 'n'; } 
 
}; 

class Derived :protected Base {    
     int c; 
  public:
   void setabc(int i,int j,int n) {setab(i,j);c=n;}
     void setc(int n) { c = n; } 
     void showabc()  { cout << "a: " << a << "tb:" << b << "tc : " << c << 'n'; } 
}; 

int main()
{
    Derived ob; 

    ob.setab(1, 2);
    ob.setc(3); 
    ob.showabc();

*/
class Base

  protected:
     int a, b;
  public: 
     void setab(int n, int m) { a = n; b = m; } 
}; 

class Derived : public Base

     int c; 
  public: 
     void setc(int n) { c = n; } 
     void showabc() { cout << "a: " << a << "tb:" << b << "tc : " << c << 'n'; }
}; 

int main() 

    Derived ob;

    ob.setab(1, 2); 
    ob.setc(3); 
    ob.showabc();

 

 

신고공유스크랩

댓글 0

댓글 쓰기
권한이 없습니다. 로그인
에디터 모드

신고

"님의 댓글"

이 댓글을 신고하시겠습니까?

댓글 삭제

"님의 댓글"

이 댓글을 삭제하시겠습니까?

공유

퍼머링크