C++숙제,,, 대학생활/C++ 2009. 4. 9. 17:56

이제 C++패스했다고, 점점 귀찮아 집니다....ㄷㄷ

1. Julian dates. Suppose you would like to know how many days ago Columbus was born. It is tedious to figure this out by hand, because months have different lengths and because you have to worry about leap years. Many people, such as astronomers, who deal with dates a lot have become tired of dealing with the craziness of the calendar and instead represent days in a completely different way: the so-called Julian day number. That value is defined as the number of days that have elapsed since Jan. 1, 4713 B.C. A convenient reference point is that October 9, 1995, is Julian day 2,450,000.

Here is an algorithm to compute the Julian day number: Set jd, jm, jy to the day, month, and year. If the year is negative, add 1 to jy. (There was no year 0. Year 1 B.C. was immediately followed by year A.D. 1) If the month is larger than February, add 1 to jm. Otherwise, add 13 to jm and subtract 1 from jy. Then compute

long jul = floor(365.25 * jy) + floor(30.6001 * jm) + d + 1720995.0

We store the result in a variable of type long; simple integers may not have enough digits to hold the value. If the date was before October 15, 1582, return this value. Otherwise, perform the following correction:

int ja = 0.01 * jy;

jul = jul + 2 - ja + 0.25 * ja;

Now write a function

long julian(int year, int month, int day)

that converts a date into a Julian day number. Use that function in a program that prompts the user for a date in the past, then prints out how many days that is away from today's date.

이게 1번문제 이고

 

2. Write a procedure void sort2(int& a, int& b) that swaps the values of a and b if a is greater than b and otherwise leaves a and b unchanged. For example,

int u = 2;

int v = 3;

int w = 4;

int x = 1;

sort2(u, v);

/* u is still 2, v is still 3 */

sort2(w, x);

/* w is now 1, x is now 4 */
이게 2번인데,,,
1번은 무슨 juliandate라는 만년력을 구하라는 문제 같고,,
2번은 간단히 크기가 작은것을 앞으로 큰것을 뒤로 보내는 문제 같네여,, C++은 BB를 보시면 교수님의 ppt도 있고, wiley에 보시면 교재도 있으니,, 참조변수에 관한것을 좀 보시는것이 도움이 되겠네요,,