paranid5

Cat class

Jun 4th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. //cat.h
  2.  
  3. #ifndef CAT_H
  4. #define CAT_H
  5. #include <string>
  6.  
  7. class Cat
  8. {
  9. public:
  10.     Cat(std::string, std::string, unsigned short);
  11.  
  12.     void set_name(std::string);
  13.  
  14.     void set_color(std::string);
  15.  
  16.     void set_age(unsigned short);
  17.  
  18.     std::string get_name() const;
  19.  
  20.     std::string get_color() const;
  21.  
  22.     unsigned short get_age() const;
  23.  
  24.     void voice();
  25.  
  26.     void eat();
  27.  
  28.     void sleep();
  29.  
  30.     void hunt();
  31.  
  32. private:
  33.     std::string name_;
  34.     std::string color_;
  35.     unsigned short age_;
  36. };
  37.  
  38. #endif // CAT_H
  39.  
  40. //cat.cpp
  41.  
  42. #include "cat.h"
  43.  
  44. Cat::Cat(std::string name, std::string color, const unsigned short age)
  45. {
  46.     name_ = name;
  47.     color_ = color;
  48.     age_ = age;
  49. }
  50.  
  51. void Cat::set_name(std::string name)
  52. {
  53.     if (!name.empty() && name != " ")
  54.         name_ = name;
  55. }
  56.  
  57. void Cat::set_color(std::string color)
  58. {
  59.     if (!color.empty() && color != " ")
  60.         color_ = color;
  61. }
  62.  
  63. void Cat::set_age(const unsigned short age)
  64. {
  65.     if (age < 31)
  66.         age_ = age;
  67. }
  68.  
  69. std::string Cat::get_name() const
  70. {
  71.     const std::string name = name_;
  72.     return name;
  73. }
  74.  
  75. std::string Cat::get_color() const
  76. {
  77.     const std::string color = color_;
  78.     return color;
  79. }
  80.  
  81. unsigned short Cat::get_age() const
  82. {
  83.     const unsigned short age = age_;
  84.     return age;
  85. }
  86.  
  87. void Cat::voice()
  88. {
  89.     puts("Voice");
  90. }
  91.  
  92. void Cat::eat()
  93. {
  94.     puts("Eat");
  95. }
  96.  
  97. void Cat::sleep()
  98. {
  99.     puts("Disable");
  100. }
  101.  
  102. void Cat::hunt()
  103. {
  104.     puts("Hunt");
  105. }
Advertisement
Add Comment
Please, Sign In to add comment