Question

Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day of the week you were born an

C++ question

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
string strDays[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

bool isLeapYear(int year) {
        return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}



int aprilOneDay() {
        int y = 2019;
        int d = 1;
        int m = 1;
        int day = 2;  // start 1 Jan is on tuesday
        while(m != 4 || d != 1) {
                d++;
                // 2019 is not leap, so no need to worry.
                if(d > daysInMonths[m]) {
                        d = 1;
                        m++;
                }
                day = (day + 1) % 7;
        }
        return day;
}

int getDaysInMonth(int m, int y) {
        if(isLeapYear(y) && (m == 2)) {
                return 29;
        }
        return daysInMonths[m];
}

int main() {
        int m, d, y;
        int day = 0;
        cout << "Enter brith day(M D Y): ";
        cin >> m >> d >> y;
        int currentDay = aprilOneDay();
        int count = 0;

        while(m != 4 || d != 1 || y != 2019) {
                d++;
                // 2019 is not leap, so no need to worry.
                if(d > getDaysInMonth(m, y)) {
                        d = 1;
                        m++;
                        if(m > 12) {
                                m = 1;
                                y++;
                        }
                }
                day = (day + 1) % 7;
                count++;
        }
        day = (7 - day + currentDay) % 7;
        cout << strDays[day] << " " << count << endl;
}

please upvote.

main.cpp saved https://UpsetFrighteningTriggers.anjaligupta000.re 36 37 38 int main() 39 40 41 42 43 clang version 7.0.0-3-ub

Add a comment
Know the answer?
Add Answer to:
Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:      ...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

  • c++ please :) First, ask the user to enter a year (4-digit) and what week day...

    c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....

  • FINDING THE LEAP YEARS (14 points) From Wikipedia, "A leap year (also known as an intercalary...

    FINDING THE LEAP YEARS (14 points) From Wikipedia, "A leap year (also known as an intercalary year or bissextile year) is a calendar year containing one additional day (or, in the case of lunisolar calendars, a month) added to keep the calendar year synchronized with the astronomical or seasonal year." In the Gregorian calendar, which is in use today, to determine leap year: A year is a leap year if it is divisible by 400 Or it is divisible by...

  • PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program tha...

    PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file  timeValidation.txt :   ...

  • Use Java please Creating a calendar for a given year A shell for this assignment has...

    Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...

  • In Java You are to write a program that determines the day of the week for...

    In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...

  • Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a part...

    Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a particular date (also your choosing) with an asterisk. Make sure the calendar displays the week, the days of the week and the year. Make sure the MSU Programming Class appears in the title of the Calendar. I will choose May 1st for the month and date. The code below is what I will be using. Please show where I can go to in...

  • Your task s to mid a prediction interval lor the y-value when x=2019. show 4 deerma Iditarod Modeling to Prediction Interval for single Y- Find x Win Years Day Hour Min Sec 2018 9 12 0 0 228.0 2017 8...

    Your task s to mid a prediction interval lor the y-value when x=2019. show 4 deerma Iditarod Modeling to Prediction Interval for single Y- Find x Win Years Day Hour Min Sec 2018 9 12 0 0 228.0 2017 8 3 40 13 195.6703 2016 8 11 20 16 203.3378 2015 8 18 13 6 210.2183 2014 8 13 4 19 205.0719 2013 9 7 39 56 223.6656 2012 9 4 29 26 220.4906 2011 8 18 46 39 210.7775...

  • General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You sho...

    General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You should create identifiers with sensible names; • You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. • Logical structures and statements are properly used for specific purposes. Objectives This assignment requires you to write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT