Question

Problem write a program that prints the day number

Must use a function to compute the day.

All cin and cout statements must appear in main(). Has to be in c++. lab 10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

usingnamespace std;

void noOfDays(int, int, int);

int main()

{

int day, month, year;

cout<<"Please enter month, day and year:"<<endl<<endl;

cin>>month>>day>>year;

noOfDays(day, month, year);

system ("pause");

return 0;

}

void noOfDays(int d, int m, int y)

{

int numDays;

if ((y % 4 == 0) || ( y % 400 == 0))

{

cout<< "The year " << y <<" is a leap year. "<<endl<<endl;

switch (m)

{

case 1:numDays = d;

break;

case 2:numDays = 31 + d;

break;

case 3:numDays = 31 + 29 + d;

break;

case 4:numDays = 31 + 29 +31 + d;

break;

case 5:numDays = 31 + 29 + 31 + 30 + d;

break;

case 6:numDays =31 + 29 + 31 + 30 + 31 + d;

break;

case 7:numDays = 31 + 29 + 31 + 30 + 31 + 30 + d;

break;

case 8:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + d;

break;

case 9:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + d;

break;

case 10:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d;

break;

case 11:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d;

break;

case 12: numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d;

}

}

else { cout<< "The year " << y <<" is not a leap year. "<<endl<< endl;

switch (m)

{

case 1:numDays = d;

break;

case 2:numDays = 31 + d;

break;

case 3:numDays = 31 + 28 + d;

break;

case 4:numDays = 31 + 28 +31 + d;

break;

case 5:numDays = 31 + 28 + 31 + 30 + d;

break;

case 6:numDays =31 + 28 + 31 + 30 + 31 + d;

break;

case 7:numDays = 31 + 28 + 31 + 30 + 31 + 30 + d;

break;

case 8:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + d;

break;

case 9:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + d;

break;

case 10:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d;

break;

case 11:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d;

break;

case 12: numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d;

}

}

cout<<"Number of days: " << numDays << endl;

}

Add a comment
Know the answer?
Add Answer to:
Must use a function to compute the day. All cin and cout statements must appear in...
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
  • leap year C++

    the instructions are: A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are:1) The year must be divisible by 42) If the year is a century year...

  • In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists...

    In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4...

  • Has to be written in C++ Write a program that asks the user to enter the...

    Has to be written in C++ Write a program that asks the user to enter the month (1-12) and the year (0-2019). Validate the input and print an error and stop the program if an invalid month or year was entered. The program should then display the number of days in that month. Use the following criteria to identify leap years: Determine whether the year is divisible by 100. If it is, then it is a leap year if and...

  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes...

    A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year...

  • CIS22A Homework 6 Topic: Chapter 4 & 5 Purpose: Determine if a year is a leap...

    CIS22A Homework 6 Topic: Chapter 4 & 5 Purpose: Determine if a year is a leap year Create a new C++ project titled “HW 6” in the CodeBlocks IDE. Use the “Console Application” project option. Over time, the calendar we use has changed a lot. Currently, we use a system called the Gregorian Calendar and it was introduced in 1582. The algorithm to determine if a year is a leap year is as follows: Every year that is exactly divisible...

  • please follow format of example output, do in python A year in the modern Gregorian Calendar...

    please follow format of example output, do in python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by...

  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes...

    A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year...

  • Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day ...

    C++ 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 and how many days passed since you were born. Remember that January 1st of the year 2019 is Tuesday See the example below Read 1/1/2019 - Tue 90 Read 4/1/2019 - Mon 0 Read 4/1/2018 - Sun 365 Read 4/1/2017 -> Sat 730 Read 4/1/2016 Fri 1095 Read 4/1/2015-> Wed 1461 Bye... Wikipedia...

  • Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for...

    Write a class named MonthDays. The class’s constructor should accept two arguments: l An integer for the month (1 = January, 2 February, etc). l An integer for the year The class should have a method named getNumberOfDays that returns the number of days in the specified month. The method should use the following criteria to identify leap years: 1. Determine whether the year is divisible by 100. If it is, then it is a leap year if and if...

  • 3. Using no date-specific Java libraries, write a program that computes the number of days between...

    3. Using no date-specific Java libraries, write a program that computes the number of days between any two dates (inclusive). You must take into account leap years. The rule for computing a leap year is as follows: If the year is divisible by 4 it is a Leap Year ... Unless the year is divisible by 100, then it is _not_ a Leap Year ... Unless the year is divisible by 400, then it _is_ a Leap Year. During a...

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