C++

1. A sequence of integers such as 1, 3, 5, 7, ... can be represented by a function that takes a non-negative integer as paramNotes: a. The implementation of the virtual function sequence Term in the subclass OddSeq should have the same return as the2. Update the program in Task 1 to include the following two subclasses: a. FibonacciSeq whose member function sequence Term

1. A sequence of integers such as 1, 3, 5, 7, … can be represented by a function that takes a non-negative integer as parameter and returns the corresponding term of the sequence as illustrated in the following examples: Example 1 The sequence of odd numbers can be represented by the function: int oddSeqTerm(int k) {return 2 * K – 1; } Example 2 The sequence of square numbers can be represented by the function: int squareSeqTerm(int k) {return k * k; } Write an abstract class named AbstractSeq that has the following members: a. A pure virtual member function named sequence Term that takes an integer parameter. Implementations of this function will be left to the subclasses OddSeq and Square Seq that you will need to add to your program. b. A member function named printSeq that takes two integer parameters k and m, where k Notes: a. The implementation of the virtual function sequence Term in the subclass OddSeq should have the same return as the oddSeqTerm function mentioned in Example 1 above. b. The implementation of the virtual function sequence Term in the subclass SquareSeq should have the same return as the squareSeqTerm function mentioned in Example 2 above. The program in Figure 1 demonstrates the AbstractSeq class by printing two different sequences and the sums of their terms. And Figure 2 shows a snapshot of the program’s input and output. int main() // Create two sequences OddSeq odd; SquareSeq sq; int k, m; cout << “Enter the lower bound integer k: “; cin >> k; cout << “Enter the upper bound integer m: “; cin >> m; cout 2. Update the program in Task 1 to include the following two subclasses: a. FibonacciSeq whose member function sequence Term returns the terms of the Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, … b. TriangularSeq whose member function sequence Term returns the terms of the triangular sequence: 1, 3, 6, 10, 15, 21, 28, … Figure 3 illustrates how the numbers of the triangular sequence can be generated. 1, 3, 6, 10, 15, … Figure 3



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *