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
|
#include <iostream>
#include<vector>
#include <fstream>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sstream>
using namespace std;
//strptime turns string into time. will not work in windows
class schedule
{
tm m_time;
public:
friend ostream& operator<<(ostream& os, const schedule & x);
schedule() { // generating November schedule
m_time.tm_sec = 0;
m_time.tm_min = 15 * (rand() % 3);
m_time.tm_hour = rand() % 10 + 7;
m_time.tm_mday = rand() % 30 + 1;
m_time.tm_mon = rand()%12;
m_time.tm_year = 114;
m_time.tm_wday = rand() % 7;
}
tm get() const
{
return m_time;
}
string return_type() const
{
return event_types;
}
};
class event : public schedule
{
string event_types;
public:
friend ostream& operator<<(ostream& os, const event& x);
event():schedule()
{
int num=rand()%2;
if(num == 0)
{
string party = "p";
event_types= party;
//party
}
if(num == 1)
{
string anni = "a";
event_types = anni;
// anii
}
}
string get_event_types() const
{
return event_types;
}
};
class duty : public schedule
{
string duty_type;
public:
friend ostream& operator<<(ostream& os, const duty & x);
duty():schedule()
{
int num = rand()%2;
if(num == 0)
{
string school = "s";
duty_type= school;
}
if(num == 1)
{
string family = "f";
duty_type = family;
}
}
string get_duty_types() const
{
return duty_type;
}
};
class Scheduler{
vector<schedule*> stuff;
public:
friend ostream& operator<<(ostream& os, const Scheduler& x);
void read(char*name)
{
}
void write(char*name)
{
ofstream myfile;
myfile.open(name);
for(int i=0; i<stuff.size(); i++)
{
myfile<<stuff[i]<<endl;
}
myfile.close();
}
Scheduler(int x);
};
Scheduler :: Scheduler(int x)
{
for(int i=0; i<x; i++)
{
int num = rand()%2;
if(num == 0)
{
//event
stuff.push_back(new event());
}
if(num==1)
{
// duty
stuff.push_back(new duty());
}
}
};
int main(){
srand (time(NULL));
Scheduler s(20);
s.write("scheduler.data");
cout << s;
/*cout << s;
s.write("scheduler.data);
s.order();
cout << "AFTER SORTING..." << endl << endl;
cout << s;
s.read("scheduler.data);
cout << s;
*/
return 0;
}
ostream& operator<<(ostream& os, const schedule* x)
{
//how to find the type of something
char*str;
}
ostream& operator<<(ostream& os, const Scheduler& x)
{
for(int i=0; i<x.stuff.size(); i++ )
{
os << x.stuff[i]<<endl;
}
return os;
}
ostream& operator<<(ostream& os, const event* x)
{
char*str;
tm temp=x->get();
strftime(str,10000,
"%c", &temp);
os<<"Event"<< x->get_event_types()<<str<<endl;
return os;
}
ostream& operator<<(ostream& os, const duty* x)
{
char*str;
tm temp=x->get();
strftime(str,10000,
"%c", &temp);
os<<"Duty"<< x->get_duty_types()<<str<<endl;
return os;
}
|