blob: dd37dfa6f94c1cff1de120bfa94b1dbb21136fe0 [file] [log] [blame]
Brian Silvermanf3ec38b2022-07-06 20:43:36 -07001// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#pragma once
10
11#include <cstdint>
12#include <sstream>
13#include <stdint.h>
14#include <string>
15
16class Goat {
17public:
18 Goat() : horns(0) {}
19 void add_a_horn();
20 std::string describe() const;
Austin Schuh6ea9bfa2023-08-06 19:05:10 -070021 uint32_t& get_horns() { return horns; }
Brian Silvermanf3ec38b2022-07-06 20:43:36 -070022private:
23 uint32_t horns;
24};
25
26
27inline void Goat::add_a_horn() { horns++; }
28inline std::string Goat::describe() const {
29 std::ostringstream oss;
30 std::string plural = horns == 1 ? "" : "s";
31 oss << "This goat has " << horns << " horn" << plural << ".";
32 return oss.str();
33}
34
35class Field {
36public:
37 const Goat& get_goat() const {
38 return the_goat;
39 }
40
41private:
42 Goat the_goat;
43};