Advertisement
WupEly

Untitled

Oct 21st, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. using namespace std;
  5. class Animal {
  6. private:
  7. string pet, name;
  8. char sex;
  9. int price;
  10. int id;
  11. static int quantity;
  12.  
  13. int set_id() {
  14.  
  15. }
  16. public:
  17.  
  18.  
  19. Animal(string pet, string nzame, char sex, int price)
  20. {
  21.  
  22. this->name = name;
  23. this->pet = pet;
  24. if (sex == 'm' || sex == 'f') {
  25. this->sex = sex;
  26. }
  27. else {
  28. while (sex != 'm' && sex != 'f') {
  29. cout <<"sex did not recognize, please try again:" << endl;
  30. cin >> sex;
  31. }
  32. this -> sex = sex;
  33. }
  34.  
  35. this->price = price;
  36. quantity += 1;
  37. id = quantity - 1;
  38. }
  39.  
  40. ~Animal(){}
  41.  
  42. string get_sex() {
  43. if (this->sex == 'm')
  44. {
  45. return "male";
  46. }
  47. else if (this->sex == 'f') {
  48. return "female";
  49. }
  50. }
  51.  
  52. int get_quantity() {
  53. return this->quantity;
  54. }
  55.  
  56.  
  57.  
  58. };
  59.  
  60. int Animal::quantity = 0;
  61.  
  62. int main()
  63. {
  64. Animal cat("cat", "kit", 'f', 2100);
  65. Animal dog("d", "d", 'f', 2);
  66. cout << cat.get_quantity();
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement