Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cat.h
- #ifndef CAT_H
- #define CAT_H
- #include <string>
- class Cat
- {
- public:
- Cat(std::string, std::string, unsigned short);
- void set_name(std::string);
- void set_color(std::string);
- void set_age(unsigned short);
- std::string get_name() const;
- std::string get_color() const;
- unsigned short get_age() const;
- void voice();
- void eat();
- void sleep();
- void hunt();
- private:
- std::string name_;
- std::string color_;
- unsigned short age_;
- };
- #endif // CAT_H
- //cat.cpp
- #include "cat.h"
- Cat::Cat(std::string name, std::string color, const unsigned short age)
- {
- name_ = name;
- color_ = color;
- age_ = age;
- }
- void Cat::set_name(std::string name)
- {
- if (!name.empty() && name != " ")
- name_ = name;
- }
- void Cat::set_color(std::string color)
- {
- if (!color.empty() && color != " ")
- color_ = color;
- }
- void Cat::set_age(const unsigned short age)
- {
- if (age < 31)
- age_ = age;
- }
- std::string Cat::get_name() const
- {
- const std::string name = name_;
- return name;
- }
- std::string Cat::get_color() const
- {
- const std::string color = color_;
- return color;
- }
- unsigned short Cat::get_age() const
- {
- const unsigned short age = age_;
- return age;
- }
- void Cat::voice()
- {
- puts("Voice");
- }
- void Cat::eat()
- {
- puts("Eat");
- }
- void Cat::sleep()
- {
- puts("Disable");
- }
- void Cat::hunt()
- {
- puts("Hunt");
- }
Advertisement
Add Comment
Please, Sign In to add comment