- NVIDIA GeForce RTX 4080 /4080S / 4090 (AD103 / 102)
- TCL LCD és LED TV-k
- Azonnali VGA-s kérdések órája
- HiFi műszaki szemmel - sztereó hangrendszerek
- Kompakt vízhűtés
- AMD Ryzen 9 / 7 / 5 / 3 5***(X) "Zen 3" (AM4)
- Dobta az OLED kijelzőt a Honor MagicPad 3
- Leégett az első Radeon a hírhedt 12V-2x6 tápkonnektorral
- Indulhat a hardverparti!
- OLED TV topic
-
PROHARDVER!
Arduino hardverrel és szoftverrel foglakozó téma. Minden mikrovezérlő ami arduinoval programozható, és minden arduino program, board, és hardverrel kapcsolatos kérdések helye.
Új hozzászólás Aktív témák
-
Tomika86
senior tag
válasz
Tankblock #17103 üzenetére
Nem látok benne én:
#include <movingAvg.h>
// initialize - allocate the interval array
void movingAvg::begin()
{
m_readings = new int[m_interval];
}
// add a new reading and return the new moving average
int movingAvg::reading(int newReading)
{
// add each new data point to the sum until the m_readings array is filled
if (m_nbrReadings < m_interval)
{
++m_nbrReadings;
m_sum = m_sum + newReading;
}
// once the array is filled, subtract the oldest data point and add the new one
else
{
m_sum = m_sum - m_readings[m_next] + newReading;
}
m_readings[m_next] = newReading;
if (++m_next >= m_interval) m_next = 0;
return (m_sum + m_nbrReadings / 2) / m_nbrReadings;
}
// just return the current moving average
int movingAvg::getAvg()
{
return (m_sum + m_nbrReadings / 2) / m_nbrReadings;
}
// start the moving average over again
void movingAvg::reset()
{
m_nbrReadings = 0;
m_sum = 0;
m_next = 0;
}
header:#ifndef MOVINGAVG_H_INCLUDED
#define MOVINGAVG_H_INCLUDED
class movingAvg
{
public:
movingAvg(int interval)
: m_interval(interval), m_nbrReadings(0), m_sum(0), m_next(0) {}
void begin();
int reading(int newReading);
int getAvg();
int getCount() {return m_nbrReadings;}
void reset();
int* getReadings() {return m_readings;}
private:
int m_interval; // number of data points for the moving average
int m_nbrReadings; // number of readings
long m_sum; // sum of the m_readings array
int m_next; // index to the next reading
int *m_readings; // pointer to the dynamically allocated interval array
};
#endif
Új hozzászólás Aktív témák
- Apple iMac 27" 5K 2017 1TB
- Gyári garanciális HP Pavilion 14 x360 i5 1235u/16GB/512SSD/360 TOUCH Screen
- BESZÁMÍTÁS! Apple MacBook Pro 16 M4 Max 36GB RAM 1TB SSD macbook garanciával hibátlan működéssel
- BESZÁMÍTÁS! Apple MacBook Pro 14 M4 Max 36GB RAM 1TB SSD macbook garanciával hibátlan működéssel
- BESZÁMÍTÁS! Apple MacBook Pro 16 2024 M4 Max 64GB 2TB SSD macbook garanciával hibátlan működéssel
- ÁRGARANCIA!Épített KomPhone Ryzen 7 9700X 32/64GB RAM RX 7800 XT 16GB GAMER PC termékbeszámítással
- HIBÁTLAN iPhone 14 256GB Red -1 ÉV GARANCIA - Kártyafüggetlen, MS3241
- Bomba ár! Acer Aspire E5 - i7-7GEN I 8GB I 128GB SSD I 15,6" FHD I Nvidia 2GB I Cam I W11 I Gari!
- Telefon felvásárlás!! iPhone 13 Mini/iPhone 13/iPhone 13 Pro/iPhone 13 Pro Max
- BESZÁMÍTÁS! ASUS TUF A15 FA507NV 15 notebook - R7 7735HS 32GB DDR5 512GB SSD 1TB SSD RTX 4060 6GB W
Állásajánlatok
Cég: FOTC
Város: Budapest