Brian Silverman | 4e662aa | 2022-05-11 23:10:19 -0700 | [diff] [blame^] | 1 | // Copyright 2020 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 | |
| 16 | class Goat { |
| 17 | public: |
| 18 | Goat() : horns(0) {} |
| 19 | void add_a_horn(); |
| 20 | std::string describe() const; |
| 21 | private: |
| 22 | uint32_t horns; |
| 23 | }; |
| 24 | |
| 25 | inline uint32_t DoMath(uint32_t a) { |
| 26 | return a * 3; |
| 27 | } |
| 28 | |
| 29 | inline void Goat::add_a_horn() { horns++; } |
| 30 | inline std::string Goat::describe() const { |
| 31 | std::ostringstream oss; |
| 32 | std::string plural = horns == 1 ? "" : "s"; |
| 33 | oss << "This goat has " << horns << " horn" << plural << "."; |
| 34 | return oss.str(); |
| 35 | } |