Question

In: Computer Science

Given the following int variables which represent a date, int day; // 0-6 for Sunday-Saturday int...

Given the following int variables which represent a date,

int day; // 0-6 for Sunday-Saturday
int month; // 1-12 for January-December
int date; // 1-31
int year; // like 2020

Define the function

void tomorrow(int& day, int& month, int& date, int& year);

which updates the variables to represent the next day. Test in main().

Solutions

Expert Solution

Greetings!!

Code:

#include <stdio.h>
#include <stdlib.h>
void tomorrow(int *, int *, int *, int *);
int main()
{
int day,month,date,year;
printf("Please enter the day 0-6:\n");
scanf("%d",&day);
printf("Please enter the month 1-12:\n");
scanf("%d",&month);
printf("Please enter the date 1-31:\n");
scanf("%d",&date);
printf("Please enter the year:\n");
scanf("%d",&year);
tomorrow(&day,&month,&date,&year); //calling function
return 0;
}
void tomorrow(int *dy, int *m, int *dt, int *y)
{
int day,month,date,year;
if(*m==2) //if february
{
if(*dt<29)
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
else
{
if(*dt==29) //if the date is 29
{
if(*y%4==0)
{
*dt=1;
*m=3;
*dy=(*dy%6)+1;
}
else
{
printf("\n\n\nSorry! Invalid year!!\n\n\n");
exit(0);
}
}
else
{
printf("\n\n\nSorry! Invalid date!!\n\n\n");
exit(0);
}
}
}
else if((*m==4)|(*m==6)|(*m==9)|(*m==11))
{
if(*dt==31)
{
printf("\n\n\nSorry! Invalid date!!\n\n\n");
exit(0);
}
else if(*dt==30)
{
*dt=1;
*m=*m+1;
*dy=(*dy%6)+1;
}
else
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
}
else if(*m==12)
{
if(*dt==31)
{
*dt=1;
*m=(*m%12)+1;
*dy=(*dy%6)+1;
*y=*y+1;
}
else
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
}
else
{
*dt=*dt+1;
*dy=(*dy%6)+1;
}
printf("\nTomorrow:\n\n day=%d\n month=%d\n date=%d\n year=%d\n",*dy,*m,*dt,*y);
}

Output screenshots:

Case 1:

Case 2:

Case 3:

Case 4:

Case 5:

Case 6:

Hope this helps


Related Solutions

Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year:...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year: int) +setDate(month: int, day: int, year: int): void -setDay(day: int): void -setMonth(month: int): void -setYear(year: int): void +getMonth():int +getDay():int +getYear():int +isLeapYear(): boolean +determineSeason(): string +printDate():void Create the class Constructor with no arguments sets the date to be January 1, 1900 Constructor with arguments CALLS THE SET FUNCTIONS to set the Month, then set the Year, and then set the Day - IN THAT ORDER...
What day of the week is a given date? i.e. On what day of the week...
What day of the week is a given date? i.e. On what day of the week was 5 August 1967? if it is given that 1 January 1900 was a tuesday Write a function is leap() which takes 1 input argument, an integer representing a year, and returns True if the year was a leap year, and False if it was not. .Then, write a function days_since() which takes 3 input integers day, month, year, representing a date (after 1st...
Consider the following function: int counter( int n) { int s = 0;    for ( int...
Consider the following function: int counter( int n) { int s = 0;    for ( int i = 0; i < n; i++)             for ( int j = i; j > 0; j--)                        s = s + 1;   return s; } Part (a): How many times "s=s+1;" will be executed? Determine a precise count.  Show all your work. Part (b): What is the time complexity of the "counter" function in terms of Big-O notation? Justify and show all your work.
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100;...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100; i++) myAry = i + 2; for(int i=100; i>0; i--) cout << myAry[i] << '\t'; The first for loop assigns myAry 99 values and the null character. The second for loop prints out myAry elements backwards. The index in the second for loop is out of bounds. Only the first loop needs the null character. Q3. A value returning function that takes one parameter,...
Given the following data, construct a three-sigma range control chart. Day of Sample Sample Values Saturday...
Given the following data, construct a three-sigma range control chart. Day of Sample Sample Values Saturday 22,19,20 Sunday 21,20,17 Monday 16,17,18 Tuesday 20,16,21 Wednesday 23,20,20 Thursday 19,16,21 a. If Friday's results are 15,14,21 is the process in control? b.Construct a three-sigma means control chart and determine if the process is still in control on Friday.
Question 1-6 are based on the following series of futures price (F(0), F(1),... F(6)): Day 0:...
Question 1-6 are based on the following series of futures price (F(0), F(1),... F(6)): Day 0: F(0)=$212 Day 1: F(1)=$211 Day 2: F(2)=$214 Day 3: F(3)=$209 Day 4: F(4)=$210 Day 5: F(5)=$202 Day 6: F(6)=$200 Suppose you are going to long 20 contracts. The initial margin=$10 per contract, and the maintenance margin is $2. 1) from the set of information: how much do you need to deposit in the trading account at Day 0? 2) Using the same set of...
Given the method static int test(int x, int y, int z){ return(x=y+z); } Which of the...
Given the method static int test(int x, int y, int z){ return(x=y+z); } Which of the follwing is true: public static void main(String[] args) { A System.out.println(test ( 7, 14, 23)) ; B System.out.println(test ( test ( 7,9, 14) , 23 ); C System.out.println( test ( 14, 23 ) ; D System.out.println(test(1,2,4), 14, 23)) ;
     i What values would be stored in the given variables in each case? a.          int n =...
     i What values would be stored in the given variables in each case? a.          int n = 12 % 5; b.          double x = 15 % 11 + 5.3 - 5 / (2.5 - 0.3); c.   float y = 2 / (3.5 + static_cast<int>(3.5)); d.   bool z = (6 – 7 <= 2 * 1) && (5 + 4 >= 3) || (6 + 2 != 17 – 3 * 10);
plz answers these short Qs in python language Q1-Given three int variables that have been given...
plz answers these short Qs in python language Q1-Given three int variables that have been given values, areaCode, exchange, and lastFour, write a string expression whose value is the string equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression's value would be "800-555-1212". Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression's value would be "212-867-5309" Q2-Write...
c++ Exercise 1: Make a struct “Fate” that contains the following variables: int month, int year,...
c++ Exercise 1: Make a struct “Fate” that contains the following variables: int month, int year, int day. Make another struct Product that would contain the following variables: 1- Product name. 2- An array for the product ingredients. Set its max size to 3. 3- Product date of expiration. Use the date struct you made. Use those structs in entering the data for two products of your choice. Make a function printProduct(Product product) that prints out the contents of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT