- Egérpad topik
- Gaming notebook topik
- Vezetékes FEJhallgatók
- Meghalt a Windows 10, éljen a Windows 10!
- Korábbi vezére figyelmeztette az Intelt a legfontosabb célra
- Kezdő fotósok digitális fényképei
- Milyen asztali (teljes vagy fél-) gépet vegyek?
- Milyen videókártyát?
- Épített vízhűtés (nem kompakt) topic
- AMD vs. INTEL vs. NVIDIA
-
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
- Egérpad topik
- OFF TOPIC 44 - Te mondd, hogy offtopic, a te hangod mélyebb!
- Hegesztés topic
- Mesterséges intelligencia topik
- Világ Ninjái és Kódfejtői, egyesüljetek!
- Telekom otthoni szolgáltatások (TV, internet, telefon)
- Milyen hagyományos (nem okos-) telefont vegyek?
- Tőzsde és gazdaság
- Elemlámpa, zseblámpa
- BestBuy topik
- További aktív témák...
- HP 14 Elitebook 640 G9 FHD IPS i5-1235U 4.4Ghz 10mag 16GB 256GB Intel Iris XE Win11 Pro Garancia
- Új Lenovo E14 Thinkpad WUXGA IPS Ryzen7 7730U 16GB 512GB SSD Radeon RX Vega8 Win11 Pro Garancia
- HP Z240 Komplett asztali pc, garanciával, 1050ti 4GB Videóval!
- i3 8100 és i5-9400 processzorok
- 6 és 7. generációs i3 és i5 procik
- 134 - Lenovo Legion Pro 7 (16IRX8H) - Intel Core i9-13900HX, RTX 4090 - 3 év garancia
- Samsung Galaxy A33 5G 128GB, Kártyafüggetlen, 1 Év Garanciával
- Készpénzes / Utalásos Videokártya és Hardver felvásárlás! Személyesen vagy Postával!
- Samsung C27JG50QQU Monitor
- HIBÁTLAN iPhone 14 256GB Purple -1 ÉV GARANCIA - Kártyafüggetlen, MS3535
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest