Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <istream>
- #include <string>
- #include <string.h>
- #include <cstdlib>
- using namespace std;
- //Tanulmányi rendszer osztály
- class TanulmanyiRendszer {
- protected:
- string url;
- public:
- TanulmanyiRendszer(string url);
- ~TanulmanyiRendszer();
- virtual bool bejelentkezes() = 0;
- virtual bool kurzusfelvetel(const char* courseCode) = 0;
- };
- //etr gyerek osztály
- class etr : public TanulmanyiRendszer {
- public:
- etr(string url) : TanulmanyiRendszer(url) {};
- etr():TanulmanyiRendszer("asd") {};
- bool bejelentkezes();
- bool kurzusfelvetel(const char* courseCode);
- void setUrl(string url) {
- this->url=url;
- }
- string getUrl() {
- return this->url;
- }
- };
- //neptun gyerekosztály
- class neptun : public TanulmanyiRendszer {
- private:
- const char* style;
- public:
- neptun(const char* , const char* );
- //neptun(const char* url, const char* style) : TanulmanyiRendszer(url) {};
- bool bejelentkezes();
- bool kurzusfelvetel(const char* courseCode);
- void temavalt(const char* style);
- };
- class ETRArmy {
- public:
- int count;
- bool is_init=false;
- etr** ETRObject;
- ETRArmy(int);
- void init(string[]);
- ~ETRArmy();
- etr operator[] (int i) {
- if (this->ETRObject[i] == nullptr) {
- cout << "Itt már nincs ETR, kérlek nézz vissza később Neptunért, az egységes tanulmányi rendszerért!"<< endl;
- }
- return *(this->ETRObject[i]);
- };
- void operator()(int a) {
- delete this->ETRObject[a];
- this->ETRObject[a] = nullptr;
- cout << "Egy ETR rendszert sikeresen eltávolítottunk, de aggodalomra semmi ok, hamarosan Neptunként visszatér közénk!" << endl;
- }
- };
- void ETRArmy::init(string urls[]) {
- if(this->is_init == false) {
- for(int i=0;i<this->count;i++) {
- this->ETRObject[i] = new etr(urls[i]);
- }
- this->is_init = true;
- } else {
- cout << "Új ETR nem csatlakozhat a sereghez, és a meglévők is hamarosan Neptunná válnak!" << endl;
- }
- }
- ETRArmy::ETRArmy(int count){
- this->count = count;
- this->ETRObject = new etr*[count];
- }
- ETRArmy::~ETRArmy() {
- for (int i = 0; i < this->count; i++) {
- delete this->ETRObject[i];
- this->ETRObject[i] = nullptr;
- }
- delete[] this->ETRObject;
- }
- TanulmanyiRendszer::TanulmanyiRendszer(string url) {
- this->url=url;
- //strcpy_s(this->url, sizeof(url), url);
- }
- TanulmanyiRendszer::~TanulmanyiRendszer() {
- //delete[] url;
- }
- bool etr::bejelentkezes() {
- cout << "Sikeres bejelentezés" << endl;
- return true;
- }
- bool etr::kurzusfelvetel(const char* courseCode) {
- cout << "Az ETR tanulmányi rendszer 2017.04.06 - án 16:00 - kor leállt." << endl;
- return false;
- }
- bool neptun::bejelentkezes() {
- double val = (double)rand() / RAND_MAX;
- int random;
- if (val < 0.90) {
- random = true;
- cout << "Sikeres bejelentkezés" << endl;
- }
- else {
- cout << "The service is unavailable." << endl;
- random = false;
- }
- return random;
- }
- bool neptun::kurzusfelvetel(const char* courseCode) {
- double val = (double)rand() / RAND_MAX;
- bool returned = true;
- if (val < 0.20) {
- returned = false;
- cout << "Hiba! A kurzusfelvétel nem sikerült, mert nem sikerült a tárgyfelvétel." << endl;
- }
- else {
- string line;
- ifstream f("list.txt");
- if (f.good()) {
- while (getline(f, line).good()) {
- if (line == courseCode) {
- cout << "Hiba! A kurzusfelvétel nem sikerült, mert nem sikerült a tárgyfelvétel." << endl;
- returned = false;
- }
- }
- f.close();
- }
- if (returned == true) {
- fstream file;
- file.open("list.txt", ios::out | ios::binary);
- file << courseCode << endl;
- file.close();
- }
- }
- return returned;
- }
- void neptun::temavalt(const char* style) {
- this->style = new char[strlen(style) + 1];
- //strcpy(this->style, style);
- this->style = style;
- cout << "Az új téma: " << this->style << endl;
- }
- neptun::neptun(const char* url, const char* style) : TanulmanyiRendszer(url) {
- this->style = new char[strlen(style) + 1];
- //strcpy(this->style, style);
- this->style = style;
- }
- int main() {
- ETRArmy* m4 = new ETRArmy(3);
- string urls[] = {"abc", "xyz", "asd"};
- m4->init(urls);
- // m4(1);
- m4[1];
- //m4(2);
- m4[2];
- //m4(3);
- m4[3];
- m4->init(urls);
- delete m4;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement