Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Storage
- {
- char* hashCode;
- char* deviceName;
- unsigned capacityGB;
- unsigned usedCapacity;
- Storage(){
- hashCode=0;
- deviceName=0;
- capacityGB=0;
- usedCapacity=0;
- }
- Storage(const char* name, const char* code, unsigned capacity, unsigned usedcap):capacityGB(capacity),usedCapacity(usedcap)
- {
- deviceName=new char[strlen(name)+1];
- strcpy(hashCode, deviceName);
- hashCode=new char[strlen(code)+1];
- strcpy(hashCode, code);
- }
- Storage(const Storage& x)
- {
- delete[] hashCode;
- delete[] deviceName;
- hashCode=new char[strlen(x.hashCode)+1];
- deviceName=new char[strlen(x.deviceName)+1];
- strcpy(hashCode, x.hashCode);
- strcpy(deviceName, x.deviceName);
- capacityGB=x.capacityGB;
- usedCapacity=x.usedCapacity;
- }
- ~Storage(){
- delete[] hashCode;
- delete[] deviceName;
- }
- Storage& operator=(const Storage& x)
- {
- if(this!=&x)
- {
- delete[] hashCode;
- delete[] deviceName;
- hashCode=new char[strlen(x.hashCode)+1];
- deviceName=new char[strlen(x.deviceName)+1];
- strcpy(hashCode, x.hashCode);
- strcpy(deviceName, x.deviceName);
- capacityGB=x.capacityGB;
- usedCapacity=x.usedCapacity;
- }
- return *this;
- }
- const char* getDeviceName(){ return deviceName;}
- const char* getHashCode(){ return hashCode;}
- unsigned getCapacity(){return capacityGB;}
- unsigned getUsedCapacity(){return usedCapacity;}
- void setName(const char* newname){
- delete[] deviceName;
- deviceName=new char[strlen(newname)+1];
- strcpy(deviceName, newname);
- }
- void setHash(const char* newhash){
- delete[] hashCode;
- hashCode=new char[strlen(newhash)+1];
- strcpy(hashCode, newhash);
- }
- };
- class OnlineService
- {
- unsigned port;
- unsigned connectedDevices;
- unsigned maxConnections;
- bool isOn;
- OnlineService(){
- port=0;
- connectedDevices=0;
- maxConnections=0;
- isOn=false;
- }
- OnlineService(unsigned _port, unsigned _connectedDevices, unsigned _maxConnections):port(port),connectedDevices(_connectedDevices),maxConnections(_maxConnections)
- {
- isOn=false;
- }
- //ne ni trqbva dekonstruktor ili copyconstructor ili =operator, ne izpolzvame dinamichna pamet
- void setPort(unsigned newport)
- {
- port=newport;
- }
- unsigned getPort(){ return port;}
- void turnOn(){
- if(isOn)
- {
- cout<<"Device is already on!";
- }
- else if(maxConnections>0 && port!=0)
- {
- isOn=true;
- cout<<"Successfully turned on device!";
- }
- else
- {
- cout<<"Could not turn device on!";
- }
- }
- void turnOff()
- {
- if(!isOn)
- {
- cout<<"Device is already off!";
- }
- else{
- isOn=false;
- cout<<"Device turned off successfully";
- }
- }
- };
- int main()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement