물리 보고서 써야되는데,,,

우선 이것도 Chapter 1~2의 내용을 정리해 볼게,,,

Chapter 1. Introduction

이거는 간단히 프로그래밍이란 이런것이다... 니까 PASS!!

그래서 Chapter 2. using object로 넘어갈께,,

여기서는 "In Java, every value has a type" 이 말로 Chapter를 시작하지.

뭐 모든 프로그래밍 언어가 그렇지만 Java에서는 모든 value에는 type라는 형식을 매겨,

int, String, double등

int는 interger의 약자(?)로 정수형, String은 문자열 Class, double는 배정도 실수형이야.

그리고 JAVA는 본격적인 OOP 언어 답게 모든것을 Class단위로 처리해서

int luckyNumber;
luckyNumber = 13;
System.out.println(luckyNumber);
이런 소스가 나와
먼저
int luckyNumber;
이건 luckyNumber라는 정수형 변수를 선언하는거, 그밑에 luckyNumber = 13;이거는 13을 대입하라는거야,
그리고
System.out.println(luckyNumber);
이거는 System.out개체의 println메소드를 사용해서 luckyNumber변수의 값을 출력하라는거야.
근데 System.out.println 여기까지 쓰면 밑에나 옆에 "System.out.println(int 뭐시기)"라고 상자가 뜨고 거기에보면
"System.out.println(String 뭐시기)"도 있고 같은이름에 괄호속만 다른 뭐가 잔뜩 보이지?

이게 다 하나의 type에는 다른 type가 못들어 가거든? 그때 같은이름으로 다른 type도 받아들이기 위해 여러가지를 만든건데,, 이건 또 나중에,,,

"Objects are entities in your program that you manipulate by calling methods."

 이 말은 개체에는 메소드가 들어있다,,, 라고만 알면 되.

개체란 OOP의 기본인데, 사람이 움직이는것을 표현하는 프로그램을 만드는데,

사람의 손도 움직이고 발도 움직이고 해야 하잖아. 그리고 사람이 1사람이 아니면 여러개를 만들어야 하지?

이런 불편함을 없애기 위해서 사람class 를 만들어 놓고 사람A개체를 만들어서 사람A의 손을 움직여라

사람B의 손을 움직여라. 이렇게 하는거야. 이때 "사람A"는 개체  "손"은 데이터 "움직여라" 는 메소드가 되는거야

그래서 사람A.움직여라(손,15˚); 하면 사람A개체의 손이 15˚만큼 움직이게 되는거지.

그다음에 나오는것은 Method Parameters and Return Values인데,

Method Parameters 라는것은 아까 움직여라 메소드에 준 "손,15˚"을 뜻하는거고 Return Values는 수학의 함수값이라고 생각하면되.

수학에서 f(x)=y라고 하면 f는 메소드 x는 파라메터 y는 리턴값이지.

그다음 가장 중요한거는 오브젝트 생성인것 같은데,, 방법은 간단해. 원하는 클래스를 import한뒤에

Rectangle box = new Rectangle(5, 10, 20, 30);
이런식으로 생성하면 되.
 

'대학생활 > JAVA' 카테고리의 다른 글

내맘대로 강좌 JAVA편 4  (0) 2009.03.25
내맘대로 강좌 JAVA편 3  (0) 2009.03.25
3주차 JAVA숙제가 나왔습니다^^  (2) 2009.03.23
내맘대로 강좌 JAVA편 2  (0) 2009.03.16
2주차 JAVA숙제,,,(파일 삭제)  (0) 2009.03.15

먼저 Wiley교재의 Chapter1과 2를 설명할께,,

Chapter1. Introduction.

이 부분은 말 그대로 Introduction.

프로그래밍이란 이런것이다. 라고 소개하는 part니까 Pass.

그 다음은 Chapter2. Fundamental Data Types.

이 부분은 이제 C++의 기초를 시작하는거야.

먼저 예제 소스를 보자.

1  #include <iostream>
2
3  using namespace std;
4
5  int main()
6  {
7     int pennies = 8;
8     int dimes = 4;
9     int quarters = 3;
10
11    double total = pennies * 0.01 + dimes * 0.10
12       + quarters * 0.25; /* total value of the coins */
13
14    cout << "Total value = " << total << "\n";
15
16    return 0;
17  }
처음엔 이게 뭔소리야? 할 수 도 있지만 보자.(참고로 실제로 써보려면 맨앞의 줄번호는 지워야 한다는,,,)

1  #include <iostream>
using namespace std;

이 부분은 앞으로 iostream이라는 헤더에 쓰인 함수들을 갖다 쓰겠다는 선언과 std네임스페이스를 사용하겠다는 선언이야.
헤더라든지 함수라던지 네임스페이스는 앞으로 배울거니까 Pass!!

그 다음은
5  int main()

이건 프로그램이 실제로 시작되는 main함수의 선언이야 맨 앞의 int는 함수의 반환형이고, () <-이건 함수니까 인자가 들어간다는 표시지만, 공백은 아무것도 인자로 받지 않는다는 암시적인 표시. 명시적으로 하려면 int main(void) 이렇게 해야 되지만, 귀찮으면 Pass!!

이번 쳅터에서 가르치려는 핵심은 요고

7     int pennies = 8;
8     int dimes = 4;
9 int quarters = 3;
10
11    double total = pennies * 0.01 + dimes * 0.10
12       + quarters * 0.25; /* total value of the coins */

int는 4바이트 짜리 정수인 변수를 만들겠다는 거야.
정수라는 것은 중학교때 배운 바로 그 정수!! 소수점이 없는 수를 말하는건데 -2147483648~2147483647의 값을 저장할수 있어.

그리고 double는 실수형 이라고해서 실수 즉 소수점까지 나타내는 자료형이야. 하지만 지수꼴로 메모리에 근사적으로 저장을 해서 매우 작은(0.00000000001)같은것은 계산에 오차가 생기기도 한대,,,

그리고 변수라는것은 우리가 메모리에 그 쟈료형의 공간을 만들어서 앞으로 계속 써먹겠다는거야.
수학에서 x, y, a, b라고 쓰는 것 처럼,,, 그리고

9 int quarters = 3;

처럼 하는것을 선언하면서 초기화한다 라고 하고,

9 int quarters;
10 quaters = 3;

이렇게 하는것을 선언따로 초기화 따로라고 해.
그럼

11    double total = pennies * 0.01 + dimes * 0.10
12       + quarters * 0.25; /* total value of the coins */

이것은 뭐냐?라고 하면, C++이나 JAVA는 모두 형식이 자유로운 free form 언어거든?
그래서 아무대나 엔터치고 아무대나 띄워써도 다 인식을 해

(하지만 변수나 함수이름에 띄워쓰기나 엔터는 오류난다는거,,,)
ex)
total=1;                  (o)
total                =1;  (o)

to        tal = 1;        (x)

한마디로 total을 선언하면서 total의 값으로

pennies * 0.01 + dimes * 0.10 + quarters * 0.25 을 넣어준다는 거야.

그 다음에 나오는

14    cout << "Total value = " << total << "\n";
이거는 cout이라는 개체가 있거든? (C++은 개체지향언어(OOP)잖아) 그거에 << 함수를 오버로딩 한건데,,, 이건 넘어가고,

"Total value = "이라는 글씨와 total이라는 변수의 값을 출력하고"\n"은 한줄 띄운것의 기호니까 실제 표시는

Total value = 1.23¶

이렇게 되겠지,,,

'대학생활 > C++' 카테고리의 다른 글

내맘대로 강좌 C++편 5  (2) 2009.03.19
내맘대로 강좌 C++편 4  (2) 2009.03.18
내맘대로 강좌 C++편 3  (4) 2009.03.17
내맘대로 강좌 C++편 2  (1) 2009.03.17
2주차 C++숙제,,(파일 삭제)  (0) 2009.03.15

일단,,, 주목적은 포스팅 수를 늘이기위해,,, 다 같이 공부를 하기 위해서 이니까,,,

오타나 오류같은것이 있으면 언제든지 태클!!!

일단 나는 90이지만,,, 인터넷상이고,,, 볼사람도 별로 없을것 같으므로,

말은 놓겠습니다..

그럼 이제부터 달리겠어!!!

'대학생활' 카테고리의 다른 글

지금은 집 입니다.  (0) 2009.12.22
UNIST 2009년 2학기 기말고사 시간표  (0) 2009.12.05
내맘대로 강좌 공지!!!  (1) 2009.03.25
내맘대로 강좌 공통편 1  (0) 2009.03.20
학생증 드디어 나왔습니다!!!  (0) 2009.03.16

You are supposed to make two simple programs in this week.

1. Based on the rectangle class example in our text book, add "intersection method" to the rectangle class. The intersection method returns the intersection of two rectangles, that is the rectangle formed by two overlapping rectangles.

You call this method as follows:

Rectangle r3 = r1.intersection(r2);

r3 is the intersection rectangle formed by r1 and r2.

Write a program IntersectionPrinter that constructs two rectangle objects, prints them, and then prints the rectangle object that describes the intersection. Then the program should print the result of the intersection method when the rectangles do not overlap. Add a comment to your program that explains how you can tell whether the resulting rectangle is empty.

2. Write a program HollePrinter that switches the letters "e" and "o" in a string. Use the replace method repeatedly. You don't need to get inputs from console or GUI. Place the input in your code (For example String input = "Hello, World"). Demonstrate that the string "Hello, World!" turns into "Holle, Werld!".

내용은 요렇게,,,

역시 파일은 여기(였는데,,, due가 넘어가는바람에 검열당한,,,)

'대학생활 > JAVA' 카테고리의 다른 글

내맘대로 강좌 JAVA편 4  (0) 2009.03.25
내맘대로 강좌 JAVA편 3  (0) 2009.03.25
3주차 JAVA숙제가 나왔습니다^^  (2) 2009.03.23
내맘대로 강좌 JAVA편 2  (0) 2009.03.16
내맘대로 강좌 JAVA편 1  (3) 2009.03.16

You need to set up a C++ compiler in your computer. I recommend Microsoft Vistual C++ Express. It is free. Another option is using Cygwin G++ compiler, which is also free.

In this week, you will make three simple programs.

1. Write a program that asks the user for the lengths of the sides of a rectangle. Then print

The area and perimeter of the rectangle
 
The length of the diagonal (use the Pythagorean theorem)
 

2. Write a program that prompts the user for the names and salaries of three employees. Then print out the average salaries of the employees. Information about each employee must be stored in an employee object.

3. Write a program that reads a number greater than or equal to 1,000 from the user and prints it out with a comma separating the thousands. Here is a sample dialog; the user input is in color:

    Please enter an integer >= 1000:  23456    23,456

내용은 대략 요거,,,

내 풀이는,,,, 이거참조(였는데,,, due가 길어져서 검열당한,,,)

'대학생활 > C++' 카테고리의 다른 글

내맘대로 강좌 C++편 5  (2) 2009.03.19
내맘대로 강좌 C++편 4  (2) 2009.03.18
내맘대로 강좌 C++편 3  (4) 2009.03.17
내맘대로 강좌 C++편 2  (1) 2009.03.17
내맘대로 강좌 C++편 1  (0) 2009.03.16