c++ calculator design

6. write a program that takes m from user and print its month calendar of year 2013 for example
February 2009
S M Tu W Th F S
2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
23 24 25 26 27 28

Hi there,

Please do not expect us to do your homework for you.
Be specific about what you have tried, where you are stuck, which errors the compiler gives you, etc.
People will be more inclined to help you out if you do so.

All the best,
NwN
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#include <iostream>

//EXAMPLE:

//#define MIN_DEC_2012     // Take a calendar and define these as spaces after start.
//#define MAX_DEC_2012     // For example: there are 6 blank spaces until day 1 so 
                           // MIN_DEC_2012=6.
                           // Also, MAX_DEC_2012=6 because there are 6 spaces after 31.

#define MIN_JAN_2013     2 //31 days
#define MIN_FEB_2013     5 //31 days
#define MIN_MAR_2013     5 //30 days
#define MIN_APR_2013     1 //30 days
#define MIN_MAY_2013     3 //31 days
#define MIN_JUN_2013     6 //29 days
#define MIN_JUL_2013     1 //31 days
#define MIN_AUG_2013     4 //31 days
#define MIN_SEP_2013     0 //30 days
#define MIN_OCT_2013     2 //31 days
#define MIN_NOV_2013     5 //30 days
#define MIN_DEC_2013     //there isnt a december on the indian calendar.
                         //find one on your own

#define MAX_JAN_2013     2
#define MAX_FEB_2013     6
#define MAX_MAR_2013     0
#define MAX_APR_2013     4
#define MAX_MAY_2013     1
#define MAX_JUN_2013     0
#define MAX_JUL_2013     3
#define MAX_AUG_2013     0
#define MAX_SEP_2013     5
#define MAX_OCT_2013     2
#define MAX_NOV_2013     0
#define MAX_DEC_2013     //there isnt a december on the indian calendar.
                         //find one on your own

void InterpretMonth (int month);

void InterpretMonth (int month)
{
	int i;
	
	std::cout<<"F o r  t h e  y e a r  2 0 1 3"<<std::endl<<std::endl;
	std::cout<<"| S | M | T | W | T | F | S |"<<std::endl;
	std::cout<<"+---+---+---+---+---+---+---+"<<std::endl;
	
	if(month==1)
	{
		for(i=1;i<=MIN_JAN_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=31;i++)
		{
			if(i==5||i==12||i==19||i==26)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_JAN_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==2)
	{
		for(i=1;i<=MIN_FEB_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=31;i++)
		{
			if(i==2||i==9||i==16||i==23||i==30)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_FEB_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==3)
	{
		for(i=1;i<=MIN_MAR_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=30;i++)
		{
			if(i==2||i==9||i==16||i==23||i==30)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_MAR_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==4)
	{
		for(i=1;i<=MIN_APR_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=30;i++)
		{
			if(i==6||i==13||i==20||i==27)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_APR_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==5)
	{
		for(i=1;i<=MIN_MAY_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=31;i++)
		{
			if(i==4||i==11||i==18||i==25)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_MAY_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==6)
	{
		for(i=1;i<=MIN_JUN_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=29;i++)
		{
			if(i==1||i==8||i==15||i==22||i==29)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
	}
	
	else if(month==7)
	{
		for(i=1;i<=MIN_JUL_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=31;i++)
		{
			if(i==6||i==13||i==20||i==27)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_JUL_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==8)
	{
		for(i=1;i<=MIN_AUG_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=31;i++)
		{
			if(i==3||i==10||i==17||i==24||i==31)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
	}
	
	else if(month==9)
	{
		for(i=1;i<=MIN_SEP_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=30;i++)
		{
			if(i==7||i==14||i==21||i==28)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_SEP_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==10)
	{
		for(i=1;i<=MIN_OCT_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=31;i++)
		{
			if(i==5||i==12||i==19||i==26)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
		for(i=0;i<=MAX_OCT_2013;i++)
		{
			std::cout<<"|   ";
		}
	}
	
	else if(month==11)
	{
		for(i=1;i<=MIN_NOV_2013;i++)
		{
			std::cout<<"|   ";
		}
		for(i=1;i<=30;i++)
		{
			if(i==2||i==9||i==16||i==23||i==30)
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" |"<<std::endl;
				}
				else
				{
					std::cout<<"| "<<i<<"|"<<std::endl;
				}
			}
			else
			{
				if(i<10)
				{
					std::cout<<"| "<<i<<" ";
				}
				else
				{
					std::cout<<"| "<<i;
				}
			}
		}
	}
	
	else
	{
		std::cout<<std::endl<<"IN THE INDIAN MONTH, THE CALENDAR ENDS ON NOVEMBER."<<std::endl;
	}
}

main()
{
	int month;
	
	std::cout<<"What month would you like us to print out?  ";
	std::cin>>month;
	std::cout<<std::endl<<std::endl;
	
	if(month>0 && month<13)
	{
		InterpretMonth(month);
	}
	else
	{
		std::cout<<"Out of range!";
	}
}


DO NOT USE THIS CODE: 1. It is extensive. and repetitive. 2. It is very long, complicated and takes up a lot of memory. USE THIS CODE ONLY AS AN EXAMPLE.
Last edited on
oh well i m sorry i havent used this forum before my friend provided me the address. i didn't have any idea that we are suppose to post our programs as well i m not asking for my homework
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
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
clrscr();
int a, b;
cout<<"\n\t\t\n";
cout<<"\t\t--------------------------------------\n";
cout<<"\t\tCALENDER FOR 2013\n";
cout<<"\t\t--------------------------------------\n\n";
cout<<"enter the month  you want calender for::";
cin>>a;
cout<<"enter the days of the month::";
cin>>b;
cout<<"\n";
if (a==1)
{cout<<"\t\tJANUARY\n\n";
}
else if (a==2)
{cout<<"\t\tFEBURARY\n\n";
}
else if (a==3)
{ cout<<"\t\tMARCH\n";
}
else if (a==4)
{
cout<<"\t\tAPRIL\n";
}
else if (a==5)
{
cout<<"\t\tMAY\n";

}
else if (a==6)
{
cout<<"\t\tJUNE\n";
}
else if (a==7)
{
cout<<"\t\tJULY\n";
}
else if (a==8)
{
cout<<"\t\tAUGEST\n";
}
else if (a==9)
{
cout<<"\t\tSEPTEMBER\n";
}
else if (a==10)
{
cout<<"\t\tOCTOBER\n";
}
else if (a==11)
{
cout<<"\t\tNOVEMBER\n";
}
else if (a==12)
{
cout<<"\t\tDECEMBER\n";
}
cout<<"Mon   Tue  Wed   Thu  Fri  Sat   Sun\n";
for (int i=1; i<=b; i++)
{cout<<i<<setw(6);
if (i%7==0)
{
cout<<"\n";
}}
cout<<"\n\n\t\t--------------------------------------";
getche();
}

i have formulated the clender but how can i specify that certain month should start either from saturday or any other day
Last edited on
1
2
3
4
5
...
std::cout<<"What day does the month start on (1-7) ?  ";
std::cin>>min;
for(i=min;i<=b;i++)
...


Also, please use code tags.
Please edit your post so it uses code tags. Select your code, then press the <> button on the right under formatting.

With your code there a couple of things you can do to start with.

Create an array of all the month names. Use an array index variable to access them with a for loop. This is much better than lots of else-if statements.

With the starting day, you need to calculate this. Start with a year that you know what day was 1 Jan. Calc the number of days since then to the start of the month, taking into account leap years. Remeber to make use of functions.

HTH
Topic archived. No new replies allowed.