Level 1은객관식사지선다형으로출제예정 1. 다음은 POST(Post of Sales Terminal) 시스템의한콜레보레이션다이어그램이다. POST 객체의 enteritem(upc, qty) 와 Sale 객체의 makellineitem(spec,qty) 를 Java 또는 C ++, C # 언어로구현하시오. 각메소드구현과관련하여각객체내에필요한선언이있으면선언하시오. 정답 : (Java & C#) public class POST public void enteritem(int upc, int qty) ProductCatalog prodcatalog; ProductSpecification spec = prodcatalog.specification(upc); public class Sale void makelineitem(productspecification spec, int qty) SalesLineItem sl = new SalesLineItem(spec, qty); (C++) class POST void enteritem(int upc, int qty) ProductCatalog* prodcatalog; ProductSpecification* spec = prodcatalog->specification(upc); ; 1
class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++, C # 언어로구현하시오. trianglearea:=triangle.calculatearea( ) circlearea:= circle.calculatearea( ) [trianglearea< circlearea] [trianglearea>= circlearea] System.out.printIn( Circle is Bigger! ) System.out.printIn( Triangle is Bigger! ) return circlearea return trianglearea 정답 : (java) 해당클래스의특정메소드부분을구현한것이다. Circle 클래스와 Triangle 클래스의구현은달라질수있으며 Foo 클래스의 calculatemaxarea의 if문에대한구현을정확하게표현해야한다. // 아래의소스에서 Bold체에만해당됨 public class Foo public double calculatemaxarea(triangle triangle, Circle circle) double trianglearea = triangle.calculatearea(); double circlearea = circle.calculatearea(); if(trianglearea>= circlearea) System.out.printIn( Triangle is Bigger! ); return trianglearea; else if(trianglearea< circlearea) System.out.printIn( Circle is Bigger! ); 2
return circlearea KCSM Level 1 Sample 문제 public class Circle public double radius = 5.0; public double calculatearea() return radius* radius*3.14; public class Triangle public int height = 10; public int width = 10; public double calculatearea() return height * width *0.5; (C++) // 아래의소스에서 Bold 체에만해당됨 class CCircle double radius = 5.0; double calculatearea(); class CTriangle int height = 10; int width = 10; double calculatearea(); class CFoo double calculatemaxarea(ctriangle triangle, CCircle circle); double CCircle::calculateArea() return radius * radius * 3.14; 3
double CTriangle::calculateArea() return height * width * 0.5; double CFoo::calculateMaxArea(CTriangle triangle, CCircle circle) double trianglearea = triangle.calculatearea(); double circlearea = circle.calculatearea(); if(trianglearea >= circlearea) printf("triangle is Bigger!\n"); return trianglearea; else if(trianglearea < circlearea) printf("circle is Bigger!\n"); return circlearea; (C#) // 아래의소스에서 Bold 체에만해당됨 namespace anamespace public class CCircle public double radius = 5.0; public double calculatearea() return radius * radius * 3.14; public class CTriangle public int height = 10; public int width = 10; public double calculatearea() return height * width * 0.5; public class CFoo double calculatemaxarea(ctriangle triangle, CCircle circle) double trianglearea = triangle.calculatearea(); double circlearea = circle.calculatearea(); if(trianglearea >= circlearea) Console.WriteLine("Triangle is Bigger!"); return trianglearea; else if(trianglearea < circlearea) Console.WriteLine("Circle is Bigger!"); return circlearea; 4
KCSM Level 1 Sample 문제 3. 다음코드를보고액티비티 (Activity) 다이어그램을작성하시오. [ 자바버전 ] import javax.swing.joptionpane; class TestCalculator public static void main(string[] args) String number1 = JOptionPane.showInputDialog( First Num: ); String number2 = JOptionPane.showInputDialog( Second Num: ); double num1 = Double.parseDouble(number1); double num2 = Double.parseDouble(number2); int answer = JOptionPane.showConfirmDialog(null, Add the numbers?, Calculator, JOptionPane.YES_NO_OPTION); Calculator calcus = new Calculator(num1, num2); double calculatedanswer; char operator; if (answer == JOptionPane.YES_OPTION) calculatedanswer = calcus.calculatesum(); operator = + ; else calculatedanswer = calcus.calculatedouble(); operator = - ; String result = Our Calculation: + calcus.getnumber1() + + operator + calcus.getnumber2(); result += \nthe answer is + calculatedanswer; JOptionPane.showMessageDialog(null, result); Sytem.exit(0); [C++ 버전 ] #include <iostream> using namespace std; void main(void) const char YES_OPTION = 'Y'; char oper; int result; 5
char number1[10]; char number2[10]; char answer; int num1; int num2; KCSM Level 1 Sample 문제 cin >> number1; cin >> number2; num1 = atoi(number1); num2 = atoi(number2); Caculator calcus = new Calculator(number1, number1); cout << "Add the numbers(y/n)?"; cin >> answer; if(answer!= YES_OPTION) result = calcus.claculatedifference(); oper = '-'; else result = clacus.calculatesum(); oper = '+'; printf("our Calculation: %d %c %d = %d", num1, oper, num2, result); [C# 버전 ] using System; class Calculator [STAThread] static void Main(string[] args) const string YES_OPTION = "Y"; string oper = ""; string result; string answer; string number1 = Console.ReadLine(); 6
Level 1은객관식사지선다형으로출제예정 string number2 = Console.ReadLine(); int num1 = int.parse(number1); int num2 = int.parse(number2); Caculator calcus = new Calculator(num1, num2); Console.WriteLine("Add the numbers(y/n)?"); answer = Console.ReadLine(); if(answer!= YES_OPTION) result = calcus.claculatedifference(); oper = "-"; else result = calcus.calculatesum(); oper = "+"; Console.WriteLine("Our Calculation: 0 1 2 = 3", num1, oper, num2, result); 정답 : 7