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
|
#include <fstream>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
using namespace std;
class ydm_notes
{
int year;
short day;
short month;
string notes;
public:
ydm_notes() {}
ydm_notes(int m_year, short m_day, short m_month, string m_notes) :
day (m_day), month (m_month), year (m_year), notes(m_notes) {}
~ydm_notes() {}
friend ostream & operator<<(ostream &, ydm_notes);
friend istream & operator>>(istream &, ydm_notes);
friend vector<ydm_notes> sort(vector<ydm_notes> vect);
friend ydm_notes getfirst(vector<ydm_notes> vect);
void input(istream & in)
{
cout << "Year: ";
in >> year;
cout << "Day: ";
in >> day;
cout << "Month: ";
in >> month;
cout << "Day's notes: ";
in.ignore(numeric_limits<streamsize>::max(), '\n');
getline(in, notes);
}
};
ostream & operator<<(ostream & out, ydm_notes obj)
{
out << obj.year << " " << obj.day << " " << obj.month << " notes: " << obj.notes << endl;
return out;
}
istream & operator>>(istream & in, ydm_notes obj)
{
in >> obj.year;
in >> obj.day;
in >> obj.month;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.ignore(numeric_limits<streamsize>::max(), ':');
getline(in, obj.notes);
return in;
}
vector<ydm_notes> sort(vector<ydm_notes> vect)
{
vector<ydm_notes> vect2;
vect2.push_back(getfirst(vect));
return vect2;
}
ydm_notes getfirst(vector<ydm_notes> vect)
{
for(int i = vect.size(); i > 0; i--)
{
for(int j = i; vect[j].year < vect[j-1].year; j--)
{
ydm_notes temp;
temp = vect[i];
vect[i] = vect[i-1];
vect[i-1] = temp;
}
for(int j = i; vect[j].year < vect[j-1].year; j--)
{
ydm_notes temp;
temp = vect[i];
vect[i] = vect[i-1];
vect[i-1] = temp;
}
for(int j = i; vect[j].month < vect[j-1].month; j--)
{
ydm_notes temp;
temp = vect[i];
vect[i] = vect[i-1];
vect[i-1] = temp;
}
}
return vect[0];
}
void editor(vector<ydm_notes> & vect, string file);
int main()
{
vector<ydm_notes> notesh;
while(true)
{
cout << "1: New File\n"
<< "2: Load File\n"
<< "3: Exit\n>";
int choice;
cin >> choice;
if(!cin || (choice < 1 || choice > 4) )
{
cout << "Invalid input. Press ENTER to continue.\n";
cin.clear();
cin.sync();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
continue;
}
else if(choice == 3)
return 0;
else if(choice == 2)
{
cout << "File to load?\n(Full path. NOTE: use 2 backslashes (\"\\\") between folders for engine reasons.)\n>";
string file;
getline(cin, file);
editor(notesh, file);
continue;
}
else if(choice == 1)
{
editor(notesh, "\0");
}
}
}
void editor(vector<ydm_notes> & vect, string file)
{
fstream FileStream;
cout << "How many notes to log?\n";
int num;
cin >> num;
for(int i = 0; i < num; i++)
{
vect[i].input(cin);
}
if(file != "\0")
FileStream.open(file.c_str(), ios::in | ios::out);
else
{
cout << "File to save to?\n(Full path. NOTE: use 2 backslashes (\"\\\") between folders for engine reasons.)\n>";
getline(cin, file);
FileStream.open(file.c_str(), ios::in | ios::out);
}
for(int i = num; !FileStream.eof(); i++)
FileStream >> vect[i];
sort(vect);
for(int i = 0; i < vect.size(); i++)
FileStream >> vect[i];
}
|