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

#include
#include
#include
using namespace std;
bool LeapYear(int year){
return (year %4==0 && year %100!=0)||(year %400==0);
}
int daysInMonth(int month, int year){
if (month ==2){
return LeapYear(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 += LeapYear(y)?366 : 365;
}
totalDays += daysInYear(year, month, day);
return totalDays;
}
string dayOfWeek(int dayValue){
string days[]={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
// Base date 1/1/1900 is a Monday, so no adjustment is needed
return days[(dayValue -1)%7]; // Adjust for correct index
}
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 = LeapYear(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;
}
visual studio, using c++ is giving me an error with scanf and wont run

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!