borisdexter

Servis za mobilni

Jan 28th, 2020
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. enum tip{smartphone,computer};
  6.  
  7. /*
  8. class InvalidDate{
  9. private:
  10. int date;
  11. public:
  12. InvalidDate(){}
  13. InvalidDate(int date){
  14. this->date=date;
  15. }
  16. void print(){
  17. cout<<"Device was made in "<<date<<endl;
  18. }
  19. };
  20. */
  21.  
  22. class InvalidProductionDate{
  23. private:
  24. char error[100];
  25. public:
  26. InvalidProductionDate(){}
  27. InvalidProductionDate(char error[]){
  28. strcpy(this->error,error);
  29. }
  30. void print(){
  31. cout<<error<<endl;
  32. }
  33. };
  34.  
  35. class Device{
  36. private:
  37. char model[100];
  38. tip tipUred;
  39. static float casovi;
  40. int godina;
  41. public:
  42. Device(){}
  43.  
  44. Device(char model[],tip tipUred,int godina){
  45. strcpy(this->model,model);
  46. this->tipUred=tipUred;
  47. this->godina=godina;
  48. }
  49. static void setPocetniCasovi(int x){
  50. casovi=x;
  51. }
  52.  
  53. /*
  54. bool operator==(Device &drugDevice){
  55. if((strcmp(this->model,drugDevice.model)==0)&&(this->godina==drugDevice.godina)){
  56. return true;
  57. }
  58. return false;
  59. }
  60. */
  61.  
  62. friend ostream& operator<<(ostream &out,Device &objekt){
  63. out<<objekt.model<<endl;
  64. if(objekt.tipUred==0){
  65. out<<"Mobilen ";
  66. }else{
  67. out<<"Laptop ";
  68. }
  69.  
  70. if(objekt.godina>2015&&objekt.tipUred==1){
  71. out<<casovi+4<<endl;
  72. }else if(objekt.godina>2015 || objekt.tipUred==1){
  73. out<<casovi+2<<endl;
  74. }else{
  75. out<<casovi<<endl;
  76. }
  77. return out;
  78. }
  79.  
  80. int getGodina(){
  81. return godina;
  82. }
  83.  
  84. ~Device(){}
  85.  
  86. };
  87. float Device::casovi=1;
  88.  
  89. class MobileServis{
  90. private:
  91. char adresa[100];
  92. Device *niza;
  93. int brojUredi;
  94. public:
  95. MobileServis(){
  96. niza=new Device[0];
  97. brojUredi=0;
  98. }
  99. MobileServis(char adresa[]){
  100. strcpy(this->adresa,adresa);
  101. niza=new Device[0];
  102. brojUredi=0;
  103. }
  104.  
  105. //mobileservis+=device;
  106. MobileServis &operator+=(Device &novDevice){
  107.  
  108. if(novDevice.getGodina()>2019 || novDevice.getGodina()<2000){
  109. throw InvalidProductionDate("Невалидна година на производство");
  110. }
  111.  
  112. Device *tempNiza=new Device[brojUredi];
  113. for(int i=0;i<brojUredi;i++){
  114. tempNiza[i]=niza[i];
  115. }
  116. niza=new Device[brojUredi+1];
  117. for(int i=0;i<brojUredi;i++){
  118. niza[i]=tempNiza[i];
  119. }
  120. niza[brojUredi]=novDevice;
  121. brojUredi++;
  122. delete []tempNiza;
  123. return *this;
  124. }
  125.  
  126. /*
  127. MobileServis &operator-=(Device &novUred){
  128. int flag=0;
  129. for(int i=0;i<brojUredi;i++){
  130. if(niza[i]==novUred){
  131. flag=1;
  132. break;
  133. }
  134. }
  135. if(flag==1){
  136. int brojac=0;
  137. Device *tempNiza=new Device[brojUredi];
  138. for(int i=0;i<brojUredi;i++){
  139. if(niza[i]==novUred){
  140. // ne praime nishto t.e. go skoknvame novUred objektot
  141. }else{
  142. tempNiza[brojac]=niza[i];
  143. brojac++;
  144. }
  145. }
  146. brojUredi--;
  147. niza=new Device[brojUredi];
  148. for(int i=0;i<brojUredi;i++){
  149. niza[i]=tempNiza[i];
  150. }
  151. delete []tempNiza;
  152. }
  153. return *this;
  154. }
  155.  
  156. */
  157.  
  158.  
  159. void pecatiCasovi(){
  160. cout<<"Ime: "<<adresa<<endl;
  161. for(int i=0;i<brojUredi;i++){
  162. cout<<niza[i];
  163. }
  164. }
  165.  
  166. ~MobileServis(){
  167. delete []niza;
  168. }
  169. };
  170. int main()
  171. {
  172. int testCase;
  173. cin >> testCase;
  174. char ime[100];
  175. int tipDevice;
  176. int godina;
  177. int n;
  178. Device devices[50];
  179. if (testCase == 1){
  180. cout << "===== Testiranje na klasite ======" << endl;
  181. cin >> ime;
  182. cin >> tipDevice;
  183. cin >> godina;
  184. Device ig(ime,(tip)tipDevice,godina);
  185. cin>>ime;
  186. MobileServis t(ime);
  187. cout<<ig;
  188. }
  189. if (testCase == 2){
  190. cout << "===== Testiranje na operatorot += ======" << endl;
  191. cin>>ime;
  192. cin >> n;
  193. MobileServis t(ime);
  194. for(int i=0;i<n;i++)
  195. {
  196. cin >> ime;
  197. cin >> tipDevice;
  198. cin >> godina;
  199. Device tmp(ime,(tip)tipDevice,godina);
  200. try{
  201. t+=tmp;
  202. }catch(InvalidProductionDate &objekt){
  203. objekt.print();
  204. }
  205. }
  206. t.pecatiCasovi();
  207. }
  208. if (testCase == 3){
  209. cout << "===== Testiranje na isklucoci ======" << endl;
  210. cin>>ime;
  211. cin >> n;
  212. MobileServis t(ime);
  213. for(int i=0;i<n;i++)
  214. {
  215. cin >> ime;
  216. cin >> tipDevice;
  217. cin >> godina;
  218. Device tmp(ime,(tip)tipDevice,godina);
  219. try{
  220. t+=tmp;
  221. }catch(InvalidProductionDate &objekt){
  222. objekt.print();
  223. }
  224. }
  225. t.pecatiCasovi();
  226. }
  227. if (testCase == 4){
  228. cout <<"===== Testiranje na konstruktori ======"<<endl;
  229. cin>>ime;
  230. cin >> n;
  231. MobileServis t(ime);
  232. for(int i=0;i<n;i++)
  233. {
  234. cin >> ime;
  235. cin >> tipDevice;
  236. cin >> godina;
  237. Device tmp(ime,(tip)tipDevice,godina);
  238. try{
  239. t+=tmp;
  240. }catch(InvalidProductionDate &objekt){
  241. objekt.print();
  242. }
  243. }
  244. MobileServis t2 = t;
  245. t2.pecatiCasovi();
  246. }
  247. if (testCase == 5){
  248. cout << "===== Testiranje na static clenovi ======" << endl;
  249. cin>>ime;
  250. cin >> n;
  251. MobileServis t(ime);
  252. for(int i=0;i<n;i++)
  253. {
  254. cin >> ime;
  255. cin >> tipDevice;
  256. cin >> godina;
  257. Device tmp(ime,(tip)tipDevice,godina);
  258.  
  259. try{
  260. t+=tmp;
  261. }catch(InvalidProductionDate &objekt){
  262. objekt.print();
  263. }
  264. }
  265. t.pecatiCasovi();
  266. cout << "===== Promena na static clenovi ======" << endl;
  267. Device::setPocetniCasovi(2);
  268. t.pecatiCasovi();
  269. }
  270.  
  271. if (testCase == 6){
  272. cout << "===== Testiranje na kompletna funkcionalnost ======" << endl;
  273. cin>>ime;
  274. cin >> n;
  275. MobileServis t(ime);
  276. for(int i=0;i<n;i++)
  277. {
  278. cin >> ime;
  279. cin >> tipDevice;
  280. cin >> godina;
  281. Device tmp(ime,(tip)tipDevice,godina);
  282. try{
  283. t+=tmp;
  284. }catch(InvalidProductionDate &objekt){
  285. objekt.print();
  286. }
  287. }
  288. Device::setPocetniCasovi(3);
  289. MobileServis t2 = t;
  290. t2.pecatiCasovi();
  291. }
  292. return 0;
  293. }
Advertisement
Add Comment
Please, Sign In to add comment