Advertisement
NicholasB

Dairy

Mar 16th, 2025 (edited)
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | Software | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. // globals!
  7. const int dailyEstimate = 15; // In litres and when well fed.
  8.  
  9. // base class!
  10. class Animal {
  11.     public: int age;
  12.     public: string name;
  13.     public: string breed;
  14.  
  15. };
  16.  
  17. class DairyCow : public Animal {
  18.     protected: int milkProduction;
  19.     public: int feedingCost;
  20.  
  21.     // estimates milk production based on the cow’s breed and feeding cost
  22.     public: int  calculateMilkYield( DairyCow cow ) {
  23.         cout << "Calculatging MilkYeild for cow named :  !!" << cow.name << endl;
  24.         if ( cow.breed == "Friesian") {
  25.             cow.milkProduction = 25 / cow.age;
  26.         } else if (cow.breed == "Jersey") {
  27.             cow.milkProduction = 18  / cow.age;;
  28.         } else if (cow.breed == "Ayrshire") {
  29.             cow.milkProduction = 17  / cow.age;;
  30.         } else {
  31.             cow.milkProduction = 15  / cow.age;;
  32.         }
  33.  
  34.         if ( cow.feedingCost > 500 ) {
  35.             cow.milkProduction * 17  / cow.age;;
  36.         } else if ( cow.feedingCost > 300 ) {
  37.             cow.milkProduction * 13  / cow.age;;
  38.         } else {
  39.             cow.milkProduction * dailyEstimate  / cow.age;;
  40.         }
  41.  
  42.         return cow.milkProduction;
  43.  
  44.     }
  45. };
  46.  
  47. int main() {
  48.     DairyCow cow;
  49.  
  50.     // assign values to props: name, breed, age, feedingCost:
  51.     // @TODO the milkProduction is derived from the above values.
  52.     cout << "Please enter the FOUR cow details ( props ) below ::: " << endl;
  53.  
  54.     cout << "Enter Cow name : " << endl;
  55.     cin >> cow.name;
  56.     cout << "Entry assignment : Cow name  === " << cow.name << endl;
  57.  
  58.     cout << "Enter Cow breed eg Friesian, Jersey, Sahiwal etc : " << endl;
  59.     cin >> cow.breed;
  60.     cout << "Entry assignment : Cow breed  === " << cow.breed << endl;
  61.  
  62.     cout << "Enter Cow age eg 7 (for 7 yrs ): " << endl;
  63.     cin >> cow.age;
  64.     cout << "Entry assignment : Cow age  === " << cow.age << " years" << endl;
  65.  
  66.     cout << "Enter Cow feedingCost ( Kshs): " << endl;
  67.     cin >> cow.feedingCost;
  68.     cout << "Entry assignment : Cow feedingCost  === " << cow.feedingCost << " Kshs" << endl;
  69.     cout << "Exec calculateMilkYield ..... " << endl;
  70.  
  71.    cout << "Ze Yield for cow named :: " <<
  72.        cow.name << " is === " <<
  73.            cow.calculateMilkYield( cow ) << endl;
  74.  
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement