Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
0
Indexable
Never
#include <iostream>
#include <stdint.h>
#include <string>
// статические  <- 
// динамические 

struct CAT {
	uint8_t health; // unsigned int 8 bites
	std::string name;
	char colour;
	// указатель на подружку/друга КОТа 
	CAT* catfriend;
};

// добавь КОТОдруга
bool attachCatFriend(CAT *to, CAT *catfriend) {
	if (to != nullptr) to->catfriend = catfriend;
	else return false;

	if(catfriend != nullptr) catfriend->catfriend = to;

	return true;
}

bool changeColour(CAT *cat, char newColour) {
	if (cat != nullptr) cat->colour = newColour;
	else return 0;

	return 1;
}

void getCatInfo(CAT* cat) {
	if (cat == nullptr) {
		std::cout << "cat is dead\n";
		return;
	}
	if (cat->catfriend != nullptr)
		std::cout << cat->name << " druzhit s " << cat->catfriend->name << "!\n";
	else std::cout << cat->name << " hasn`t any friends :(\n";
}

int main()
{
	CAT ct;
	CAT secondCt;
	CAT catWithoutFriend;
	ct.name = "Barsik";
	secondCt.name = "Siplyi";
	if(attachCatFriend(&ct, &secondCt));
	getCatInfo(&ct);
	getCatInfo(&secondCt);
	CAT* p_cat = nullptr;
	getCatInfo(p_cat);
}