All posts by kpark

체감온도


  • 체감온도는 외부에 있는 사람이나 동물이 바람과 한기에 노출된 피부로부터 열을 빼앗길 때 느끼는 추운 정도를 나타내는 지수임
  • 바람이 강해질수록 피부의 열 손실률은 높아지게 되며 결국 내부체온을 떨어뜨리게 됨. 예를 들어 영하 10℃에서 풍속이 5km/h일 때 체감온도는 영하 13℃이지만 풍속이 30km/h가 되면 체감온도가 영하 20℃까지 떨어져 강한 추위를 느끼게 됨

산출방법



수식


* 현재 사용하고 있는 체감온도 산출식은 2001년 8월 캐나다 토론토에서 열린 Joint Action Group for Temperature Indices (JAG/TI) 회의에서 발표된 것으로 미국과 캐나다 등 북아메리카 국가들을 중심으로 최근에 가장 널리 사용되고 있음


단계별 설명및 주의사항


























단계 지수범위 설명 및 주의사항
위험 -45 미만

노출된 피부는 몇분내에 얼게 되고, 야외 활동시 저체온 위험이 매우 크므로 방풍·보온기능이 있는 매우 따뜻한 겹옷을 착용해야 함. 또한 노출된 모든 피부를 덮고 모자, 벙어리장갑, 스카프, 목도리, 마스크의 착용이 필요함. 야외환경은 생명에 매우 위험하므로 야외활동은 가급적 짧게 하거나 취소하여 실내에 머무를 수 있도록 할 것.

경고 -45~-25 미만 10~15분이내 동상 위험이 있고, 보호장구 없이 장기간 노출시 저체온에 빠질 위험이 크므로 방풍기능이 있는 겹옷이나 따뜻한 겹옷을 착용해야함. 또한 노출된 모든 피부를 덮고 모자, 벙어리장갑, 스카프, 목도리, 마스크의 착용이 필요함. 피부가 바람에 직접 노출되지 않도록 할 것
주의 -25~-10 미만 노출된 피부에 매우 찬 기운이 느껴지고, 보호장구 없이 장기간 노출시 저체온에 빠질 위험이 있으므로 방풍기능이 있는 겹옷이나 따뜻한 옷을 착용해야함. 또한 모자, 벙어리장갑, 스카프의 착용이 필요함
관심 -10 이상 추위를 느끼는 정도가 증가함. 긴 옷이나 따뜻한 옷의 착용이 필요함

 

HW1

연습문제 (1)





단원 : C# 기초


목표 : C# 프로그램 기초


주요 연습 내용 : Visual Studio 2010, C# 입출력, 변수, 메소드, 제어문 사용 연습


준비자료 : WindChillTemperatureCalculator.cs


기상청 체감온도산출법  http://www.kma.go.kr/HELP/basic/help_01_07.jsp


연습문제 Ex1 (Due by 9/27 24시까지)


-cyber 강의실 (cyber.dku.edu)source code, executable file, solution/project VC# file, 보고서를 학번_이름_Ex1.zip으로 묶어서 낼 것. 보고서 (30%)


 


[연습문제]


0. Visual C# Console Application의 프로젝트를 생성한다.


1. 체감온도계산기 WindChillTemperatureCalculator 클래스를 작성하라. (30%)


enum WindChillTemperatureIndex { DANGER, WARNING, CAUTION, AWARE };


– void GetKeyboardInput() 콘솔창에서 키보드로 기온, 풍속을 입력받아서 처리


+ 힌트: while 문을 사용하여 사용자가 잘못 입력했을 경우 다시 입력 가능하도록 함


+ 힌트: Console.ReadLine() string을 반환하므로, double로 변환하기 위하여


TryParse 함수 사용 => boolValue = double.TryParse(string, out doubleValue)


– void PrintWindChillTemperature() 체감온도와 체감온도지수를 화면에 출력


double GetWindChillTemperature(double T, double V) 체감온도 값을 반환


WindChillTemperatureIndex GetWindChillTemperatureIndex(double T) 체감온도 지수를 반환


ConsoleColor GetWindChillTemperatureIndexColor(WindChillTemperatureIndex index) 체감온도지수 경보색을 반환


2. WindChillTemperatureCalculator 클래스에 PrintWindChillTemperatureIndexTable() 메소드를 추가하라. (20%)


체감온도 산출표를 출력함 (테이블의 형식으로 색깔까지 맞춰서)


3. Main 함수에서는 WindChillTemperatureCalculator 객체를 생성하고 체감온도 산출표와 사용자 입력을 받아서 체감온도를 출력하거나 등 routine을 추가한다. (20%)


– do..while 문을 사용하여 계속해서 다른 계산을 할 수 있도록 함


그리고, 본인이 더 테스트해보고 싶은 메소드나 루틴을 추가함

사용자 삽입 이미지

C# Formatting Numeric String

Formatting Standard Numeric Format Strings
http://msdn.microsoft.com/en-us/library/s8s7t687(VS.80).aspx

Formatting Custom Numeric Format Strings
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Formatting Numeric Format Strings (Alignment)
Integer    http://www.csharp-examples.net/string-format-int/
Double    http://www.csharp-examples.net/string-format-double/
DateTime http://www.csharp-examples.net/string-format-datetime/
Align String with Spaces  http://www.csharp-examples.net/align-string-with-spaces/
Indent String with Spaces http://www.csharp-examples.net/indent-string-with-spaces/
IFormatProvider               http://www.csharp-examples.net/iformatprovider-numbers/
Custom IFormatProvider   http://www.csharp-examples.net/custom-iformatprovider/

























































Character Description Examples Output
C or c Currency Console.Write(“{0:C}”, 2.5); $2.50
Console.Write(“{0:C}”, -2.5); ($2.50)
D or d Decimal Console.Write(“{0:D5}”, 25); 25
E or e Scientific Console.Write(“{0:E}”, 250000); 2.50E+05
F or f Fixed-point Console.Write(“{0:F2}”, 25); 25
Console.Write(“{0:F0}”, 25); 25
G or g General Console.Write(“{0:G}”, 2.5); 2.5
N or n Number Console.Write(“{0:N}”, 2500000); 2,500,000.00
X or x Hexadecimal Console.Write(“{0:X}”, 250); FA
Console.Write(“{0:X}”, 0xffff); FFFF

 

int => string vs string => int

// integer => string type conversion
int i = 10;                    // 10
string j = i.ToString(); // “10”



// string => integer type conversion
string x = “123”;          // “123”
int y = Convert.ToInt32(x); // 123 (integer로 변환이 가능한 경우만 변환 가능 그 외엔 run-time exception error)
int z = Int32.Parse(x); // 123 (integer로 변환이 가능한 경우만 변환 가능 그 외엔 run-time exception error)
int w;
bool success = Int32.TryParse(x, out w); // 123 (integer로 변환이 가능한 경우만 변환 가능 그 외엔 w=0)

C# Struct

C++에서는 struct와 class간에 차이가 거의 없으며, 차이점은 아무런 명시를 하지 않았을 때 class는 멤버가 private 권한을 가지고, struct는 멤버가 public 권한을 가진다.

C#에서는 struct와 class가 유사하나 매우 다른 특징을 가진다.
-C# struct는 Value Type (값 형식)으로, 즉 stack영역에 데이터를 생성해서 사용함
-C# struct는 Default Constructor (기본생성자)나 Destructor(소멸자)선언할 수 없음
-C# struct는 다른 struct/class를 상속받을 수 없으며 파생시킬수도 없음 (따라서, protected는 선언할 수 없음)
-C# struct는 interface를 구현할 수 있음
-C# struct는 nullable type으로 사용할 수 있음
-C# struct는 일반적으로 new를 사용해서 객체를 생성하나 (예: Person p = new Person();), stack영역에 데이터를 생성해서 사용함

public struct Point
{
int x = 1; //Illegal: cannot initialize field
int y;

public Point() { } //Illegal: cannot have parameterless constructor
public Point(int x) { this.x = x; } //Illegal: must assign field y
}


http://www.codeproject.com/Articles/8612/Structs-in-C

Convert.ToIn32 vs Int32.Parse vs Int32.TryParse

http://www.codeproject.com/KB/cs/AgileWare_Convert_Int32.aspx

Convert.ToInt32(string s)는 내부적으로 Int32.Parse(string s)을 불러서 string을 32-bit signed integer로 변환시켜주는 메소드

string s1 = 1234″;
string s2 = 1234.65″;
string s3 = null;
string s4 = 123456789123456789123456789123456789123456789″;

int result;
bool success;

result = Convert.ToInt32(s1); //— 1234
result = Convert.ToInt32(s2); //— FormatException
result = Convert.ToInt32(s3); //— 0
result = Convert.ToInt32(s4); //— OverflowException

Int32.Parse(string s)는 strng을 32-bit signed integer로 변환시켜주는 메소드
그러나 만약 s가 null일 경우 ArgumentNullException을 냄
또한 s가 integer가 아닐 경우 FormatException을 냄
또한 s가 integer의 MinValue또는 MaxVale를 넘칠 경우 OverflowException을 냄

result = Int32.Parse(s1); //— 1234
result = Int32.Parse(s2); //— FormatException
result = Int32.Parse(s3); //— ArgumentNullException
result = Int32.Parse(s4); //— OverflowException


Int32.TryParse(string s, out int i)는 string을 32-bit signed integer로 변환하여 out 에 보내주는 메소드로 성공하면 true를 반환
따라서 만약 s가 null일 경우 ArgumentNullException을 내지않고 false와 out으로 0을 반환
또한 s가 integer가 아닐 경우 FormatException을 내지않고 false와 out으로 0을 반환
또한 s가 integer의 MinValue또는 MaxVale를 넘칠 경우 OverflowException을 내지않고 false와 out으로 0을 반환


success = Int32.TryParse(s1, out result); //— success => true; result => 1234
success = Int32.TryParse(s2, out result); //— success => false; result => 0
success = Int32.TryParse(s3, out result); //— success => false; result => 0
success = Int32.TryParse(s4, out result); //— success => false; result => 0

Boxing과 Unboxing을 최소화하라

Boxing은 값 형식 (value type)을 참조 형식 (reference type)으로 변경하는 것이다.
Boxing을 수행하면 힙 상에 새로운 reference type 객체가 생성되고 value type의 객체가 가지고 있던 값이 reference type 객체 내부로 복사된다.
새로 생성된 reference type 객체는 내부적으로 value type 객체의 복사본을 포함하고, value type에서 제공하였던 interface를 그대로 재구현한다.

Unboxing은 참조 형식 (reference type)을 값 형식 (value type)으로 변경하는 것이다.
만약 reference type 객체 내부에 포함된 value type 객체의 값을 얻고자 시도하면 복사본을 만들어서 돌려준다.

Console.WriteLine(“Numbers: {0}, {1}, {2}”, 10, 20, 30);
Console.WriteLine()은 System.Object의 배열을 인자로 받는데, 정수들은 모두 value type이기때문에 value type의 인자로 전달하기 위해서는 reference type으로 boxing이 수행된다.
Boxing과 Unboxing 동작은 필요시 자동적으로 일어나며, 이 과정에서 컴파일러는 어떠한 경고도 발생시키지 않는다. WriteLine(…)을 호출할 때에는, 아래와 같이 value type을 string type instance로 변경하는 것이 좋다.
Console.WriteLine(“Numbers: {0}, {1}, {2}”, 10.ToString(), 20.ToString(), 30.ToString());
이 코드는 string type을 사용하기 때문에 value type들은 더이상 System.Object 로 변경되지 않는다.