 (가) 클래스 설계에 대한 설명 클래스의 멤버함수 및 용도를 표로 작성 (강의자료 5강 10번 슬라이드) 클래스의 데이터멤버 및 용도를 표로 작성 각각의 클래스 멤버함수에 대해 다음 내용 작성 - 매개변수의 자료형 및 용도 - 반환 값이 있다면 값의 의미 및 자료형 - 처리 내용의 설명(형식 제한 없음) ```cpp!= #include <iostream> #include <vector> class WeightedMovingAverageCalculator { public: WeightedMovingAverageCalculator(const std::vector<double>& weights) : weights_(weights), sum_(0.0), weightSum_(0.0) { if (weights_.empty()) { std::cerr << "Error: Weights cannot be empty." << std::endl; } } void addData(double data) { if (weights_.empty()) { std::cerr << "Error: Weights cannot be empty." << std::endl; return; } if (dataQueue_.size() == weights_.size()) { sum_ -= dataQueue_.front() * weights_.front(); dataQueue_.pop_front(); } dataQueue_.push_back(data); sum_ += data * weights_.back(); weightSum_ += weights_.back(); } double getWeightedMovingAverage() const { if (weightSum_ == 0.0) { std::cerr << "Error: The sum of weights cannot be zero." << std::endl; return 0.0; } return sum_ / weightSum_; } private: std::vector<double> weights_; std::deque<double> dataQueue_; double sum_; double weightSum_; }; int main() { std::vector<double> weights = {0.5, 0.3, 0.15, 0.05}; WeightedMovingAverageCalculator wmaCalculator(weights); // 예제 데이터 추가 wmaCalculator.addData(10.0); wmaCalculator.addData(15.0); wmaCalculator.addData(20.0); // 가중 이동 평균 출력 std::cout << "Weighted Moving Average: " << wmaCalculator.getWeightedMovingAverage() << std::endl; return 0; } ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up