Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string.h>
- class Battery
- {
- private:
- char* name;
- int size;
- public:
- Battery(char* name, int size)
- {
- if (name == nullptr)
- {
- this->name = nullptr;
- }
- else
- {
- this->name = new char(strlen(name) + 1);
- }
- this->size = size;
- }
- Battery(const Battery& battery)
- {
- this->size = battery.size;
- if (this->name != nullptr)
- {
- delete[] this->name;
- }
- if (battery.name == nullptr)
- {
- this->name = nullptr;
- return;
- }
- this->name = new char[strlen(battery.name) + 1];
- strcpy(this->name, battery.name);
- }
- ~Battery()
- {
- if (name != nullptr)
- {
- delete[] name;
- }
- }
- void setName(char* name)
- {
- if (this->name != nullptr)
- {
- delete[] this->name;
- }
- if (name == nullptr)
- {
- this->name = nullptr;
- return;
- }
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- }
- char* getName()
- {
- char* toReturn = new char[strlen(this->name) + 1];
- strcpy(toReturn, this->name);
- return toReturn;
- }
- void setSize(int size)
- {
- this->size = size;
- }
- int getSize()
- {
- return size;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment