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

I need help with my code. This is what my I am supposed to do: A sequence of int

ID: 3535137 • Letter: I

Question

I need help with my code. This is what my I am supposed to do: A sequence of integers such as 1, 3, 5, 7, ... can be represented by a function that takes a nonnegative integer as parameter and returns the corresponding term of the 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

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

that are passed two integer parameters k and m, where k < m. The function printSeq will print all the terms fun(k) through fun(m) of the sequence, and likewise, the function sumSeq will return the sum of those terms. Demonstrate your AbstractSeq class by creat- ing subclasses that you use to sum the terms of at least two different sequences. Determine what kind of output best shows off the operation of these classes, and write a program that produces that kind of output.

And here is my code:

#include <iostream>

using namespace std;


//Prototypes

int oddSeq();

int doubleSeq();

int sumSeq();

void printSeq();


//Classes

class AbstractSeq

{

public: virtual int fun(int k) = 0;

};


int main()

{

//Variables

int k;

int m;

int rSeq;


//Input

cout << "How long do you want the sequence to be? ";

cin >> rSeq;


//Output

printSeq();


return 0;

}


//Odd numbers sequence.

int oddSeq(int k)

{

return 2 * k + 1;;

}


//Double the numbers sequence.

int doubleSeq()

{

return;

}


//Sums of all the numbers.

int sumSeq()

{

int totalSum;

return totalSum;

}


//Output the sequence.

void printSeq()

{


}

Explanation / Answer

#include <iostream>

using namespace std;

//Prototypes

int oddSeq();

int doubleSeq();

int sumSeq();

void printSeq();

//Classes

class AbstractSeq

{

public: virtual int fun(int k) = 0;

};

//Odd numbers sequence.

int oddSeq(int k)

{

return 2 * k + 1;;

}

//Sums of all the numbers.

int sumSeq(int k,int m)

{

int totalSum=0;

int i;

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

{

totalSum+=oddSeq(i);

}

return totalSum;

}

//Output the sequence.

void printSeq(int k,int m)

{

int i;

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

{

cout << oddSeq(i)<<endl;

}

}

int main()

{

//Variables

int k;

int m;

int rSeq;

//Input

cout << "How long do you want the sequence to be? ";

cin >> rSeq;

//Output

cout <<" "<<endl;

printSeq(1,rSeq);

cout << "The sum is "<<sumSeq(1,rSeq)<<endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote