Search

'실습과제 모음'에 해당되는 글 60건

  1. 2012.07.23 CPP Chapter 03 실습
  2. 2012.07.22 CPP 0722 실습과제
  3. 2012.07.20 방학특강 C 언어 주말과제 0720~0723
  4. 2012.07.18 JRadioButtonTest
  5. 2012.07.18 JCheckBoxTest
  6. 2012.07.17 java 실습 0717
  7. 2012.07.14 JAVA ComboBoxTest
  8. 2012.07.14 CPP 실습문제 0714
  9. 2012.07.11 JAVA 0711 실습과제
  10. 2012.07.11 C 언어 실습문제

CPP Chapter 03 실습

실습과제 모음 2012. 7. 23. 13:21 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

1.     다음 조건을 논리 연산자를 이용해서 하나의 if 문으로 완성해보자.

if( x > 2 ) {

    if ( y > 2 ) {

        z = x + y;

        cout << "z = " << z << endl;

    }

}

else

{

    cout << "x = " << x << endl;

}

2.     아래 네모 안 코드의 의미를 적고 switch 내용을 if ~ else로 변경해보자.

#include <iostream>

using namespace std;

 

int main()

{

    int score;

    char grade;

    do {

        cout << "점수입력: ";

        cin >> score;

    } while ( score > 100 || score < 0 );

 

    switch(score/10)

    {

    case 10:

    case 9:

        grade = 'A';

        break;

    case 8:

        grade = 'B';

        break;

    case 7:

        grade = 'C';

        break;

    default:

        grade = 'F';

        break;

    }

 

    cout << "grade = " << grade << endl;

 

    return 0;

}

 

3.     다음 두 프로그램의 결과를 적고 결과가 다른 이유를 설명하라.

#include <iostream>

using namespace std;

 

int main()

{

    for ( int i = 0 ; i < 5 ; i++ )

    {

        cout << "i=" << i << endl;

        cout << "*********************" << endl;

    }

    return 0;

}

#include <iostream>

using namespace std;

 

int main()

{

    for ( int i = 0 ; i < 5 ; i++ ) 

        cout << "i=" << i << endl;

        cout << "*********************" << endl;

   

    return 0;

}

 

4.     다음 프로그램에서 continue 문을 사용해 3의 배수와 5의 배수만 출력하도록 완성하라.

#include <iostream>

using namespace std;

 

int main()

{

    int n;

    for( n = 0 ; n < 20 ; n++ )

    {

 

        // TODO:

 

 

    }

    return 0;

}

 

 

'실습과제 모음' 카테고리의 다른 글

CPP 실습과제 0724 배열, 함수  (0) 2012.07.24
CPP 주민등록번호 분석기  (0) 2012.07.23
CPP 0722 실습과제  (0) 2012.07.22
방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20
JRadioButtonTest  (0) 2012.07.18

CPP 0722 실습과제

실습과제 모음 2012. 7. 22. 13:17 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>
#include <string>
using namespace std;


class ImaginaryNumber
{
public:
 int real;
 int imag;
 ImaginaryNumber(int r, int i)
 {
  real = r;
  imag = i;
 }
 void Display()
 {
  if(imag > 0 )
  {
   cout << real << " +" << imag << " * i"<< endl;
  }
  else
  {
   cout << real << " " << imag << " * i"<< endl;
  }
 }
 ImaginaryNumber operator*(const ImaginaryNumber object)
 {
  // 계산    1
  // 계산결과 리턴 2
  ImaginaryNumber temp;
  temp.real = ?;
  temp.imag = ?;
  return temp;
 }
};
int main( )

 ImaginaryNumber iNum1 ( 3 , 2 ); // 3 + 2i
 ImaginaryNumber iNum2 ( 4 , -3 ); // 4 - 3i

 iNum1.Display(); // 3 +2 * i
 iNum2.Display(); // 4 +-3 * i

 ImaginaryNumber iNum3 = iNum1 * iNum2;

 iNum3.Display(); // 18 +-1 * i

 return 0;
}

 

'실습과제 모음' 카테고리의 다른 글

CPP 주민등록번호 분석기  (0) 2012.07.23
CPP Chapter 03 실습  (0) 2012.07.23
방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20
JRadioButtonTest  (0) 2012.07.18
JCheckBoxTest  (0) 2012.07.18
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

첨부파일에 있는 실습문제를

 

주말동안 해보세요

C 언어 커리큘럼 요약.doc

'실습과제 모음' 카테고리의 다른 글

CPP Chapter 03 실습  (0) 2012.07.23
CPP 0722 실습과제  (0) 2012.07.22
JRadioButtonTest  (0) 2012.07.18
JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17

JRadioButtonTest

실습과제 모음 2012. 7. 18. 18:08 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

import javax.swing.*;

import javax.swing.border.Border;

 

import java.awt.event.*;

import java.awt.*;

 

class MyFrame extends JFrame implements ActionListener {

 

       private JRadioButton small, medium, large;

       private JLabel text;

       private JPanel topPanel, sizePanel, resultPanel;

 

       public MyFrame() {

             setTitle("라디오 버튼 테스트");

             setSize(300, 150);

             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

             topPanel = new JPanel();

             JLabel label = new JLabel("어떤 크기의 커피를 주문하시겠습니까?");

             topPanel.add(label);

             add(topPanel, BorderLayout.NORTH);

 

          sizePanel = new JPanel();

             small = new JRadioButton("Small Size");

             medium = new JRadioButton("Medium Size");

             large = new JRadioButton("Large Size");

 

             ButtonGroup size = new ButtonGroup();

             size.add(small);

             size.add(medium);

             size.add(large);

             small.addActionListener(this);

             medium.addActionListener(this);

             large.addActionListener(this);

             sizePanel.add(small);

             sizePanel.add(medium);

             sizePanel.add(large);

             add(sizePanel, BorderLayout.CENTER);

 

             resultPanel = new JPanel();

             text = new JLabel("크기가 선택되지 않았습니다.");

             text.setForeground(Color.red);

             resultPanel.add(text);

             add(resultPanel, BorderLayout.SOUTH);

             setVisible(true);

       }

public void actionPerformed(ActionEvent e) {

             if (e.getSource() == small) {

                    text.setText("Small 크기가 선택되었습니다.");

             }

             if (e.getSource() == medium) {

                    text.setText("Medium 크기가 선택되었습니다.");

             }

             if (e.getSource() == large) {

                    text.setText("Large 크기가 선택되었습니다.");

             }

       }

}

 

public class RadioButtonTest extends JFrame {

       public static void main(String[] args) {

             new MyFrame();

       }

 }

'실습과제 모음' 카테고리의 다른 글

CPP 0722 실습과제  (0) 2012.07.22
방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20
JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14

JCheckBoxTest

실습과제 모음 2012. 7. 18. 17:52 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.applet.Applet;

 

import javax.swing.*;

 

class MyFrame extends JFrame implements ActionListener {

 

       private JButton buttonOK;

       private JCheckBox onion, cheese, tomato;

 

       public MyFrame() {

             setTitle("체크박스 테스트");

             setSize(300, 130);

             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

             JLabel label = new JLabel("햄버거에 무엇을 추가하시겠습니까?");

             JPanel topPanel = new JPanel();

             topPanel.add(label);

             add(topPanel, BorderLayout.NORTH);

  // 체크 박스 생성 추가

             JPanel panel = new JPanel();

             onion = new JCheckBox("양파");

             panel.add(onion);

             cheese = new JCheckBox("치즈");

             panel.add(cheese);

             tomato = new JCheckBox("토마토");

             panel.add(tomato);

             add(panel, BorderLayout.CENTER);

 

             // 버튼 생성 추가

             buttonOK = new JButton("OK");

             JPanel bottomPanel = new JPanel();

             bottomPanel.add(buttonOK);

             add(bottomPanel, BorderLayout.SOUTH);

             buttonOK.addActionListener(this);

 

             setVisible(true);

       }

 

public void actionPerformed(ActionEvent e) {

             if (e.getSource() == buttonOK) {

                    String msg = "";

                    if (onion.isSelected())

                           msg += "양파\n";

                    if (cheese.isSelected())

                           msg += " 치즈";

                    if (tomato.isSelected())

                           msg += " 토마토";

                    msg = "선택한 옵션은 다음과 같습니다.\n " + msg;

                    System.out.println(msg);

                    onion.setSelected(false);

                    cheese.setSelected(false);

                    tomato.setSelected(false);

             }

       }

}

 

public class JCheckBoxTest extends JFrame {

       public static void main(String[] args) {

             new MyFrame();

       }

}

'실습과제 모음' 카테고리의 다른 글

방학특강 C 언어 주말과제 0720~0723  (0) 2012.07.20
JRadioButtonTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14

java 실습 0717

실습과제 모음 2012. 7. 17. 17:16 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import javax.swing.*;
 
import java.awt.*;
import java.awt.event.*;
 
class MyFrame extends JFrame implements MouseListener, MouseMotionListener {
 
       public MyFrame() {
             setTitle("Mouse Event");
             setSize(300, 200);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
             JPanel panel = new JPanel();
             panel.addMouseListener(this);
             panel.addMouseMotionListener(this);
             add(panel);
             setVisible(true);
 
       }
       public void mousePressed(MouseEvent e) {
           display("Mouse pressed (# of clicks: " + e.getClickCount() + ")", e);
     }

     public void mouseReleased(MouseEvent e) {
           display("Mouse released (# of clicks: " + e.getClickCount() + ")", e);
     }

     public void mouseEntered(MouseEvent e) {
           display("Mouse entered", e);
     }

     public void mouseExited(MouseEvent e) {
           display("Mouse exited", e);
     }

     public void mouseClicked(MouseEvent e) {
           display("Mouse clicked (# of clicks: " + e.getClickCount() + ")", e);
     }
     protected void display(String s, MouseEvent e) {
         System.out.println(s + " X=" + e.getX() + " Y=" + e.getY());
   }

   public void mouseDragged(MouseEvent e) {
         display("Mouse dragged", e);
   }

   public void mouseMoved(MouseEvent e) {
         display("Mouse moved", e);
        
   }
}

public class MyFrameTest5 {
   public static void main(String[] args) {
         MyFrame f=new MyFrame();
   }
}

'실습과제 모음' 카테고리의 다른 글

JRadioButtonTest  (0) 2012.07.18
JCheckBoxTest  (0) 2012.07.18
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11

JAVA ComboBoxTest

실습과제 모음 2012. 7. 14. 15:54 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ComboBoxTest extends JFrame implements ActionListener {
 JLabel label;

 public ComboBoxTest() {
  setTitle("콤보 박스");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setSize(300, 200);

  String[] animals = { "dog", "lion", "tiger" };
  JComboBox animalList = new JComboBox(animals);
  animalList.setSelectedIndex(0);
  animalList.addActionListener(this);

  label = new JLabel();
  label.setHorizontalAlignment(JLabel.CENTER);
  changePicture(animals[animalList.getSelectedIndex()]);
  add(animalList, BorderLayout.PAGE_START);
  add(label, BorderLayout.PAGE_END);
  setVisible(true);
 }

 public void actionPerformed(ActionEvent e) {
  JComboBox cb = (JComboBox) e.getSource();
  String name = (String) cb.getSelectedItem();
  changePicture(name);
 }

 protected void changePicture(String name) {
  ImageIcon icon = new ImageIcon(name + ".gif");
  label.setIcon(icon);
  if (icon != null) {
   label.setText(null);
  } else {
   label.setText("이미지가 발견되지 않았습니다.");
  }
 }

 public static void main(String[] args) {
  ComboBoxTest frame = new ComboBoxTest();
 }
}

 

 

 

 

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
CPP 실습문제 0714  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11
C 언어 실습문제  (0) 2012.07.11

CPP 실습문제 0714

실습과제 모음 2012. 7. 14. 11:32 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>
using namespace std;

class Weight
{
public :
 void setHeight(const double h);
 void setWeight(const double h);
 double getHeight();
 double getWeight();
 int    getWeightStatus();

private :
 int    StdWeight();
 double height, weight;
 int    WeightStatus;
};


void Weight::setHeight(const double h)
{
}

void Weight::setWeight(const double w)
{
}

double Weight::getHeight()
{
}

double Weight::getWeight()
{
}

int Weight::StdWeight()
{
 double sw=(height-110)*0.9;

 if (sw+0.5 < weight)
  WeightStatus=1;
 else if (sw-0.5 > weight)
  WeightStatus=-1;
 else
  WeightStatus=0;

 return 1;
}

int Weight::getWeightStatus()
{
}

int main()
{
 Weight w1; 
 w1.setHeight(175);
 w1.setWeight(87.5);
 cout << w1.getHeight() << "키에 몸무게 ";
 cout << w1.getWeight() << "는 ";
 switch (w1.getWeightStatus())
 {
 case 1:
  cout << "과체중";
  break;
 case 0 :
  cout << "정상";
  break;
 case -1:
  cout << "저체중";
  break;
 default:
  ;
 }
 cout << " 입니다." << endl;

 return 0;
}

 

include.dotx

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11
C 언어 실습문제  (0) 2012.07.11

JAVA 0711 실습과제

실습과제 모음 2012. 7. 11. 18:33 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


  /*
  ex) 3입력시
    * 1
   *** 2
  ***** 3
   *** 2
    * 1
  */

public class TestClass {
 public static void main(String[] args) throws IOException {

  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  int i, j, k;

  System.out.print("입력 :");
  i = Integer.parseInt(in.readLine());
  
  System.out.println("i = " + i);
  
  // 위부분 출력
  for(k = 1; k <= i ; k++ )
  {
   for(j = 0; j < i - k; j++)
   {
    System.out.print(" ");
   }
   for(j = 0; j < 2*k-1; j++)
   {
    System.out.print("*");
   }
   System.out.print("\n");
  }
  
  
  // 아래부분 출력
  for(k = 1; k <= i ; k++ )
  {
   for(j = 0; j < i - k; j++)
   {
    System.out.print(" ");
   }
   for(j = 0; j < 2*k-1; j++)
   {
    System.out.print("*");
   }
   System.out.print("\n");
  }
  
  
  /*

  for (j = 0; j < i; j++) {
   System.out.print("*");
  }

  System.out.print("\n");

  for (j = 0; j < i; j++) {
   System.out.print("*");
   System.out.print("\n");
  }
  */

 }
}

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14
C 언어 실습문제  (0) 2012.07.11

C 언어 실습문제

실습과제 모음 2012. 7. 11. 15:09 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C 언어 실습문제

 

문제 

세자리 정수를 입력받아 각 자리수를 출력하고 각 자리수가 짝수인지 홀수인지 출력하시오.

코드

#include <stdio.h>

int main(void)

{

   int num;

 

   printf("세자리 정수를 입력하세요 : ");

 

   scanf("%d", &num);

 

   printf("일의 자리수 : %d \n", num % 10);

 

   printf("십의 자리수 : %d \n", num / 10 % 10);

 

   printf("백의 자리수 : %d \n", num / 100);

 

   if( (num % 10) % 2 == 0 )

   {

       printf("일의 자리수는 짝수\n");

   }

   else

   {

       printf("일의 자리수는 홀수\n");

   }

 

   if( (num / 10 % 10) % 2 == 0 )

   {

       printf("십의 자리수는 짝수\n");

   }

   else

   {

       printf("십의 자리수는 홀수\n");

   }

 

   if( (num / 100) % 2 == 0 )

   {

       printf("백의 자리수는 짝수\n");

   }

   else

   {

       printf("백의 자리수는 홀수\n");

   }

 

   return 0;

}

 

 

'실습과제 모음' 카테고리의 다른 글

JCheckBoxTest  (0) 2012.07.18
java 실습 0717  (0) 2012.07.17
JAVA ComboBoxTest  (0) 2012.07.14
CPP 실습문제 0714  (0) 2012.07.14
JAVA 0711 실습과제  (0) 2012.07.11