Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.2 kB
3
Indexable
Never
#include "Card.h"
#include <cstring>
#include <iostream>

/*char * name;
		char * author;
		int count;*/

Card::Card() {
	count = 0;

	name = new char[2];
	strcpy(name, " ");

	author = new char[2];
	strcpy(author, " ");
}

Card::Card(char* n, char* a, int c) {
	name = new char[strlen(n) + 1];
	strcpy_s(name,strlen(n)+1,  n); //VISUAL STUDIO

	author = new char[strlen(a) + 1];
	strcpy_s(author, strlen(a) + 1, a);

	count = c;

}

Card::~Card() {
	if (name != nullptr) {
		delete[]name;
	}
	if (author!= nullptr) {
		delete[]author;
	}
	
}

int Card::setCount(int cnt) {
	if (cnt >= 0) {
		count = cnt;
	}
	return 0;
}

int Card::setName(char* name) {
	if (this->name != nullptr) {
		delete[] this->name;
	}
	this->name = new char[strlen(name) + 1];
	strcpy(this->name, name);
	return 0;
}

int Card::setAuthor(char* auth) {
	{
		if (author != nullptr) {
			delete[] author;
		}
		author = new char[strlen(auth) + 1];
		strcpy(author, auth);
	}
	return 0;
}
int Card::print() const {
	std::cout << "Name " << name << std::endl;
	std::cout << "Author " << author << std::endl;
	std::cout << "Counter " << count << std::endl;
	return 0;
}