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
|
#include <iostream>
#include <fstream>
#include <sstream>
#include "CinReader.h"
#include <vector>
#include <string>
using namespace std;
CinReader reader;
struct entry
{
string day;
string event;
};
struct month
{
int year;
string months;
int firstDayinmo;
vector<entry> thismonth;
int dinmo;
};
void newJournal(month a[], int size);
void viewEdit (month a[], int size);
void ess(month a[], int size);
void printMonth (month a);
void centerstring(string& buff);
void clearScreen ();
//void save (month a[12], int size);
//void getJournal (month a[], int size);
//int monthCheck(int month,int year, month a[12]);
int main()
{
const int miny = 12;
month year[miny];
//int rows = 6;
//int days = 7;
//int array [rows][days];
cout << "Would you like to create a new Journal or work on an existing one?\n"
<< "1. Start new Journal\n"
<< "2. Work on existing one.\n";
int userchoice = reader.readInt(1,2);
switch (userchoice)
{
case 1:
newJournal(year, miny);
ess(year, miny);
break;
case 2:
//getJournal(year);
//ess();
break;
}
return 0;
}
void ess(month a[], int size)
{
bool quit = false;
while (quit == false)
{
system ("cls");
int mainchoice;
cout << "What would you like to do?\n"
<< "1. View and/or Edit Entry.\n"
<< "2. Search an Entry.\n"
<< "3. Save & Quit.\n"
<< endl;
mainchoice = reader.readInt(1,3);
switch (mainchoice)
{
case 1:
viewEdit(a,size);
break;
case 2:
//search(a,size);
break;
case 3:
quit = true;
break;
}
}
}
void viewEdit (month a[], int size)
{
bool quitEdit = 0;
while (quitEdit == 0)
{
bool quitMonth = 0;
cout << "Which month would you like?\n";
for (int i = 0; i < size; i++)
{
cout << (i+1) << ". " << a[i].months << endl;
}
int usermonth = reader.readInt(1,12);
int userchoice;
usermonth -= 1;
clearScreen();
printMonth (a[usermonth]);
while (quitMonth == 0)
{
cout << "Which day would you like? 1 - " << a[usermonth].dinmo << endl;
int userday = reader.readInt(1,a[usermonth].dinmo);
userday -= 1;
//in the array a sub usermonth inside vector sub userday get day and event
cout << a[usermonth].thismonth[userday].day << endl;
cout << a[usermonth].thismonth[userday].event << endl;
cout << "\n1. Replace entry?\n"
<< "2. Add to entry?\n"
<< "3. Back\n"
<< endl;
userchoice = reader.readInt(1,3);
switch (userchoice)
{
case 1:
a[usermonth].thismonth[userday].event = reader.readString();
break;
case 2:
a[usermonth].thismonth[userday].event = a[usermonth].thismonth[userday].event + "\n" + reader.readString();
break;
case 3:
clearScreen();
break;
}
cout << "\n1. Work on another day.\n"
<< "2. Back\n"
<< endl;
userchoice = reader.readInt(1,2);
switch (userchoice)
{
case 1:
clearScreen();
break;
case 2:
quitMonth = 1;
break;
}
}
cout << "\n\n1. Work on another month.\n"
<< "2. Back\n"
<< endl;
userchoice = reader.readInt(1,2);
switch (userchoice)
{
case 1:
clearScreen();
break;
case 2:
quitEdit = 1;
break;
}
}
}
void printMonth (month a)
{
int dayctr = 7;
string strbuffer;
string dayofweek[7] = {"Su ","M ","T ","W ","Th ","F ","Sa"};
strbuffer = a.months;
centerstring (strbuffer);
//print days of week
for (int i = 0; i < 7; i++)
{
strbuffer += dayofweek [i];
}
centerstring (strbuffer);
cout << "\n";
//decide where to start printing numbers
for (int j = 0; j < (7-a.firstDayinmo%7); j++)
{
cout << " ";
dayctr ++;
}
for (int k = 0; k < a.dinmo; k++)
{
if (dayctr%7 == 0)
{
cout << "\n";
centerstring(strbuffer);
}
if (k < 9)
cout << " "; //if single digit then allign
strbuffer += " ";
strbuffer += (k+1) + " ";
//cout << (k+1) << " ";
dayctr ++;
//cout << strbuffer;
}
}
void centerstring(string& buff)
{
int l= buff.length();
int position=((80-l)/2);
for(int i = 0; i<position; i++)
cout<<" ";
cout<< buff << endl;
buff.clear();
}
void newJournal(month a[], int size)
{
int firstDaysinmo[12] = {12,8,8,11,13,9,11,7,10,12,8,10};
int daysInmonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
string monthset[12] = {"January","Febuary","March","April","May","June","July","August","September","October","November","December"};
string dayofweek[7] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
cout << "Please tell me what year it is.\n";
int useryear = reader.readInt(2010,2020);
for (int i = 0; i < size; i++)
{
a[i].year = useryear;
a[i].months = monthset[i];
a[i].dinmo = daysInmonth[i];
a[i].firstDayinmo = firstDaysinmo[i];
for (int j = 0; j < daysInmonth[i]; j++)
{
entry e;
e.day = dayofweek [((firstDaysinmo [i] + (j))%7)];
e.event = "empty";
a[i].thismonth.push_back(e);
}
}
}
void clearScreen ()
{
#ifdef WIN32
system("cls");
#else
system("clear");
#endif
}
|