Docsity

Programming Project - Computer Science with C++ | CSC 1253, Study notes of Computer Science

Toggle sidebar
bg1
Decision Statements CSc 1253: Programming Project # 2
Calculating the Day of the Week
Out: 2/4
Due: 2/12 by 11:50 PM
Learning Objectives
•Using Conditional Statements
•Using Logical Connectors
•More on Writing Interactive Programs
The Gregorian calendar was first introduced in October 1582 in Italy over
time it replaced the Julian calendar. The Gregorian calendar is accurate but
it needs a day adjustment for every intercalary year.
Definition 1. The following rules apply when determining an intercalary
(leap) year:
A. A year that is a multiple of 400 is a leap year.
B. A year that is not a multiple of 100, but is a multiple of 4, is a leap
year.
Day of the Week
The following rules will apply when determining the day of the week of a
valid date:
1. u= 2(3 −(century mod 4)), where century is the first two digits of the
year. For example, century is 20 for the year 2011.
2. v= the last two digits of the year. For example, vis 11 for 2011.
3. w=v
4, using integer division. For example, v = 11/4 = 2 for 2011.
Duncan 1 Spring 2011
pf3
pf4

Partial preview of the text

Download Programming Project - Computer Science with C++ | CSC 1253 and more Study notes Computer Science in PDF only on Docsity!

Calculating the Day of the Week

Out: 2/ Due: 2/12 by 11:50 PM

Learning Objectives

  • Using Conditional Statements
  • Using Logical Connectors
  • More on Writing Interactive Programs

The Gregorian calendar was first introduced in October 1582 in Italy over time it replaced the Julian calendar. The Gregorian calendar is accurate but it needs a day adjustment for every intercalary year.

Definition 1. The following rules apply when determining an intercalary (leap) year:

A. A year that is a multiple of 400 is a leap year.

B. A year that is not a multiple of 100, but is a multiple of 4, is a leap year.

Day of the Week

The following rules will apply when determining the day of the week of a valid date:

  1. u = 2(3 − (century mod 4)), where century is the first two digits of the year. For example, century is 20 for the year 2011.
  2. v = the last two digits of the year. For example, v is 11 for 2011.
  3. w = v 4 , using integer division. For example, v = 11/4 = 2 for 2011.

Month x 1 0 (6 in a leap year) 2 3 (2 in a leap year) 3 3 4 6 5 1 6 4 7 6 8 2 9 5 10 0 11 3 12 5

Table 1: Month Table

  1. x is determined using the month Table 1. For example, x is 3 for February 2011.
  2. y = u + v + w + x + day. y = 6 + 11 + 2 + 3 + 3 = 25 for February 3,
  3. day of the week = y mod 7. For example, February 3, 2011 oc- curs on Thursday, since 25 mod 7 is 4. Note that 0 = Sunday, 1 = Monday,... , 6 = Saturday.

Preparing your workspace and submitting Your Work

  1. Logon to the server (classes.csc.lsu.edu) using your logon ID and pass- word.
  2. Create a directory prog2 in your home area: mkdir prog
  3. Change to the prog2 directory: cd prog
  4. Edit your program using pico or your favorite editor: pico weekday.cpp
  5. Save your program (ctrl-O) and then exit the editor (ctrl-X).
  6. Compile your program: g++ -o weekday weekday.cpp
  7. Correct any syntax and semantic errors you may have. Once your program is free of these errors, run the program with multiple test cases to make sure that the results are accurate: weekday.
  8. Submit your assignment to the grader with the following command: ∼cs1253 dun/bin/p copy 2 This command copies everything in your prog2 directory.
  9. Once p copy is finished, check to see if your files have been submitted: ∼cs1253 dun/bin/verify 2
  10. You may submit your work as many times as you wish once the deadline has not elapsed. Any submission after the deadline means you will get no credit for this project.