I tried to add enum \"days {JAN=31,FEB=28,MAR=31,APR=30,MAY,JUN=30,JUL,AUG=31,SE
ID: 3626117 • Letter: I
Question
I tried to add enum "days {JAN=31,FEB=28,MAR=31,APR=30,MAY,JUN=30,JUL,AUG=31,SEP=30,OCT,NOV=30,DEC}month; " to it like this code, but I am not sure where I should modify after it! Can anyone help?//header File
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() //Main Function};
int main(void)
{
// Design Method:
// 1. There are 365 days in a year whcih means 52 weeks and 1 extra day Jan 1st Year 1 is Monday so Jan 1st Years 2 should be Tuesday
// so we need to find out how many leap year will be in the calendar from year 1.
// 2. Then we can use the method to calculate what day is in the firstday of each month.
// 3. There is leap year after each 4 years, there is no leap year when face every 100 years, and there is a leap year when faced 400 years
int i;
int remainder; // Calculate the left over of days of the first month,it means to calculate what day it is in first month
int year; // Calculate year
int month; // Calculate month
// Define how many day in each month
int day[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dayrem; // discover the leftover in each Jan
ifstream fin;
ofstream fout;
fout.open("cal.txt");
cout << "Enter A Year¡G";
cin >> year;
cout << "Enter A Month¡G";
cin >> month;
cout << endl << endl;
// We know Jan. 1st year 1 is Monday
remainder =
(year - 1 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7;
// We need to calculate leap years to calculate how many leftover in first month
// If it can be divided by 100 then its not a leap year but if it can be divide by 400 then its leap year
// Calculate the day before a Dec. 31 from the year u asked
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
// if it is leap year the leftover +1 and Feb. has 29 day now
if (month >= 2)
{
day[1] = 29;
}//end leap year
}//end Feb in leap year
// calculate how many days total in the year you ask
for (i = 0; i < (month - 1); i++)
{
remainder += day[i];
}
// calculate whcih day it is in the month u ask but because we calculate from Sunday so + 1
dayrem = (remainder + 1) % 7;
cout << " **********AD: " << year<<"*********"<<"MONTH: " << month <<"**********"<< endl;
fout << " **********AD: " << year<<"*********"<<"MONTH: " << month <<"**********"<< endl;
cout << " =====SUN===MON===TUE===WED===THU===FRI===SAT===" << endl;
fout << " =====SUN===MON===TUE===WED===THU===FRI===SAT===" << endl;
for (i = 0; i < dayrem; i++)
{
cout << setw(6) << setfill(' ') << "";
fout << setw(6) << setfill(' ') << "";
}
// Calculate the first day to input in the month
int count = dayrem % 7;
for (i = 0; i < day[month - 1]; i++)
{
cout << setw(6) << setfill(' ') << i + 1;
fout << setw(6) << setfill(' ') << i + 1;
// changeline in each SAT
if (count >= 6)
{
cout << endl;
fout << endl;
count = 0;
}
else
{
count++;
}
}
cout << endl;
fout << endl;
fout.close();
system("pause");
return 0;
}// end of main function
Explanation / Answer
http://www.anyexample.com/programming/cplusplus/example_of_using_enum_in_cplusplus.xml here has example of how you use enum in c++, and basically, if you want to use enum instead of day array, all you need to modify is the array day, and everywhere it accessed.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.