C++ Question: 1. I have a wedding on June 4, 2017 I need to know how many days I
ID: 3791900 • Letter: C
Question
C++ Question:
1. I have a wedding on June 4, 2017 I need to know how many days I have to plan for the wedding. Today is Jan. 1, 2016.
2. Today is March 3, 2015. How many shopping days are there till Christmas?
3. I will receive a report and I have been told I have 75 days to respond to the report. If I get the report on Feb. 15, 2016, by what date must I have a response?
4. I have a class I teach in New Orleans every week and I can get a direct flight from Huntsville to New Orleans. I will need a flight every Wednesday (class that day) for Aug. 23, 2016 through Nov. 29, 2016 I need to know what are the dates in need to book flights.
5. I work in a hospital and we just received a fancy x-ray machine (computer control, graphics the works). Now to keep the guarantee valid on the machine, we have to perform prevented maintenance every 23 working/operational days (weekends are not working days). It takes two days to do the maintenance (during maintenance the machine is not in service ie not a working day). I need to set up a schedule showing which dates that maintenance is to be performed. That way I will not schedule any patients on those days. We will start the machine on Mar. 20, 2016 and I need a schedule for the next months, say through September, showing the schedule for the maintenance days.
Attached are some date calculating functions function already written and ready for you to use in solving these problems. You are to solve the problems found on the spec sheet using only the date algorithms functions given. You cannot rewrite them, get new ones, or write your own. You can only use the date functions supplied to solve my date problems assigned.
Date Calculation Algorithms:
Calculate day number from date.
/*All division is integer division, operator % is modulus.*/
Given integer y, m, d, calculate day number g as:
function g(y,m,d)
m = (m + 9) % 12
y = y - m/10
return 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )
Calculate date from day number
*/All division is integer division, operator % is modulus./*
Given day number g, calculate year, month, and day:
function d(g)
y = (10000*g + 14780)/3652425
ddd = g - (365*y + y/4 - y/100 + y/400)
if (ddd < 0) then
y = y - 1
ddd = g - (365*y + y/4 - y/100 + y/400)
endif
mi = (100*ddd + 52)/3060
mm = (mi + 2)%12 + 1
y = y + (mi + 2)/12
dd = ddd - (mi*306 + 5)/10 + 1
return y, mm, dd
Applications.
Date differences.
The difference in days between two dates:
g(y2,m2,d2) - g(y1,m1,d1)
Day offsets.
The date n days from y,m,d:
d(g(y,m,d) + n)
Date legality.
To check if a date is on the calendar:
if [y,m,d] = d(g(y,m,d))
Explanation / Answer
// Example program
#include <iostream>
#include <string>
using namespace std;
//Calculate date from day number
/*All division is integer division, operator % is modulus.*/
//Given day number g, calculate year, month, and day:
void d(int g){
int mm,dd,mi;
int y = (10000*g + 14780)/3652425;
int ddd = g - (365*y + y/4 - y/100 + y/400);
if (ddd < 0) {
y = y - 1;
ddd = g - (365*y + y/4 - y/100 + y/400);
}else{
mi = (100*ddd + 52)/3060;
mm = (mi + 2)%12 + 1;
y = y + (mi + 2)/12;
dd = ddd - (mi*306 + 5)/10 + 1;
}
cout << y << "/" << mm << "/" << dd << endl;
}
// Calculate day number from date.
/*All division is integer division, operator % is modulus.*/
// Given integer y, m, d, calculate day number g as:
int g(int y,int m,int d){
m = (m + 9) % 12 ;
y = y - m/10 ;
int a = 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 );
return a;
}
//Day offsets.
//The date n days from y,m,d:
//d(g(y,m,d) + n)
// Date legality.
//To check if a date is on the calendar:
// if [y,m,d] = d(g(y,m,d))
void dayPlanforWedding(int currentYear , int currentMonth , int currentDate , int weddingYear, int weddingMonth, int weddingDate){
int dayNeedsToBePlanned = g(currentYear,currentMonth,currentDate) - g(weddingYear,weddingMonth,weddingDate);
if(dayNeedsToBePlanned < 0){
dayNeedsToBePlanned = -(dayNeedsToBePlanned);
}
cout << dayNeedsToBePlanned << endl;
}
void daysPendingTillChristmas(int todaysYear , int todaysMonth , int todaysDate ){
int christmasMonth = 12;
int christmasDate = 25;
dayPlanforWedding(todaysYear,todaysMonth,todaysDate,todaysYear,christmasMonth,christmasDate);
}
void reportsRespondToBeGivenInDays(){
cout <<"Date Format : " << "yy/m/dd" << endl;
cout <<"Response To be sent with respect to report recieved on date : " << "16/2/15" << endl;
d(g(16,2,15) + 75);
}
void flightToBeTakenforWedClasses(){
cout << "Date Format : " << "yy/m/dd" << endl;
cout << "First flight to be taken on date : " << "16/8/23" << endl;
cout << "Second and Subsequent flight to be taken on date given as below : " << endl;
int days = g(16,8,23) - g(16,11,29);
days = -(days);
for(int i = 7 ; i < days ; ){
d(g(16,8,23) + i);
i = i + 7;
}
}
int main()
{
cout << " ###### Answer of Query first " << endl << endl;
dayPlanforWedding(17,2,14,17,3,16);
cout << " ###### Answer of Query Second " << endl << endl;
daysPendingTillChristmas(17,3,3);
cout << " ###### Answer of Query Third " << endl << endl ;
count<<"Date on which report to be submitted is : ";
reportsRespondToBeGivenInDays();
cout << " ###### Answer of Query fourth " << endl << endl;
flightToBeTakenforWedClasses();
return 0;
}
--------------------------------------------------------
OutPut :
###### Answer of Query first 30
###### Answer of Query Second 297
###### Answer of Query Third
Date Format : yy/m/dd
Response To be sent with respect to report recieved on date : 16/2/15
Date on which report to be submitted is : 16/4/30
###### Answer of Query fourth Date Format : yy/m/dd
First flight to be taken on date : 16/8/23
Second and Subsequent flight to be taken on date given as below :
16/8/30
16/9/6
16/9/13
16/9/20
16/9/27
16/10/4
16/10/11
16/10/18
16/10/25
16/11/1
16/11/8
16/11/15
16/11/22
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.