Calendar

This is an exercise that i am working on. The program is supposed to display the calendar of a month after the user has inputted the month and year. But i cannot really figure out how to calculate the day (e.g monday) of the first day of the month. I want some guidance. Thank You

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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  #include  <iostream>
using namespace std;


// get_date obtain month and year from user
bool	get_date(int &month, int &year) {

cout << "Please input month <1-12> and year <2000- > :";
cin >> month;
cout << " ";
cin >> year;

if((month > 12) || (month < 1)){
    return false;
}

if(year < 2000){
    return false;
}

else{
    return true;
}

}

// get_month_name return name of month, e.g., get_month(1) returns "January"
string	get_month_name(int month) {

if(month == 1){
    return "January";
}

if(month == 2){
    return "February";
}

if(month == 3){
    return "March";
}

if(month == 4){
    return "April";
}

if(month == 5){
    return "May";
}

if(month == 6){
    return "June";
}

if(month == 7){
    return "July";
}

if(month == 8){
    return "August";
}

if(month == 9){
    return "September";
}

if(month == 10){
    return "October";
}

if(month == 11){
    return "November";
}

if(month == 12){
    return "December";
}

}

// get_days_in_month return number of days in a given month and year,
//   e.g., get_days_in_month(2, 1996) returns 29
int	get_days_in_month(int month, int year) {

if(month = 1){
    return 31;
}

if(month = 2){
    if((year % 4 == 0)){
        return 29;
    }
    if ((year % 4 != 0)){
        return 28;
    }
}

if(month = 3){
    return 31;
}

if(month = 4){
    return 30;
}

if(month = 5){
    return 31;
}

if(month = 6){
    return 30;
}

if(month = 7){
    return 31;
}

if(month = 8){
    return 31;
}

if(month = 9){
    return 30;
}

if(month = 10){
    return 31;
}

if(month = 11){
    return 30;
}

if(month = 12){
    return 31;
}
}

// get_day_of_week return day of week of first day of month in year
int	get_day_of_week(int month, int year) {

}

// print_month print monthly calendar in table form, one row per week
void	print_month(int month, int year) {

	cout << get_month_name(month) << ' ' << year << endl;
	cout << "---------------------------------\n";
	cout << "Sun  Mon  Tue  Wed  Thu  Fri  Sat\n";
	cout << "---------------------------------\n";

	cout << "---------------------------------\n";
}

int main() {
	int	year, month;

	if (get_date(month, year)) {
		print_month(month, year);
	}
	else cout << "Error: month[" << month << "] and/or year ["
		  << year << "] unacceptable.\n";
}
Last edited on
Topic archived. No new replies allowed.