Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the question, A sequence of integers, 1,3,5,7,...can be represented by a

ID: 3537055 • Letter: H

Question

Here is the question,

A sequence of integers, 1,3,5,7,...can be represented by a function that takes a non negative integer as parameter and returns the corresponding term of teh sequence. For example, the sequence of odd numbers just cited can be represented by the function

int odd(int k) {return 2 * K +1;}

Write an abstract class AbstractSeq that has a pure virtual member function

virtual int fun(int K) = 0;

as a stand-in for an actual sequence, and 2 member functions

void printSeq (int K, int m);

int sumSeq(int k, int m)

That are passed 2 integer parameters K and m where k

Thank you for your help.

Explanation / Answer

abstract class abstractSeq

{

     public:

          int k=0,m=0,arr[20],count,sum=0;

          abstractSeq(int k,int m)

          {

                   this.k=k;

                   this.m=m;

          }

          virtal int fun(int k)=0;

          void printSeq(int k,int m)

           {

                  count=0;

                  cout<<" Sequence is : ";

                  for(int i=k;i<m;i++)

                  {

                              a[count] = 2*k+1;

                              cout<<a[count];

                              count++;

                  }

           }

          int sumSeq(int ,int m)

          {

                    for(int i=0;i<m-k;i++)

                    {

                               sum+=a[i];

                    }

                    cout<<"Sum of sequence is : "<<sum;

                     return 0;

          }

};

int main()

{

     abstractSeq aseq(5,7);

     return 0;

}