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
|
#include <iostream>
#include <string>
#include <iomanip>
#include "Date.h"
#include <fstream>
using namespace std;
void app1() ;
void app2() ;
void print_calendar( int year );
char *major[]={"New Year Day","MLK Birthday","Valentine's Day","President Day","St.Patrick's Day","April Fools","May Day","Mother's Day",
"Memorial Day","Father's Day","Independence Day","Labor Day",
"Columbus Day","Halloween","Election Day", "Veterans Day","Thanksgiving Day", "Christmas"};
char * dayofweek[] = {"Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"};
void print_calendar( int year, ostream &out );
void menu() {
cout << "\n\t\tType 1 for major holidays ";
cout << "\n\t\tType 2 for Calendar ";
cout <<"\n\t\tType 3 to quit.";
cout << "\n\n\t\tPlease enter your choice :";;
}
int main() {
int choice ;
cout << endl << endl << "\tWelcome to CSC262 Holidays/ Calendar System: \n\n";
while (true) {
menu() ;
cin >> choice ;
switch(choice) {
case 1: app1() ; break ;
case 2 : app2() ; break ;
case 3: break ;
default: cout << "\n\n\t\tInvalid choice \n"; break;
}
if ( choice == 3 ) break ;
}
cout << "\n\n\tThank you for using U.S. Major Holidays Calendar System! \n";
cout << "\n\n\t\tBye! \n\n";
return 0 ;
}
///////////////////////////////
Date NewYear(int yr) {
Date tmp(1,1,yr) ;
return tmp ;
}
// MLK day third monday of January
Date MLKDay(int yr) {
// I need help here!
}
Date Valentine(int yr) {
return Date(2,14,yr) ;
}
Date PresidentDay(int yr) { // 3rd monday of Febraury
// I need help here!
}
Date StPatrick(int yr) { //mar 17
Date temp(3,17,yr) ;
return temp;
}
Date AprilFool(int yr){
return Date(4,1,yr) ;
}
Date MayDay(int yr) { // May ist
Date tmp(5,1,yr) ;
return tmp ;
}
Date MotherDay(int yr) { // 2nd sunday in may
// I need help here!
}
Date MemorialDay(int yr) {
// function that returns a Date object which is the date for Memoriial day of year yr
// I need help here!
}
Date FatherDay(int yr) { // 3rd sunday in June
// I need help here!
}
Date IndependenceDay(int yr) { // July 4
Date tmp(7,4,yr) ;
return tmp;
}
Date Labor(int yr) {
// function that returns a Date object which is the date for Labor day of the year yr
// I need help here!
}
Date Columbus(int yr) { // second monday of october
// I need help here!
}
Date Halloween(int yr) {
Date tmp(11,1,yr) ; // november 1st, a day after Halloween
return --tmp ;
}
Date ElectionDay(int yr) { // 1st tuesday after 1st monday in november
// I need help here!
}
Date VeteransDay(int yr ) { // Nov 11
Date temp(11,11,yr) ;
return temp;
}
Date thanksgiving (int yr) {
// function that returns a Date object which is the date for Thanksgiving of the year yr
// the fourth thursday of Novemeber
// I need help here!
}
Date xmas(int yr) {
return Date(12,25,yr) ;
}
// an array of function pointers
Date (*fp[18])(int)= { NewYear, MLKDay,Valentine,PresidentDay,StPatrick,AprilFool,MayDay,MotherDay,MemorialDay,
FatherDay,IndependenceDay,Labor,Columbus, Halloween,ElectionDay,VeteransDay,thanksgiving,xmas } ;
void process( Date (*fun)(int), int yr, int index){
Date d = fun(yr) ;
// I need help here!
}
void app1() {
int yr ;
while(true) {
cout << "\tPlease enter the year (4 digits) or -1 to quit: " ;
cin >> yr ;
if ( yr < 0 ) break ;
cout << "\n\n\t\tMajor holidays for year " << yr << endl << endl;
for (int i = 0 ; i < 18 ; i++ ) process(fp[i],yr,i) ;
cout << endl << endl;
}
}
void app2() {
int yr ;
char resp[10];
string filename;
ofstream out;
cout << "\n\tDo your want to write to a file?";
cin >> resp;
if ( resp[0] == 'y' || resp[0] == 'Y'){
cout << "\n\tPlease enter the file name: ";
cin >> filename;
filename += ".txt";
out.open ( filename, ios::app );
}
while(true) {
cout << "\tPlease enter the year (4 digits) or -1 to quit: " ;
cin >> yr ;
if ( yr < 0 ) break ;
cout << "\n\n\t\tCalendar for year " << yr << endl << endl;
if ( resp[0] == 'y' || resp[0] == 'Y' ) print_calendar(yr,out) ;
else print_calendar(yr,cout) ;
cout << endl << endl;
}
if (resp[0] == 'y' || resp[0] == 'Y' ) out.close() ;
}
void print_calendar( int year, ostream &out ) {
// I need help here!
}
|