본문 바로가기
정보처리기사

정보처리기사 실기 17-21년도 프로그래밍 문제 정리

by mihsyeh 2021. 5. 7.

* 2017년-2021년 기출 중 프로그래밍 유형만 정리했습니다. (SQL, C언어, JAVA, Python)

* 제가 혼자 편하게 공부하려고 작성한 글 입니다!

* 실제 기출 문제/답/순서와 다를 수 있으며 시나공 시리즈, 수제비 카페 (cafe.naver.com/soojebi), 블로그 코딩하는핑가님 (ss-o.tistory.com/) 글을 참고로 작성하였습니다.

* 답은 천천히 업로드 될 예정입니다.

 

2021

2021 제1 회 실기 기출


C언어

struct insa{
	char name[10];
    int age
} a[] = {"Kim", 28, "Lee", 38, "Park", 41, "Choi", 30};

struct insa *p;
p=a;
p++;
printf("%s\n", p->name);
printf("%d\n", p->age);

파이썬

class Soojebi:
	li=["Seoul", Kyeonggi", "Inchon", "Daejeon", "Daegu", "Pusan"]
    
s = Soojebi()
str01 = ''
for i in s, li:
	str01 = str01 + i[0]

print(stro1)

 

JAVA

 

a[] = {{45, 40, 65}, {89}}
System.out.println(a[].length);
System.out.println(a[1].length);
System.out.println(a[0][0]);
System.out.println(a[0][1]);
System.out.println(a[1][0]);

 

(2)

public calss Test01{
	public static void main(String[] args){
    	int j, i;
        for (j=0, i=0, i<=5; i++){
        j+=i;
        System.out.print(i);
        if(i==5) {
        	System.out.print("=");
            System.out.println(j);
        } else {
        	System.out.println("+");
        	}
   		}
	}
 }

SQL

SELECT COUNT(*) FROM [TABLE] WHERE
EMPNO > 100 AND SAL >=3000 OR EMPNO = 200

<TABLE>

ENPNO SAL
100 1000
200 3000
300 1500

 

 

2020

2020 제1회 실기 기출


C언어

#include <stdio.h>

void main () {
 int i, j;
 int temp;
 int a[5] = {75, 95, 85, 100, 50};

 for(i=0; i<4; i++){
  for(j=0; j<4-i; j++){
   if(a[j] > a[j+1]{
    temp = a[j];
    a[j] = a[j+1];
    a[j+1] = temp;
  }
 }
}

 for(i=0; 9<5; i++){
  printf("%d ", a[i]);
  }
 }

JAVA

(1)

public static void main(String[] args) {
 int i;
 int a[4] = {0, 1, 2, 3};

 for(i=0; i<4; i++){
  system.out.print(a[i] + " ");
 }
}

 

(2)

public static void main(String[] args){
 int i=3;
 int k=1;

 swith(i){
 case 0:
 case 1:
 case 3: k=0;
 case 4: k+=3;
 case 5: k-=10;
 dafault: k--;
 }

 System.out.print(k);
}

SQL

STUDENT 테이블에 컴퓨터과 학생 50명, 인터넷과 학생 100명, 사무자동화과 학생 50명의 정보가 저장되어 있을 때, 다음 SQL 문의 실행 결과에 따른 각 튜플의 수는? *DEPT는 학과 컬럼명

① SELECT DEPT FROM STUDENT;
② SELECT DISTINCT DEPT FROM STUDENT;
③ SLELCT COUNT(DISTINCT DEPT) FROM STUDENT
  WHERE DEPT='컴퓨터과'

 

 

2020 제2 회 실기 기출


Python

asia={"한국","중국","일본"}
aisa.add("베트남")
aisa.add("중국")
aisa.remove("일본")
asia.update("홍콩","한국","태국")
print(aisa)

JAVA

(1)

class Parent{
public void Print(){
System.out.println("Parent");
}
}
class Child extends parent {
public void Print(){
System.out.println("Child");
}
}
public class Main {
public static void main(String[] args) {
Parent pa = (    ?    ) Child;
pa.print();
}
}

 

(2)

class A {
int a;
public A(int n) {
a = n;
}
public void print() {
System.out.println("a=" +a);
}

class B ectends A {
public B(int n) {
super(a);
super.print();
}
}
public claass Test {
public static void main(String [] args) {
B obj = new B(10);
}
}

SQL

(1) 학생 테이블에서 학년에 3,4 학년인 학번, 이름 속성을 검색. 반드시 IN을 사용하여 SQL문을 작성하시오

*값의 범위 지정 IN 사용, 세미콜론 꼭

(2) student 테이블의 'name' 속성에서 'idx_name'이라는 이름의 인덱스를 생성하는 SQL문을 작성하시오

 

 

2020 제3 회 실기 기출


C언어

(1)

int main(){
   int i, c=0;
   while(i <10){

         i++;
         c *= i;

   }
   printf("% d", c);
}

 

(2)

int r1( ){
    return 4;
}

int r10( ){
    return (30+r1( ));
}

int r100( ){
    return (200+r10( ));
}

int main( ){
    printf("%d ", r100( ));
    return 0;
}

JAVA

(1)

public class Gisafirst {

    public static void main(String [] args){
        int i=0;
        int sum=0;
        while (i <10){
            i++;
            if(i%2==1)
              continue;
        sum += i;
        }
    System.out.print(sum);
    }
}

 

(2)

abstract class Vehicle {
 String name;
 abstract public String getName(String val); 

 public String getName(){
 return "Vehicle name :" + name;
 }
} 

class Car extends Vehicle {
 public Car(String val){
 name = super.name = val;
 }
 public String getName(String val){
 return "Car name :" + val;
 }
 public String getName(byte val []){
 return "Car name :" + val;
 }
}

public class Test {
 public static void main(String [] args){
 Vehicle obj = new Car("Spark");
 System.out.printf(obj.getName());
 }
}

SQL

(1) 테이블에 속성 추가

( ① ) TABLE 학생 ( ② ) 주소 VARCHAR(20);

 

(2) 과목별 점수의 평균이 90 이상인 과목 이름 최소 점수 최대 점수 적으시오 (WHERE 구문 사용 X, GROUP BY, HAVING, AS 사용 *대/소문자 구분 X, 세미콜론(;) 생략 가능

 

(3) 학생 테이블에서 이름이 민수인 튜플 삭제 *대/소문자 구분 X, 세미콜론(;) 생략 가능

 

 

2020 제4 ·5 회 실기 기출


Python

lol = [[1,2,3], [4,5], [6,7,8,9]]

print(lol [0])

print(lol [2][1])

for sub in lol:

for item in sub:

print(item, end=" ")

print()

C언어

int main(){
    char *p = "KOREA";
    printf("% s \n  ", p);
    printf("%s \n ", p+3);
    printf("% c \n ", *p);
    printf("%c \n ", *(p+3));
    printf("%c ", *p+2);
}

JAVA

public class Gisafirst { 
   public static void main(String[] args) {   
    int[][] array = new int[①][②];
    int n = 1;

    for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 5; j++) {
        array[i][j] = j*3 + (i+1);
        System.out.print(array[i][j] + "");
      }
      System.out.println();
    }
  }
}


1 4 7 10 13
2 5 8 11 14
3 6 9 12 15

 

(2)

public class Gisafirst { 
   public static void main(String[] args) {   
      int a[] = new int[8];
      int i = 0, n = 10;
      while (n>0) {  
         a[i++] = n%2; 
         n /= 2; 
      } 
      for (i=7; i>=0; i--)
         System.out.printf("%d", a[i]);
      }
}


실행 결과 : 00001010

 

(3)

class Parent {
 int compute(int num) {
    if( num <= 1) return num;
        return compute(num-1) + compute(num-2);
    }
}

class Child extends Parent {
 int compute(int num) {
    if( num <= 1) return num;
    return compute(num-1) + compute(num-3);
    }
}

public class Gisafirst {
 public static void main(String [] args) {
     Parent obj = new Child();
        System.out.print(obj.compute(4));
    }
}

SQL

where 쓰지 말 것, group by 쓸 것, 집계 함수 사용할 것, AS(alias) 사용할 것, 세미콜론(;) 생략 가능, 인용 필요시 ' 사용

결과 테이블
학과 학과별 튜플수
전기 1
컴퓨터 2
전자 2

 

 

2019

2019 제1 회 실기 기출


C언어

#include <stdio.h>

main(){
	int input, sum = 0;
    scanf("%d", &input);
    while (1) {
    	if (  ( ① ) == 0)
        	break;
        sum = sum + input % 10;
        input = input / ( ② );
    }
    printf("%d\n", sum);
}

 

JAVA

(1)

class SuperClass {
    void paint() {
        draw();
    }
    void draw() {
        system.out.println("Super Object");
    }
}

class SubClass extends SuperClass {
    void paint() {
        super.paint();
        super.draw();
    }
    void draw() {
        system.out.println("Sub Object");
    }
}

public class SampleProgram {
    public static void main(String[] args) {
        SuperClass ex = new SubClass();
        ex.paint();
    }
}

 

(2)

public class Test {
	public static viod main(String[] args) {
    	int i, sum = 0;
        for (i = 1; i <= 110; 1++) {
        	if (i%4 == 0)
            	sum = sum = 1;
        }
        System.out.printf("%d", sum);
    }
}

 

SQL

관계형 데이터베이스에서 사용되는 SQL은 데이터베이스의 조작과 관리에 사용되는 프로그래밍 언어이다. 1974년 IBM 연구소에서 개발한 SEQUEL에서 유래한 SQL은 국제표준 데이터베이스 언어이며, 많은 회사에서 관계형 데이터베이스(RDB)를 지원하는 언어로 채택하고 있다. 관계대수와 관계해석을 기초로 한 혼합 데이터 언어이며, 데이터 구조의 정의, 데이터 조작, 데이터 제어 기능을 모두 갖추고 있다. DCL은 이러한 SQL에서 데이터 관리를 목적으로 사용하는 언어이다. 주로 데이터의 보안, 무결성, 회복, 병행 수행 제어 등을 정의하는 데 사용된다. 그 중 ( 1 )은(는) 데이터베이스 사용자에게 사용 권한을 부여하는데 사용하는 명령어이다.
( 1 )은(는) ALL, SELECT, INSERT, DELETE, UPDATE, INDEX, ALTER 등의 다양한 권한을 다른 사용자에게 부여할 수 있으며, 부여받은 권한을 다른 사용자에게 다시 부여할 수 있는 권한을 부여하는 WITH GRANT OPTION 또한 존재한다. 예) GILDONG에게 STUDENT 테이블에 대한 모든 권한과 다른 사람에게도 권한을 부여할 수 있는 권한까지 부
여한다.

( 1 ) ALL ON STUDENT TO GILDONG WITH GRANT OPTION;


이와 반대로 부여된 권한을 취소하는 명령어는 ( 2 )(이)라고 한다. 취소할 수 있는 권한의 종류는 ( 1 )와 (과) 동일하다. ( 2 )(에)는 WITH GRANT OPTION을 취소할 수 있는 GRANT OPTION FOR가 있으며, 권한 해제 시 권한을 부여받았던 사용자가 다른 사용자에게 부여한 권한도 연쇄적으로 해제시키는 CASCADE가 있 다. 예) GILDONG에게 부여된 STUDENT 테이블에 대한 권한은 유지하고, 다른 사용자에게 권한을 부여할 수 있는 권한만 취소한다.

( 2 ) GRANT OPTION FOR ALL ON STUDENT FROM GILDONG;

 

 

 

2019 제2 회 실기 기출


 

C언어

#include <stdio.h>

main()
{
	char ch, str[] = "12345000";
    int i, j;
    
    for(i = o; i < 8; i++){
    	ch = str[i];
        if { (  ) }
        	break;    
    }
    
    i--;
    for (j = 0; j < i; j++){
    	ch = str[j];
        str[j] = str[i];
        str[i] = ch;
        i--;
    }
    
    printf("%s", str);
}


실행 결과 : 54321000

JAVA

(1)

public static void main(String[] args){
	int numAry[] = new int[5];
	int result = 0;

	for(int i=0; i<5; i++)
		numAry[i]=i+1;
        
	for(int i:numAry)
    	result +=i;
        
	System.out.printf("%d", result);
    }
}

 

(2)

public class Test {
	public static void main(String[] args) {
    	int numAry[] = new int[5];
        int result = 0;
        
        for(int i = o; i <5; i++)
        	numAry[i] = i+1;
            
        for(int i:numAry)
        	result += i;
            
        System.out.printf("%d", result);
 	}
}

SQL

(1) <SCORE> 테이블에 대해 <SQL>을 수행한 결과를 적으시오

<SCORE>

DEPT DB TERM ALGO
001 100 NULL 100
002 NULL NULL 0
003 100 100 200

<SQL>

SELECT SUM(DB) FROM SCORE;
SELECT SUM(TERM) FROM SCORE;
SELECT SUM(ALGO) FROM SCORE;

 

(2) <처리 조건>에 부합하는 SQL문을 작성하시오

<처리조건>

1. 테이블명은 학생을 정의한다.

2. 학생 테이블의 구조는 다음과 같다

3.  학생 테이블에 학번이 193739, 성명이 '홍길동', 학년이 3, 과목이 '경영학개론', 연락처 '010-1234-1234'인 학생의 정보를 입력하시오.

3. 문자형은 싱글(작은)따옴표로 입력하고 문자의 끝에는 세미콜론(;)을 반드시 표기하시오

 

 

 

2018

2018 제1 회 실기 기출


C언어

<출력>

statck's status
value = 40
value = 30
value = 20

<코드>

#include <stdio.h>
#define MAX_STACK_SIZE 10

int stak[MAX_STACK_SIZE];
int top = -1;

void push(int item)
{
	if (top >= (  ①  ))
    {
    	printf("stack is full\n");
    }
    stack[++top] = (  ②  );
}

int pop()
{
	if (top == (  ③  ))
    {
    	printf("stack is empty\n");
    }
    return stack[(  ④  )];
}

int isempty()
{
	if (top == (  ③  ))
    	return 1; else return 0;
}

int isfull()
{
	if (top >= (  ①  ))
    	return 1; else return 0;
}

int main()
{
	int e;
    push(20); push(30); push(40);
    printf("stack's status\n");
    while (!isempty())
    {
    	e = pop();
        printf("calue = %d\n", e);
	}
}

JAVA

<처리조건>

1. 배열에는 95, 75, 85, 100, 50이 차레대로 저장된다.

2. 배열에 저장된 값을 오름차순으로 정렬하여 출력한다.

<코드>

public class Test1 {
	publi static void maind(String[] args) {
    	int E[] = { ( ① ) };
        int i = 0;
        int Temp = 0;
        
        do
        {
        	int j = i;
            do
            {
            	if(E[i] > ( ② ))
                {
                	Tmep = E[i];
                    E[i] = E[j];
                    E[j] = Temp;
                }
                j++;
            } While (j < 5);
            i++;
        } While (i < 4);
        
        for (int a = 0; a <5; a++)
        {
        	System.out.printf(E[a]+"\t");
        }
        System.out.println();
 	}
 }

SQL

<학생>

학번 이름 학년 수강과목 점수 연락처
180101 김기사 1 데이터베이스 90 123-4567
180102 박산업 2 전자계산기 80 234-5678
180103 최사무 3 정보통신 98 345-6789
180104 조합격 4 시스템분석 85 456-7890

<처리조건>

1. 학생 테이블에서 3학년과 4학년 학생의 학번과 이름을 검색하는 SQL문을 작성하시오.

2. 원소 함수 In을 사용하시오 원소함수 In(value1, value2, …)

3. SQL문의 끝에는 세미콜론(;)으로 표시하시오.

 

 

2018 제2회 실기 기출


C언어

(1)

#include <stdio.h>

main() {
	int i, a[5], cnt = 0;
    
    for (i = 0; i < 5; i++)
    	scanf("%d", &a[i]);
        
    for (i = 0; i < 5; i++)
    	if (a[i] % 2 ( ① ) 0)
        	cnt = cnt + 1;
    }
    
    printf("홀수의 개수:%d개", cnt);
}

 

(2)

<출력>

1의 약수 : 1
2의 약수 : 1 2
3의 약수 : 1 3
4의 약수 : 1 2 4
5의 약수 : 1 5

<코드>

#include <stio.h>

main() {
	int i, ;;
    for (i = 1; i <= 5; i++) {
    	printf("%d의 약수 : ", i);
        for (j = 1l j <= 5; j++) {
        	if ( (①) )
            	prinff("%d ", j);
        }
        printf("\n");
    }
    return 0;
}

JAVA

<출력>

0 1 2 3 4
1 2 3 4 5
2 3 4 5 6

<코드>

public class Problem {
	public static void main(String[] args) {
    	int[][] a = new int[()][()];
        for(int i = 0; i < 3; j++) {
        	for(int lnt j = 0; j < 5; j++) {
            	a[i][j] = i + j;
                System.out.printf("%d ", a[i][j]);
             }
             System.out.printf();
        }
    }
}

SQL

<학생>테이블에 최대 3문자로 구성되는 학년 속성을 추가하는 SQL문의 괄호를 채워 완성하시오.

<SQL문>

( ① ) TABLE 학생 ( ② ) 학년 VARCHAR(3);

 

 

2017

2017 제1 회 실기 기출


C언어

#include <stdio.h>
main()
{
	int num[10];
    int min = 9999;
    int i;
    for (i = 0; i < 10; i++; {
    	scanf("%d", &num[i]);
    }
    for (i = 0; i < 10; i++) {
    	if(min > ( ① )){
        	min = num[i];
        }
    }
    print("가장 작은 값은 %d이다.", min);
}

JAVA

public class Test001 {
		public static void main(String[] args) {
    	int[] a = {3, 4, 10, 20, 5};
    	int temp;
    	for(int i = 0; i <= 3; i++{
    		for(int j = i + 1; j <= 4; j++)|
        	if(a[i] < a[j])
        	{
        		temp = a[i];
            	a[i] = a[j];
            	a[j] = temp;
			}
		}
	}
	for(int i = 0; i <5; i++)
    	System.out.println(a[i]);
    }
}

SQL

(1)

 

(2) 데이터베이스와 관련한 다음 <처리 조건>에 부합하는 SQL문이 완성되도록 괄호와 적합한 옵션을 쓰시오.

<처리 조건>

<학생>테이블을 제거한다.

<학생> 테이블을 참조하는 모든 데이터도 함께 제거한다.

<SQL 문>

DROP TABLE 학생 (     );

 

 

2017 제2 회 실기 기출


C언어

#include <stdio.h>
int isprime(int number)
{
	int i;
    for(i = 2; i < number; i++)
    	if( ① )
    		return 0;
    return 1
}

int main()
{
	int number = 100, cnt - 0, i;
    for (i = 2; i < numberl i++)
    	cnt = cnt + isprime(i);
    printf("%d를 넘지 않는 소수는 %d개입니다.\n", numver, cnt);
    return 0;
}

JAVA

public class Tes001{
	public static void main(String[] args){
    INT A = 0, SUM = 0;
    While (a < 10 )
    {
    	a++;
        if(a % 2 ==1)
        continue;
        sum += a;
        }
        system.out.println(sum);
    }
}

SQL

<처리 조건>

1. 학생 테이블에서 이름이 Scott인 튜플을 삭제하시오.

2. 문자형은 싱글(작은)따옴표로 입력하고 문장의 끝에는 세미콜론(;)을 반드시 표기하시오.

 

2017 제3 회 실기 기출


C언어

(1) 실행 결과를 쓰시오

#include <stdio.h>
int res10() {
	return 4;
}
int res30() {
	return 30 + res10();
}
int res200() {
	return 200 + res30();
}
int maint() {
	int result;
	return = res200();
    printf("%d\n", result);
}

 

(2) 실행 결과를 쓰시오

#include <stdio.h>
int power (int data, int exp){
	int i, result = 1;
    for(i = 0; i < exp; i++)
    	result = result + data;
    return result;
}
int main(){
	pintf("%d\n", power(2, 10));
    return 0;
}

JAVA

(1) 배열에 저장된 5개의 자료 중 가장 큰 값과 가장 작은 값을 찾아 출력하는 프로그램을 구현한 것. 괄호에 해당하는 답안을 적으시오

public class Test02{
	public static void main(String[] args){
    	int a[] = {10, 30, 50, 70, 90};
        int i, max, min;
        max = a[0];
        min = a[0];
        for (i = 0; i < 5; i++){
        	if( (    ) > max)
            	max = a[i];
            if( (    ) < min)
            	min = a[i];
        }
        System.out.printf("%d\n", max);
        System.out.printf("%d\n", min);
    }
}

SQL

 

댓글