Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <istream>
  4. #include <string>
  5. #include <string.h>
  6. #include <cstdlib>
  7.  
  8. using namespace std;
  9.  
  10. //Tanulmányi rendszer osztály
  11. class TanulmanyiRendszer {
  12. protected:
  13. string url;
  14. public:
  15. TanulmanyiRendszer(string url);
  16. ~TanulmanyiRendszer();
  17. virtual bool bejelentkezes() = 0;
  18. virtual bool kurzusfelvetel(const char* courseCode) = 0;
  19.  
  20. };
  21.  
  22. //etr gyerek osztály
  23. class etr : public TanulmanyiRendszer {
  24. public:
  25. etr(string url) : TanulmanyiRendszer(url) {};
  26. etr():TanulmanyiRendszer("asd") {};
  27. bool bejelentkezes();
  28. bool kurzusfelvetel(const char* courseCode);
  29. void setUrl(string url) {
  30. this->url=url;
  31. }
  32. };
  33. //neptun gyerekosztály
  34. class neptun : public TanulmanyiRendszer {
  35. private:
  36. const char* style;
  37. public:
  38. neptun(const char* , const char* );
  39. //neptun(const char* url, const char* style) : TanulmanyiRendszer(url) {};
  40. bool bejelentkezes();
  41. bool kurzusfelvetel(const char* courseCode);
  42. void temavalt(const char* style);
  43. };
  44.  
  45. class ETRArmy {
  46. public:
  47. int count;
  48. etr* ETRObject;
  49. ETRArmy(int);
  50. void init(string[]);
  51. ~ETRArmy();
  52. etr& operator[] (int i) {
  53. return this->ETRObject[i];
  54. };
  55.  
  56. void operator () ( int a ) {
  57. etr* TMPETRObject;
  58. for (int i=0;i<(sizeof ETRObject / sizeof ETRObject[0]);i++) {
  59. if (i>=a) {
  60. TMPETRObject[i-1] = this->ETRObject[i];
  61. } else {
  62. TMPETRObject[i] = this->ETRObject[i];
  63. }
  64. }
  65. delete[] ETRObject;
  66.  
  67. for (int i=0;i<(sizeof TMPETRObject / sizeof TMPETRObject[0]);i++) {
  68. this->ETRObject[i] = TMPETRObject[i];
  69. }
  70. delete[] TMPETRObject;
  71.  
  72. cout << "Egy ETR rendszert sikeresen eltávolítottunk, de aggodalomra semmi ok, hamarosan Neptunként visszatér közénk!" << endl;
  73. }
  74. };
  75.  
  76. void ETRArmy::init(string urls[]) {
  77. for(int i =0; i<this->count; i++){
  78. this->ETRObject[i].setUrl(urls[i]);
  79. }
  80. }
  81.  
  82. ETRArmy::ETRArmy(int count){
  83. this->count = count;
  84. this->ETRObject = new etr[count];
  85. }
  86.  
  87. ETRArmy::~ETRArmy() {
  88. if (ETRObject != NULL) {
  89. delete[] ETRObject;
  90. }
  91. }
  92.  
  93. TanulmanyiRendszer::TanulmanyiRendszer(string url) {
  94. this->url=url;
  95. //strcpy_s(this->url, sizeof(url), url);
  96. }
  97.  
  98. TanulmanyiRendszer::~TanulmanyiRendszer() {
  99. //delete[] url;
  100. }
  101.  
  102. bool etr::bejelentkezes() {
  103. cout << "Sikeres bejelentezés" << endl;
  104. return true;
  105. }
  106.  
  107. bool etr::kurzusfelvetel(const char* courseCode) {
  108. cout << "Az ETR tanulmányi rendszer 2017.04.06 - án 16:00 - kor leállt." << endl;
  109. return false;
  110. }
  111.  
  112. bool neptun::bejelentkezes() {
  113. double val = (double)rand() / RAND_MAX;
  114. int random;
  115. if (val < 0.90) {
  116. random = true;
  117. cout << "Sikeres bejelentkezés" << endl;
  118. }
  119. else {
  120. cout << "The service is unavailable." << endl;
  121. random = false;
  122. }
  123. return random;
  124. }
  125.  
  126. bool neptun::kurzusfelvetel(const char* courseCode) {
  127. double val = (double)rand() / RAND_MAX;
  128. bool returned = true;
  129.  
  130. if (val < 0.20) {
  131. returned = false;
  132. cout << "Hiba! A kurzusfelvétel nem sikerült, mert nem sikerült a tárgyfelvétel." << endl;
  133. }
  134. else {
  135. string line;
  136. ifstream f("list.txt");
  137. if (f.good()) {
  138. while (getline(f, line).good()) {
  139. if (line == courseCode) {
  140. cout << "Hiba! A kurzusfelvétel nem sikerült, mert nem sikerült a tárgyfelvétel." << endl;
  141. returned = false;
  142. }
  143. }
  144. f.close();
  145. }
  146.  
  147. if (returned == true) {
  148. fstream file;
  149. file.open("list.txt", ios::out | ios::binary);
  150. file << courseCode << endl;
  151. file.close();
  152. }
  153. }
  154. return returned;
  155. }
  156.  
  157. void neptun::temavalt(const char* style) {
  158. this->style = new char[strlen(style) + 1];
  159. //strcpy(this->style, style);
  160. this->style = style;
  161. cout << "Az új téma: " << this->style << endl;
  162. }
  163.  
  164. neptun::neptun(const char* url, const char* style) : TanulmanyiRendszer(url) {
  165. this->style = new char[strlen(style) + 1];
  166. //strcpy(this->style, style);
  167. this->style = style;
  168.  
  169. }
  170.  
  171. int main() {
  172. /* etr a("https://etr.u-szeged.hu");
  173. etr* d = &a;
  174. d->bejelentkezes();
  175. d->kurzusfelvetel("ibl45");
  176.  
  177. neptun b("https://neptun.u-szeged.hu", "lila");
  178. neptun* c = &b;
  179. c->bejelentkezes();
  180. // c->kurzusfelvetel("ibl345");
  181. c->temavalt("kek");*/
  182. ETRArmy a(3);
  183. string url[] = {"abc", "xyz", "asd"};
  184. ETRArmy* c = &a;
  185. //c->init(url);
  186.  
  187.  
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement