C 201 Schedule of First Two Weeks Review

  • Slides: 7
Download presentation
C 201 Schedule of First Two Weeks: Review of C 101 ¨ Week 1

C 201 Schedule of First Two Weeks: Review of C 101 ¨ Week 1 ¨ Functions ¨ Array and sorting ¨ Week 2 ¨ C-String ¨ An application 5 -1

Program 1: Determine the day of a week This is formula to determine the

Program 1: Determine the day of a week This is formula to determine the day of a week given the date information W = (k + floor(2. 6*m - 0. 2) – 2*C + Y + floor(Y/4. 0) + floor(C/4. 0)) % 7 Where ¨ floor() denotes the integer floor function, ¨ k is day (1 to 31), ¨ m is month (1 = March, . . . , 10 = December, 11 = Jan, 12 = Feb), treat Jan & Feb as months of the preceding year, ¨ C is century (1987 has C = 19, 2000 has C=20 except C=19 for Jan & Feb), ¨ Y is year (1987 has Y = 87 except Y = 86 for Jan & Feb), ¨ W is week day (0 = Sunday, . . . , 6 = Saturday), if W is less than 0, add 7. 5 -2

Program 2 Any even number larger than 2 can be expressed as the sum

Program 2 Any even number larger than 2 can be expressed as the sum of two prime numbers (Goldbach's conjecture). Write a program that takes input of an even integer number n (larger than or equal to 4) and find two prime numbers p 1 and p 2, such that n = p 1 + p 2, and print p 1 and p 2. For example, 10 = 3 + 7, or 8 = 3 + 5, or 20 = 13 + 7. 5 -3

Program 3 Any integer number larger than 5 can be expressed as the sum

Program 3 Any integer number larger than 5 can be expressed as the sum of three prime numbers (Goldbach's conjecture). Write a program that takes input of an integer number n (larger than or equal to 6) and find three prime numbers p 1, p 2, and p 3 such that n = p 1 + p 2 +p 3, and print p 1, p 2, and p 3. For example, 6 = 2 + 2, or 8 = 3 + 2 + 3, 11 = 3 + 5 5 -4

Array in C++ ¨ Size and index ¨ Search an array ¨ Sort an

Array in C++ ¨ Size and index ¨ Search an array ¨ Sort an array 5 -5

C-String ¨ The ending mark: the ‘�’character ¨ C-String functions ¨ strlen() ¨ strcmp()

C-String ¨ The ending mark: the ‘’character ¨ C-String functions ¨ strlen() ¨ strcmp() ¨ Strcpy() ¨ Strcat() ¨ Implementations 5 -6

An Application ¨ Write a program that asks a user to enter his/her first

An Application ¨ Write a program that asks a user to enter his/her first name, year of birth, and weight (in pounds) in one line separated with spaces. The program should show if the user is overweight using the following formula Age ≤ than 5 >5 Weight ≥ 98. 5 < 98. 5 ≥ 198. 5 Result Overweight Can not tell Overweight <198. 5 Can not tell 5 -7