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
Wich type of operating system is usually used in personal computers
Anvisha [2.4K]
The three most common operating systems for personal computers are Microsoft Windows, Apple Mac OS X, and Linux.
4 0
3 years ago
Read 2 more answers
What is the price of a k1 speed birthday party?
valentinak56 [21]
There is differen prices depending on the race go to the k1 website to see the packages
8 0
3 years ago
Read 2 more answers
Jennifer stays fit by playing games that track the movement of her body. Which platform features such a physical interface featu
Usimov [2.4K]

Answer:

kinect xbox 360.

Explanation:

for example- just dance

7 0
3 years ago
How would you use SQL to change a table's structure? What general types of changes are possible? Which commands are used to impl
xz_007 [3.2K]

The SQL is used to change a table's structure by:

The use of the SQL ALTER TABLE command.

<h3>How is it done?</h3>

The SQL ALTER TABLE command is known to  be that which is often used to alter the structure of an existing table.

It is known to help one to be able to add or delete columns, make or destroy indexes, alter the kinds of existing columns, rename columns or the table itself.

Note that  It can also be used to alter the comment for any kind of table and type of the table therein.

Learn more about SQL from

brainly.com/question/25694408

#SPJ1

4 0
2 years ago
You are the network administrator for a small organization of 100 users. Users till now were freely browsing the Internet. You w
Schach [20]

Answer: Proxy server

Explanation: Proxy server is a type of server that is acts as interface between the network on huge scale and any local network. This server provides the feature of security, operations, privacy etc in the network system. They also help in improving the performance of the network.

It can work as the web filter to eliminate the unwanted websites.They acts as the gateway by  observing the website that is being browsed by the other user.Thus installation of proxy server should implemented on the organization.

8 0
3 years ago
Other questions:
  • Which of the following situations would not require knowledge of networking?
    6·1 answer
  • What is the decimal equivalent of the binary number 1102?
    8·2 answers
  • The United States Army retains a history of all equipment acquisition from approval of requirements through funding, authorizing
    13·1 answer
  • Explain why Windows and Linux implements multiple locking mechanisms. Describe the circumstances under which they use spinlocks,
    13·1 answer
  • Tips for being confident and entertaining when presenting?
    6·1 answer
  • Which expression is equivalent to 3x + 3x + 3x?<br><br> From Performance Matters
    11·2 answers
  • How are keyboards applied in the real world
    13·1 answer
  • In addition to being fun, another reason that people have been creating games ever since they settled into communities is:
    6·2 answers
  • As part of your regular system maintenance, you install the latest operating system updates on your Windows 10 computer. After s
    12·1 answer
  • Self-driving cars are a result of developments in which field of computer<br> science?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!