Question: #include #include using namespace std; bool isLeapYear ( int year ) { return ( year % 4 = = 0 && year % 1 0

#include
#include
using namespace std;
bool isLeapYear(int year){
return (year %4==0 && year %100!=0)||(year %400==0);
}
int daysInMonth(int month, int year){
if (month ==2){
return isLeapYear(year)?29 : 28;
}
return (month ==4|| month ==6|| month ==9|| month ==11)?30 : 31;
}
int daysInYear(int year, int month, int day){
int days =0;
for (int m =1; m month; m++){
days += daysInMonth(m, year);
}
days += day;
return days;
}
int dayValue(int year, int month, int day){
int totalDays =0;
for (int y =1900; y year; y++){
totalDays += isLeapYear(y)?366 : 365;
}
totalDays += daysInYear(year, month, day);
return totalDays;
}
string dayOfWeek(int dayValue){
string days[]={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
return days[dayValue %7];
}
int main(){
ifstream inputFile("dates.txt");
string line;
while (getline(inputFile, line)){
int month, day, year;
sscanf(line.c_str(),"%d/%d/%d", &month, &day, &year); // Assuming the input format is "MM/DD/YYYY"
int value = dayValue(year, month, day);
string dayName = dayOfWeek(value);
bool leapYear = isLeapYear(year);
cout dayName "" month "/" day "/" year " has a day value of " value
(leapYear ?" and is a leap year." : " and is not a leap year.") endl;
}
inputFile.close();
return 0;
}
The code outputs the day as "wednesday" no matter what date I plug into my input file, I put today's date which is a tuesday and it says " wednesday"
#include #include using namespace std; bool

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!