Calendar Program

Hi,
So for my C++ class I am required to create a program that will "Write a program to generate a calendar for a year. The program should accept the year and the day of the week for january 1 of that year (0=Sunday, 1=Monday, etc.)" (problem statement) and I am completely stuck. Can anyone help me? I've posted what I have so far below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <iomanip>
using namespace std;
 
bool isLeapYear(int year);
int daysInMonth(int month, bool lpYear);
int printCalendar(int month);
int printDay(int dow);

int main ()
{
    int dow, year;
    cout << "What year is it?\n";
    cin >> year;
    cout << "What day of the week does January start on? Enter 0 for Sunday, 1 for Monday, etc.\n";
    cin >> dow;
	for(int i=1;i<13;i++)
	{

	}
	return 0;
}
bool isLeapYear(int year)
{
	return ((year%400==0) || (year%4==0 && year%100!=0));
}
int printCalendar (int month, int year)
{
	if (month==1)
        cout << "January  ";
    else if (month==2)
        cout << "February  ";
    else if (month==3)
        cout << "March  ";
    else if (month==4)
        cout << "April  ";
    else if (month==5)
        cout << "May  ";
    else if (month==6)
        cout << "June  ";
    else if (month==7)
        cout << "July  ";
    else if (month==8)
        cout << "August  ";
    else if (month==9)
        cout << "September  ";
    else if (month==10)
        cout << "October  ";
    else if (month==11)
        cout << "November  ";
    else if (month==12)
        cout << "December  ";
    cout << setw(2) << year;
    cout << endl << endl;
    cout << "Sun  " << setw(2) << "Mon  " << setw(2) << "Tues  " << setw(2) << "Wed  " << setw(2) << "Thurs  " << setw(2) << "Fri  " << setw(2) << "Sat  " << endl;
}
int daysInMonth (int month, bool lpYear)
{
	int daysinmonth;
    switch(month)
	{
	case 1://jan
		daysinmonth=31;
		break;
	case 2://feb
		if(lpYear = true)
			daysinmonth = 29;
		else
			daysinmonth = 28;
		break;
	case 3://march
		daysinmonth = 31;
		break;
	case 4://april
		daysinmonth = 30;
		break;
	case 5://may
		daysinmonth = 31;
		break;
	case 6://june
		daysinmonth = 30;
		break;
	case 7://july
		daysinmonth = 31;
		break;
	case 8://august
		daysinmonth = 31;
		break;
	case 9://sept
		daysinmonth = 30;
		break;
	case 10://oct
		daysinmonth = 31;
		break;
	case 11://nov
		daysinmonth = 30;
		break;
	case 12://dec
		daysinmonth = 31;
		break;
	}
	return daysinmonth;
}
int printDay(int dow)
{
    for (days[i])
    {
        int day = StartDay;
        cout << num;
        day++;
        if (day > 7)
        {
            cout << endl;
            day = 1;
        }
    }
}
This doesn't use all the nice code you have written but maybe you will get some ideas from it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <iomanip>
using namespace std;
 
bool isLeapYear(int year);
int daysInMonth(int month, bool lpYear);
int printCalendar(int month);
int printDay(int dow);
string daysofweek="Su Mo Tu We Th Fr Sa";
int month=1; 			// What month is it
int maxdaysinmonth=0; 	// Max days to print for month
int endofweek=6;  		// end of week is Sa
int startingspaces=0; 	// leading spaces
int daycount=1;  		// Current day to print

int main ()
{
    int dow, year;
    cout << "What year is it?\n";
    cin >> year;
    cout << "What day of the week does January start on? Enter 0 for Sunday, 1 for Monday, etc.\n";
    cin >> dow;

// Print Year
cout << "\t" << year << endl<< endl;
// Print Month
	if (month==1)
        {
		cout << "      January" << endl;
		maxdaysinmonth = 31;
		}
cout << daysofweek << endl;

// Determine leading spaces
if (dow==0)
{startingspaces=1;}
else if (dow==1)
{startingspaces=4;}
else if (dow==2)
{startingspaces=7;}
else if (dow==3)
{startingspaces=10;}
else if (dow==4)
{startingspaces=13;}
else if (dow==5)
{startingspaces=16;}
else if (dow==6)
{startingspaces=19;}

for (int i=1; i <=startingspaces;i++)
	{cout << " ";}

while (daycount < 10)
	{
		if (daycount < 9)
		{
		cout << daycount << "  ";
		}
		else 
		{
		cout << daycount<< " ";
		}	
		daycount++;		
		if (dow==6)
			{
			cout << endl << " ";
			dow=0;
			}
		else
		{dow++;}
	}

while (daycount <=maxdaysinmonth)
	{
		cout << daycount << " ";
		daycount++;		
		if (dow==6)
		{
		cout << endl;
		dow=0;
		}
		else
		{dow++;}
	}

month++;
cout << endl;
cout << "Next Month = " << month << endl;
cout << "Starting day of week for next month: " << dow << endl;


return 0;	
}


bool isLeapYear(int year)
{
	return ((year%400==0) || (year%4==0 && year%100!=0));
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
What year is it?
2013
What day of the week does January start on? Enter 0 for Sunday, 1 for Monday, etc.
2
        2013

      January
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Next Month = 2
Starting day of week for next month: 5
Last edited on
I am required to create a program that will "Write a program to generate a calendar for a year.


Are you required to(?):

-Write a program which generates a calendar.
-Write a program which writes a program which generates a calendar.
Topic archived. No new replies allowed.