Advertisement
Guest User

Untitled

a guest
May 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Storage
  7. {
  8. char* hashCode;
  9. char* deviceName;
  10. unsigned capacityGB;
  11. unsigned usedCapacity;
  12.  
  13. Storage(){
  14. hashCode=0;
  15. deviceName=0;
  16. capacityGB=0;
  17. usedCapacity=0;
  18. }
  19. Storage(const char* name, const char* code, unsigned capacity, unsigned usedcap):capacityGB(capacity),usedCapacity(usedcap)
  20. {
  21. deviceName=new char[strlen(name)+1];
  22. strcpy(hashCode, deviceName);
  23. hashCode=new char[strlen(code)+1];
  24. strcpy(hashCode, code);
  25. }
  26. Storage(const Storage& x)
  27. {
  28. delete[] hashCode;
  29. delete[] deviceName;
  30. hashCode=new char[strlen(x.hashCode)+1];
  31. deviceName=new char[strlen(x.deviceName)+1];
  32. strcpy(hashCode, x.hashCode);
  33. strcpy(deviceName, x.deviceName);
  34. capacityGB=x.capacityGB;
  35. usedCapacity=x.usedCapacity;
  36. }
  37. ~Storage(){
  38. delete[] hashCode;
  39. delete[] deviceName;
  40. }
  41. Storage& operator=(const Storage& x)
  42. {
  43. if(this!=&x)
  44. {
  45. delete[] hashCode;
  46. delete[] deviceName;
  47. hashCode=new char[strlen(x.hashCode)+1];
  48. deviceName=new char[strlen(x.deviceName)+1];
  49. strcpy(hashCode, x.hashCode);
  50. strcpy(deviceName, x.deviceName);
  51. capacityGB=x.capacityGB;
  52. usedCapacity=x.usedCapacity;
  53. }
  54. return *this;
  55. }
  56.  
  57. const char* getDeviceName(){ return deviceName;}
  58. const char* getHashCode(){ return hashCode;}
  59. unsigned getCapacity(){return capacityGB;}
  60. unsigned getUsedCapacity(){return usedCapacity;}
  61.  
  62. void setName(const char* newname){
  63. delete[] deviceName;
  64. deviceName=new char[strlen(newname)+1];
  65. strcpy(deviceName, newname);
  66. }
  67. void setHash(const char* newhash){
  68. delete[] hashCode;
  69. hashCode=new char[strlen(newhash)+1];
  70. strcpy(hashCode, newhash);
  71. }
  72. };
  73.  
  74. class OnlineService
  75. {
  76. unsigned port;
  77. unsigned connectedDevices;
  78. unsigned maxConnections;
  79. bool isOn;
  80. OnlineService(){
  81. port=0;
  82. connectedDevices=0;
  83. maxConnections=0;
  84. isOn=false;
  85. }
  86. OnlineService(unsigned _port, unsigned _connectedDevices, unsigned _maxConnections):port(port),connectedDevices(_connectedDevices),maxConnections(_maxConnections)
  87. {
  88. isOn=false;
  89. }
  90. //ne ni trqbva dekonstruktor ili copyconstructor ili =operator, ne izpolzvame dinamichna pamet
  91. void setPort(unsigned newport)
  92. {
  93. port=newport;
  94. }
  95. unsigned getPort(){ return port;}
  96. void turnOn(){
  97. if(isOn)
  98. {
  99. cout<<"Device is already on!";
  100. }
  101. else if(maxConnections>0 && port!=0)
  102. {
  103. isOn=true;
  104. cout<<"Successfully turned on device!";
  105. }
  106. else
  107. {
  108. cout<<"Could not turn device on!";
  109. }
  110. }
  111. void turnOff()
  112. {
  113. if(!isOn)
  114. {
  115. cout<<"Device is already off!";
  116. }
  117. else{
  118. isOn=false;
  119. cout<<"Device turned off successfully";
  120. }
  121.  
  122. }
  123. };
  124.  
  125.  
  126. int main()
  127. {
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement