Question

please help ASAP need to complete soon

needs to be done in C programing void countDays (unsigned month, unsigned day): Given a month and day, print a message based on the following conditions (whic

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

Below is whole program with explanation in comment:

#include<stdio.h> // header file for standard input and output
#include<conio.h> // header file for text user interface
#include<time.h> // header file that contains time and date function

/* isLeapYear() function is used to check given year is leap year or not */

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

/* Required Function as per given information */

void countDays(unsigned int month,unsigned int day)
{

/* days in each month with consider year is non-leap year */
   int nDays[]={31,28,31,30,31,30,31,31,30,31,30,31};   
   int i,day1,day2;

/*  time_t datatype is a data type in the ISO C library defined for storing system time values*/
   time_t s;

/*struct tm* is use to represent the local time */
   struct tm* current_time;

/* time(NULL) returns the number of seconds elapsed since 00:00:00 hours */
   s=time(NULL);
  

/* localtime function converts a calendar time and returns a pointer to a structure containing local time */
   current_time=localtime(&s);

/* adding 1900 because this value gives us the number of years starting from 1900 */
   int year=current_time->tm_year+1900;
  

/* condition to set february days */

   if(isLeapYear(year)==1)
       nDays[1]=29;

  

/* condition for checking valid month or not */
   if(month<0 || month>12)
   {
       printf("Invalid month %u",month);
   }
   else
   {

/* condition for checking valid day or not */
       if(day<0 || day>nDays[month-1])
           printf("Invalid day %u in month %u",day,month);
       else
       {


           if(month<=3 && day<=6) ////* condition for before break */
           {
               printf("University open");
           }
           else if(month==3 && (day>6 && day<18)) // condition for spring break  
           {
               printf("Spring break");
           }
           else // after spring break
           {
               day1=nDays[0]+nDays[1]+6; // calculating day before spring
              
              
               if(month==3)
                   day2=day-17;
               else
                   day2=14;
               for(i=4;i<=month;i++)
               {
                   if(i==month)
                   {
                       day2+=day;
                       break;
                   }
                   day2+=nDays[i];
               }
                  
               printf("Days since last class: %d and Days of remote learning: %d",day1,day2);
           }
          
       }
   }  
}


int main()
{
   unsigned int month,day;
   printf("Enter Month: ");
   scanf("%u",&month);
   printf("Enter Day: ");
   scanf("%u",&day);
   countDays(month,day);
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
please help ASAP need to complete soon needs to be done in C programing void countDays...
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
  • //Please help me out with this problem.. This problem has to be done in C++ and...

    //Please help me out with this problem.. This problem has to be done in C++ and has to strictly follow the instructions... I have given the expected output of the problem below.   1) Design a class Date: Provide 3 instance variables (int) to store the month, the day number, and the year Provide the following functions Default constructor -sets date to, 1500 Constructor with parameters - if parameters are not valid, set like default constructor setDate if parameters are not...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March","April", "May", "June", "July", "August", "September", days_in_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day...

  • Using c++.Complete the implementation of the class date that represents dates written in the form day/month/year....

    Using c++.Complete the implementation of the class date that represents dates written in the form day/month/year. Do not modify the main program. You must write the prototypes and the definitions of the methods of the class. Declaration of Class Date /File: date.h A class representing dates in the form: day, month and year dat e s are written to a stream in the form day/mon th / year day number () returns the number of days since 1/1 of the...

  • 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...

  • Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that...

    Please!!! need help asap!!!! write a C++program to analyze a small subset of the data that has been collected. See file universities.txt .Use precisely seven parallel arrays: one for name of university, one for state, one for city, one for yearly tuition, one for enrollment, one for average freshman retention, and one for the percent of students who graduate with in six years. Note that the percentage of student accepted is not stored.An output file is opened in main() and...

  • C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...

    C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined: Set the month. Set the day. Set the year. Return the month. Return the day. Return the year. Test whether the year is a leap year. Return the number of days in...

  • C++ Project Modify the Date Class: Standards Your program must start with comments giving your name...

    C++ Project Modify the Date Class: Standards Your program must start with comments giving your name and the name of the assignment. Your program must use good variable names. All input must have a good prompt so that the user knows what to enter. All output must clearly describe what is output. Using the date class, make the following modifications: Make the thanksgiving function you wrote for project 1 into a method of the Date class. It receive the current...

  • need help Instructions Assume we collected weather temperature data from a city for 5 day, Mon...

    need help Instructions Assume we collected weather temperature data from a city for 5 day, Mon thru Fri. The data is record in a 10 array. Each day is represented with 3 data points. So, create an array with 15 "unsigned short" items, and fill this array with random numbers from 32 to 120. Let's call this array temp array. Then create a structure to keep 1) name of day, and 2) average of temp of this array. Since we...

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