1 / 7

C201 Schedule of First Two Weeks: Review of C101

C201 Schedule of First Two Weeks: Review of C101. Week 1 Functions Array and sorting Week 2 C-String An application. Program 1: Determine the day of a week. This is formula to determine the day of a week given the date information

Download Presentation

C201 Schedule of First Two Weeks: Review of C101

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C201 Schedule of First Two Weeks: Review of C101 • Week 1 • Functions • Array and sorting • Week 2 • C-String • An application

  2. 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.

  3. 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 p1 and p2, such that n = p1 + p2, and print p1 and p2. For example, 10 = 3 + 7, or 8 = 3 + 5, or 20 = 13 + 7.

  4. 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 p1, p2, and p3 such that n = p1 + p2 +p3, and print p1, p2, and p3. For example, 6 = 2 + 2 + 2, or 8 = 3 + 2 + 3, 11 = 3 + 3 + 5

  5. Array in C++ • Size and index • Search an array • Sort an array

  6. C-String • The ending mark: the ‘\0’character • C-String functions • strlen() • strcmp() • Strcpy() • Strcat() • Implementations

  7. 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

More Related