Skip to main content
Ctrl+K
Jörg Faschingbauer - Home Jörg Faschingbauer - Home
  • Training Courses
  • About
  • Blog
  • Training Courses
  • About
  • Blog

Section Navigation

  • Course Descriptions
  • Pricing, Organizational
  • Log Of Past Courses
  • Complete Slide Material
    • Linux: Introduction, Userland/Kernel Programming, Hardware/Embedded
    • Python Programming
    • C Programming
    • C++ Programming
      • C++ < 11
      • C++ >= 11
      • Design Patterns With C++
      • C++: Miscellaneous Live-Hacking
      • C++ Code
      • C++ Exercises
        • Working On Exercise Projects
        • OO Basics, Interfaces (Shapes)
        • C++ Exercises: Standard Template Library
        • Exercises: Design Patterns
        • FH Sensor OO (First Try)
        • Exercise: ConstantSensor_nopoly (Non-Polymorphic)
        • Exercise: RandomSensor_nopoly (Non-Polymorphic)
        • Exercise: MockSensor_nopoly (Non-Polymorphic)
        • Exercise: Mocking Switch (Non-Polymorphic)
        • Exercise: AveragingSensor_nopoly (Non-Polymorphic)
        • Exercise: Hysteresis_nopoly (Non-Polymorphic)
        • Exercise: LEDStripeDisplay_nopoly (Non-Polymorphic)
        • Exercise: Sensor Interface
        • Exercise: OneWire Sensor Class
        • Exercise: OneWire Sensor Factory
    • Build Tools, Unit Testing, Design, And More
  • Training Courses
  • Complete Slide Material
  • C++ Programming
  • C++ Exercises
  • Exercises: Design Patterns
  • Solutions
  • Solution: Proxy (Rounding Thermometer)

Solution: Proxy (Rounding Thermometer)#

  • Rounding Sensor (Proxy) Implementation

Rounding Sensor (Proxy) Implementation#

/trainings/material/soup/cxx/cxx-code/design-patterns-proxy/sensors/sensor-round.h#
#pragma once

#include "sensor.h"

#include <cmath>


class RoundingSensor : public Sensor
{
public:
    RoundingSensor(Sensor* sensor) : _sensor(sensor) {}

    virtual double get_temperature()
    {
        double value = _sensor->get_temperature();
        return std::round(value);
    }

private:
    Sensor* _sensor;
};
On this page
  • Rounding Sensor (Proxy) Implementation

© Copyright 2019-2025 (GPLv3), Jörg Faschingbauer.

Created using Sphinx 8.1.3.

Built with the PyData Sphinx Theme 0.16.1.

Show Source