Untitled
unknown
plain_text
2 years ago
1.2 kB
1
Indexable
#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); }
Editor is loading...