1. A professor will assign homework today and does not want it due on anybody^?s
ID: 667760 • Letter: 1
Question
1. A professor will assign homework today and does not want it due on anybody^?s holy day. The professor enters today^?s day of the week (0 for Sunday, 1 for Monday, etc.) and the number of days, D, to allow the students to do the work, which may be several weeks. Calculate the day of the week on which the work would be due. If that day is someone^?s holy day - Friday (Moslems), Saturday (Jews), or Sunday (Christians) - add enough days to D to reach the following Monday. Print the corrected value of D and the day of the week the work is due. 1) Use a switch statement for calculating the number of days based on today^?s day. 2) If the entered day for today is not in the range of 0 to 6, display an error message and abort the program. 3) Display the corrected value of the number of days and the day of the week the work s due. For example, if today is Thursday, and the number of days D is 8, then the due date falls on Friday, then 3 days will be added to reach the following Monday. So the corrected value of D is 11.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int day=0, D=0, dueDay=0,calcDay=0;
cout << "Please enter today's day of the week ";
cin >> day ;
if(day > 6)
{
cout << "Error:The value entered is not in the range. " ;
exit(0) ;
}
cout << "Please enter value for alloted days D " ;
cin >> D ;
calcDay = (D+day) % 7;
switch(calcDay) {
case 0 :
D = D + 1;
break;
case 6 :
D = D + 2;
break;
case 5 :
D = D + 3;
break;
default :
break;
}
dueDay = (day + D)%7 ;
cout << "The number of days required for this work is " << D << " which is due on " << dueDay << " day of the week ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.