1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
avanturin [10]
3 years ago
8

Write a program that prompts the user to enter the year and the first three letters of a month name (with the first letter in up

percase) and displays the number of days in the month.

Computers and Technology
1 answer:
elena55 [62]3 years ago
5 0

Answer:

I am writing a C++ program.

#include <iostream> // for input output functions

using namespace std; // to identify objects like cout, cin

int main() { // start of main() function body

   int year; // stores the year entered

   string month;  // holds the letters of a month

   cout<<"Enter the Year: "; // prompts user to enter year

   cin>>year; // reads year entered by user

   cout<<"Enter first three letters of a month ";

// prompts user to enter first three letters of a month

   cin>>month;    //reads the three letters of month entered by the user

// formula to determine leap year

   bool leapYear =((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);

//if checks if the 3 letters of input month match with one from these months  

if ( month == "Jan" || month =="Mar" || month == "May" || month == "Jul" || month == "Aug"|| month == "Oct"|| month == "Dec")

 //displays no of days in input month and year are 31

 cout<<"Number of days in "<<month<<" "<<year<<": 31 ";

//else- if checks if the input month matches with one from these months

else if (month =="Apr" || month=="Jun"|| month == "Sep"|| month == "Nov")

 //displays no of days in input month and year are 31

       cout<<"Number of days in "<<month<<" "<<year<<": 30 ";

else if (month =="Feb") //if the input month is Feb

cout<<"Number of days in "<<month<<" "<<year<<": "<<((leapYear) ? 29 : 28); // checks if the year is leap if yes then displays 29 days else 28

else //if none of the above if else conditions is true

{cout<<"Not a valid entry"; //displays invalid entry

    exit(0); //exits the program } }

             

Explanation:

The basic working of this program is briefly described in the comments above. I will explain the logic of the program.

This program takes int type year and a string month from the user (first three letters of the month).

Then it computes that if the year entered by the user is a leap year by this formula:

((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)

A leap year has 366 days and year which is not a leap year has 365 days. modulus operator is used here which returns the remainder of the division. If the input year is completely divisible by 4 which means we get remainder 0 then mod of year is taken with 100.  If the input year is evenly divisible by 100 then mode of year is taken with 400. Then if the input year is completely divisible by 400 this means the year is a leap year. Otherwise, year is not a leap year.

Next the IF statement is used to check the condition if the first three letters the month entered by the user matches one of the those mentioned in the if statement. As we know that the months Jan, March, May, July, Aug, Oct and Dec have 31 days so if the input month is any of these months then the message is displayed that the month has 31 days.

If the input month is not from the above months then else-if part is checked for input month. If the input month's letters matches with any of the months in else-if condition then the message displayed that the input year and month has 30 days.

If the above if and else if statement evaluate to false then the second else-if part is executed which checks if the input month is Feb, if its true the conditional statement checks if the input year is a leap year or not. If the input year is a leap year then the month Feb has 29 days otherwise 28 days.

If none of the above conditions are true this means that the user might be entering wrong letters such as Fab or Aig etc instead of Feb or Aug, so the message printed : Not a valid entry and program exits.

Screenshot of program along with its output is attached.

You might be interested in
F
Alex_Xolod [135]

Answer:

everything

A.

B.

C.

NOOO.

3 0
2 years ago
Kelly wants to change the text in a cell so that it is centered instead of left-aligned, where should she look to make this
timurjin [86]

Answer:

c

Explanation:

I don't know if it's correct

make me brainlist

4 0
2 years ago
Do you know how i can text my mom (and tell my mom to tell dad) that i want to get a new phone and get my ipad back without it b
posledela

You can clean your room, do chores without being told, and being nice to your siblings, or being very helpful around your house. I don't have social media myself, but from what I know, you just have to follow the directions correctly on the site or ask a friend. Plze mark me brainiest:) Hopefully this was helpful:)

7 0
2 years ago
A malicious user in your organization was able to use the Trinity Rescue Kit to change the password on a department manager's co
netineya [11]

Answer:

The answer is "The PC should be kept in a physically secure location".

Explanation:

In general, malicious users are hackers as well as malicious users. This user indicates that even a rogue worker, contractor, student, and another consumer who uses his sensitive rights is indeed a common word of violation of information in security circles and the headlines, and to manage the data from the theft the system should be on the physically secure location, that refers to any place, a room or a group of room within facilities of physical or staff security protocols that are sufficient to support the AI-based on LEIN and related Is a physically safe room.

7 0
2 years ago
HELP WILL MARK BRAINLIEST!!!!!!!!!!!!!!!!!<br> How do you take a screenshot on Windows 7?
Alina [70]
U can see the printscr botton at the top right of ur keyboard and then u can type paint and the control v. 
3 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following are types of formatting you
    12·2 answers
  • Compare a switch to a router.
    8·2 answers
  • What are the two main components on the motherboard?
    12·2 answers
  • A one-to-many binary relationship allows an occurrence of the entity type on the "one side" of the relationship to be associated
    5·1 answer
  • Which option is most likely used to create many-to-many relationships in Access?
    8·1 answer
  • An important task that the operating system performs is ____, which keeps track of the files stored on a computer so that they c
    15·1 answer
  • Manuel has set up his network so that some employees can open and view files but are unable to edit them. Others can open, view,
    10·1 answer
  • True or false = the order of cannot be changed in slide shorter view ,true or false =menu bar is located just below the title ba
    8·2 answers
  • Why is it important to do research prior to making a purchase? What types of sources can be helpful (or not helpful!)
    15·1 answer
  • 19. Fatigue can help improve your reaction time.<br> False<br> O True
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!