Advertisement
borisdexter

Parking Plac

Jan 27th, 2020
1,195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. class Avtomobil{
  6. private:
  7. char boja[20];
  8. char brend[20];
  9. char model[20];
  10. public:
  11. Avtomobil(){}
  12. Avtomobil(char boja[],char brend[20],char model[20]){
  13. strcpy(this->boja,boja);
  14. strcpy(this->brend,brend);
  15. strcpy(this->model,model);
  16. }
  17.  
  18. Avtomobil &operator=(Avtomobil &novObjekt){
  19. if(this!=&novObjekt){
  20. strcpy(this->boja,novObjekt.boja);
  21. strcpy(this->brend,novObjekt.brend);
  22. strcpy(this->model,novObjekt.model);
  23. }
  24. return *this;
  25. }
  26.  
  27. void print(){
  28. cout<<"Avtomobil: "<<model<<" "<<brend<<" "<<boja<<endl;
  29. }
  30. ~Avtomobil(){}
  31. };
  32.  
  33. class ParkingPlac{
  34. private:
  35. char adresa[20];
  36. char *id;
  37. int cena;
  38. int zarabotka;
  39. Avtomobil *niza;
  40. // brojot na avtomobili
  41. int n;
  42. public:
  43. ParkingPlac(){
  44. id=new char[0];
  45. niza=new Avtomobil[0];
  46. n=0;
  47. }
  48.  
  49. ParkingPlac(char adresa[],char *id,int cena){
  50. strcpy(this->adresa,adresa);
  51. this->id=new char[strlen(id)+1];
  52. strcpy(this->id,id);
  53. this->cena=cena;
  54. niza=new Avtomobil[0];
  55. n=0;
  56. this->zarabotka=0;
  57. }
  58.  
  59. void parkirajVozilo(Avtomobil &novoVozilo){
  60. Avtomobil *tempNiza=new Avtomobil[n];
  61. for(int i=0;i<n;i++){
  62. // operator = povik
  63. tempNiza[i]=niza[i];
  64. }
  65. niza=new Avtomobil[n+1];
  66. for(int i=0;i<n;i++){
  67. niza[i]=tempNiza[i];
  68. }
  69. niza[n]=novoVozilo;
  70. n++;
  71. delete []tempNiza;
  72. }
  73.  
  74. void pecatiParkiraniVozila(){
  75. cout<<"ParkingPlac: "<<adresa<<endl;
  76. for(int i=0;i<n;i++){
  77. niza[i].print();
  78. }
  79. }
  80.  
  81. void pecati(){
  82. if(zarabotka!=0){
  83. cout<<id<<" "<<adresa<<" "<<zarabotka<<" denari"<<endl;
  84. }else{
  85. cout<<id<<" "<<adresa<<endl;
  86. }
  87. }
  88.  
  89. void platiCasovi(int casovi){
  90. zarabotka+=casovi*cena;
  91. }
  92.  
  93. bool daliIstaAdresa(ParkingPlac p){
  94. if(strcmp(this->adresa,p.adresa)==0){
  95. return true;
  96. }
  97. return false;
  98. }
  99.  
  100. char* getId(){
  101. return id;
  102. }
  103.  
  104. ~ParkingPlac(){
  105. delete []id;
  106. }
  107. };
  108.  
  109. int main(){
  110.  
  111. ParkingPlac p[100];
  112. int n,m;
  113. char adresa[50],id[50];
  114. int brojcasovi,cenacas;
  115. cin>>n;
  116. if(n > 0){
  117. for (int i=0;i<n;i++){
  118. cin.get();
  119. cin.getline(adresa,50);
  120. cin>>id>>cenacas;
  121. ParkingPlac edna(adresa,id,cenacas);
  122. p[i]=edna;
  123. }
  124. //plakjanje
  125. cin>>m;
  126. for (int i=0;i<m;i++){
  127.  
  128. cin>>id>>brojcasovi;
  129.  
  130. int findId=false;
  131. for (int j=0;j<m;j++){
  132. //cout << p[j].getId() << endl;
  133. if (strcmp(p[j].getId(),id)==0){
  134. p[j].platiCasovi(brojcasovi);
  135. findId=true;
  136. }
  137. }
  138. if (!findId)
  139. cout<<"Ne e platen parking. Greshen ID."<<endl;
  140. }
  141. cout<<"========="<<endl;
  142. ParkingPlac pCentar("Cvetan Dimov","C10",80);
  143. for (int i=0;i<n;i++)
  144. if (p[i].daliIstaAdresa(pCentar))
  145. p[i].pecati();
  146. } else {
  147. ParkingPlac najdobarPlac("Mars", "1337", 1);
  148. int brVozila;
  149. cin >> brVozila;
  150. for(int i = 0; i < brVozila; ++i){
  151.  
  152. char boja[20];
  153. char brend[20];
  154. char model[20];
  155.  
  156. cin >> boja >> brend >> model;
  157. Avtomobil novAvtomobil(boja, brend, model);
  158. // isto so += operator
  159. najdobarPlac.parkirajVozilo(novAvtomobil);
  160. }
  161. if(brVozila != 0)
  162. najdobarPlac.pecatiParkiraniVozila();
  163. }
  164. return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement