Initialize Filter3 Class

#include <iostream>
using namespace std;

// Define Filter3 class here
class Filter3{
    const int id = 0 ;
    int coeff[3],lastoutput;
    public:
        Filter3(int Filterid,int c0,int c1,int c2):id(Filterid),coeff{c0,c1,c2},lastoutput(0){}
        
        void apply(int x){
            lastoutput = x * coeff[0] + coeff[1] + coeff[2];
        }
        int read(){return lastoutput;}
};

int main() {
    int id, c0, c1, c2;
    cin >> id >> c0 >> c1 >> c2;

    Filter3 f(id, c0, c1, c2);

    int s1, s2;
    cin >> s1 >> s2;

    f.apply(s1);
    f.apply(s2);

    cout << f.read();
    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

7 2 3 1 10 4

Expected Output

12