본문 바로가기
카테고리 없음

2020년 정보처리기사 실기 2회 프로그래밍 문제 모음

by artra 2023. 7. 4.
반응형
# 2020년 2회 2번 문제 파이썬
 
>>> asia={"한국""중국""일본"}
>>> asia.add("베트남")
>>> asia.add("중국")
>>> asia.remove("일본")
>>> asia.update(["홍콩""한국""태국"])
>>> print(asia)
cs
// 2020년 2회 5번 문제 자바
 
class Parent {
    void show() {
        System.out.println("Parent");
    }
}
class Child extends Parent {
    void show() {
        System.out.println("Child");
    }
}
public class Exam {
    public static void main(String[] args) {
        Parent pa = new Child();
        pa.show();
    }
}
 
// 2020년 2회 5번 문제 자바 -> C언어
 
#include <stdio.h>
 
typedef void (*ShowFunc)();
 
typedef struct {
    ShowFunc show;
} Parent;
 
void parent_show() {
    printf("Parent\n");
}
 
typedef struct {
    Parent base;
} Child;
 
void child_show() {
    printf("Child\n");
}
 
int main() {
    Child child = { .base.show = child_show };
    Parent *pa = (Parent *)&child;
    pa->show();
    return 0;
}
 
// 2020년 2회 5번 문제 자바 -> 파이썬
 
class Parent:
    def show(self):
        print("Parent")
 
class Child(Parent):
    def show(self):
        print("Child")
 
pa = Child()
pa.show()
 
cs
// 2020년 2회 19번 문제 자바
 
class A {
   int a;
   public A(int n) {
       a = n;
   }
   public void println("a="+a);
}
class B extends A {
   public B(int n) {
       super(n);
       super.print();
   }
}
public class Exam {
   public static void main(String[] args) {
       B obj = new B(10);
   }
}
 
// 2020년 2회 19번 문제 자바 -> C언어
 
#include <stdio.h>
 
typedef struct {
    int a;
    void (*println)(int);
} A;
 
typedef struct {
    A base;
} B;
 
void print(int a) {
    printf("a=%d\n", a);
}
 
A create_A(int n) {
    A a;
    a.a = n;
    a.println = print;
    return a;
}
 
B create_B(int n) {
    B b;
    b.base = create_A(n);
    b.base.println(b.base.a);
    return b;
}
 
int main() {
    B obj = create_B(10);
    return 0;
}
 
// 2020년 2회 19번 문제 자바 -> 파이썬
 
class A:
    def __init__(self, n):
        self.a = n
 
    def println(self):
        print(f'a={self.a}')
 
 
class B(A):
    def __init__(self, n):
        super().__init__(n)
        super().println()
 
 
if __name__ == "__main__":
    obj = B(10)
cs
반응형

댓글