Computer Science: A Structured Programming Approach Using C, Third Edition
Computer Science: A Structured Programming Approach Using C, Third Edition
3rd Edition
ISBN: 9780534491321
Author: Behrouz A. Forouzan, Richard F. Gilberg
Publisher: Course Technology, Inc.
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 5, Problem 60PS

Write a program that, given a person's birth date (or any other date in the Gregorian calendar), will display the day of the week the person was born.

To determine the day of the week, you will first need to calculate the day of the week for December 31 of the previous year. To calculate the day for December 31, use the following formula.

year 1 × 365 + year 1 4 year 1 100 + year 1 400 % 7

The formula determines the day based on the values as shown below.

Day 0: Sunday Day 1: Monday Day 2: Tuesday Day 3: Wednesday Day 4: Thursday Day 5: Friday Day 6: Saturday

Once you know the day for December 31, you simply calculate the days in the year before the month in question. Use a switch statement to make this calculation. If the desired month is 12, add the number of days for November (30). If it is 11, add the number of days for October (31). If it is 3, add the number of days for February (28). If it is 2, add the number of days for January (31). If you do not use a break between the months, the switch will add the days in each month before the current month.

To this figure, add the day in the current month and then add the result to the day code for December 31. This number modulo seven is the day of the week.

There is one more refinement. If the current year is a leap year, and if the desired date is after February, you need to add 1 to the day code. The following formula can be used to determine if the year is a leap year.

! year % 4  &&  year % 100  | | ! year % 400

Your program should have a function to get data from the user, another to calculate the day of the week, and a third to print the result.

To test your program, run it with the following dates:

a . February 28, 1900, and March 1, 1900 b . February 28, 1955, and March 1, 1955 c . February 28, 1996, and March 1, 1996 d . February 28, 2000, and March 1, 2000 e . December 31, 1996 f . The first and last dates of the current week .

Blurred answer
Students have asked these similar questions
Airline companies apply baggage restrictions for their passengers. An airline company has decided to apply a 10kg limitation for passengers' hand luggage and 20kg for their normal baggage. When passengers arrive, they enter their hand and normal luggage weight from the keyboard. If passengers exceed their normal baggage allowance of 10 dollars per gram, they pay 12 dollars per kg. Accordingly, write the program that calculates the baggage price of the airline they will go to according to the baggage values entered by the arriving passenger and keeps this from closing the program for each passenger. Note: If hand and normal baggage allowances are stretched below the maximum value, the payment amount will be considered not negative. An example printout is given on the right. Geri bildirim gönder
Write a program to calculate the position of a projectile at a given time t. For an initial velocity vo and angle of departure ®g, the position is given by x and y coordinates as follows (note: the gravity constant g is 9.81 m/s²): X= V0 Cos (0)t y=vo sin (8,)t –; gt The program should initialize the variables for the initial velocity, time, and angle of departure. It should then call a function to find the x and y coordinates, and then another function to print the results
An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program to display each digit, starting with the rightmost digit. Your program should also determine whether or not the number is divisible by 9.

Chapter 5 Solutions

Computer Science: A Structured Programming Approach Using C, Third Edition

Ch. 5 - There are two different ways to implement a...Ch. 5 - Which of the following statements about switch...Ch. 5 - Which of the following statements about the...Ch. 5 - Prob. 14PSCh. 5 - Prob. 15PSCh. 5 - If x=0,y=5,z=5, what is the value of x, y, and z...Ch. 5 - If x=3,y=0,andz=4, what is the value of the...Ch. 5 - Simplify the following expressions by removing the...Ch. 5 - Prob. 19PSCh. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=4,y=0,andz=2, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=0,y=0,andz=1, what is the value of...Ch. 5 - If originally x=2,y=1,andz=1, what is the value of...Ch. 5 - If originally x=1,y=3,andz=0, what is the value of...Ch. 5 - Evaluate the value of the following expressions:...Ch. 5 - Evaluate the value of the following expressions:...Ch. 5 - Write an if statement that will assign the value 1...Ch. 5 - Prob. 36PSCh. 5 - Write the code to add 4 to an integer variable,...Ch. 5 - Prob. 38PSCh. 5 - Write the code to print either zero or not zero...Ch. 5 - If the variable divisor is not zero, divide the...Ch. 5 - Prob. 41PSCh. 5 - Rewrite the following code using one if statement:...Ch. 5 - Rewrite the following code fragment using one...Ch. 5 - Write a code fragment that tests the value of an...Ch. 5 - Prob. 45PSCh. 5 - Prob. 46PSCh. 5 - Write a function called smallest that, given three...Ch. 5 - Prob. 48PSCh. 5 - Write a function called month_of_year that, given...Ch. 5 - Write a function called parkingcharge that, given...Ch. 5 - Prob. 51PSCh. 5 - Complete the incremental implementation of Program...Ch. 5 - Write a program that determines a student's grade....Ch. 5 - Prob. 54PSCh. 5 - Given a point, a line from the point forms an...Ch. 5 - Prob. 56PSCh. 5 - Write a program that asks the user to enter the...Ch. 5 - Prob. 58PSCh. 5 - This program is a simple guessing game. The...Ch. 5 - Write a program that, given a person's birth date...Ch. 5 - Write a program that calculates the change due a...Ch. 5 - Write a menu-driven program that allows a user to...Ch. 5 - Write a program that tests a user-entered...Ch. 5 - Write a program to compute the real roots of a...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY