Question

Write a program to find number of days in a month: Header comments must be present...

Write a program to find number of days in a month:

  • Header comments must be present
  • Prototypes must be present
  • Use comments and good style practices

NOTE: For simplicity, we will ignore leap years (i.e. February will always have 28 days).

main() function:

  • Display hello message
  • Call getMonth and assign result to month
  • Call getDaysInMonth and assign result to days
  • Display results
  • Display goodbye message

getMonth() function:

  • Prompt user for month
  • Loop until month is between 1 and 12
  • Return month

getDaysInMonth() function:

  • Switch on month to find days
  • Return days
SAMPLE RUN:
Welcome! This program will display how many days are in a month selected by the user.
Enter a month (1-12): 7
There are 31 days in that month.
Exiting program. Goodbye!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

#include <iostream>

using namespace std;

int getMonth();

int getDaysInMonth(int);

int main() {

cout << "Welcome! This program will display how many days are in a month selected by the user." << endl;

int month = getMonth();

int days = getDaysInMonth(month);

cout << "There are " << days <<" days in that month." << endl << "Exiting program. Goodbye!";

}

int getMonth()

{

int month;

cout << "Enter a month (1-12): ";

cin >> month;

while(month > 12 || month < 1)

{

cout << "Enter a month (1-12): ";

cin >> month;

}

return month;

}

int getDaysInMonth(int month)

{

switch(month)

{

case 2:

return 28;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

return 31;

case 4:

case 6:

case 9:

case 11:

return 30;

}

return -1;

}

OUTPUT

Welcome! This program will display how many days are in a month selected by the user.
Enter a month (1-12): 7
There are 31 days in that month.
Exiting program. Goodbye!

Add a comment
Know the answer?
Add Answer to:
Write a program to find number of days in a month: Header comments must be present...
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
  • part1 7.4 Create a new file (in Dev C++) and save it Write a program that...

    part1 7.4 Create a new file (in Dev C++) and save it Write a program that uses parallel arrays to store payroll data for 5 employees. The program should display each employee name and then prompt for hours and rate. Calculate and store gross pay for each employee. After the data has been entered for all employees, display each employee's ID, name, hours, rate and gross pay as a table. Use the following arrays: arrEmpIDs: array of five integers, initialized...

  • Create a new file (in Dev C++) Modify program above to use a vector instead of...

    Create a new file (in Dev C++) Modify program above to use a vector instead of an array. Header comments must be present Prototypes must be present if functions are used Hello and goodbye messages must be shown Vector(s) must be used for implementation Use comments and good style practices ====================================================================================================== #include <iostream> using namespace std; int main() { cout<<"Welcome! This program will find the minimum and maximum numbers in an array."<<endl; cout<<"You will be asked to enter a number...

  • C++ code: Days in current month: Write a program that can determine the number of days...

    C++ code: Days in current month: Write a program that can determine the number of days in a month for a specified month and year. The program should allow a user to enter two integers responding a month and a year, and it should determine how many days are in the specified month. The integers 1 through 12 will be used to identify the months of January through December. The user indicates the end of days in the current month...

  • C Program Question 1: Write a program that reads a date from the keyboard and tests...

    C Program Question 1: Write a program that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning...

    PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...

  • Question 1: Write a program in C that reads a date from the keyboard and tests...

    Question 1: Write a program in C that reads a date from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

  • Must be written in C++ Display results and comments Write a program that sorts a vector...

    Must be written in C++ Display results and comments Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions: 1. void selSort (vector <string> & v): sorts the vector using selection sort 2. void display (const vector <string> & v): displays the vector contents 3. int binSearch (const vector <string> & v, string key): searches...

  • Write a program that reads a string from keyboard and tests whether it contains a valid...

    Write a program that reads a string from keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be 1 from to a value that is appropriate...

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