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

#include
#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;
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 is reading the input file but the values in the output are not working correctly to show the value of the day, correct day of the week for the date and if the year was a leap year correctly. ive attached a screenshout of the output im correctly getting
#include #include #include using namespace std;

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!