A intermediate level task for practicing object-oriented programming.
Estimated time to complete the task: 2 hour.
The task requires .NET 8 SDK installed.
Implement a class library of generators of sequences of elements of various types.
- Create a generic interface
ISequenceGenerator<T>. - Define the following properties:
Previousof typeT, representing the previous element in the sequence.Currentof typeT, representing the current element in the sequence.Nextof typeT, representing the next element in the sequence.
- Create an abstract class
SequenceGenerator<T>that implements theISequenceGenerator<T>interface. - Provide a constructor that initializes two first values of the sequence.
- Implement the properties
PreviousandCurrentwith appropriate accessors. - Define a public property
Count, representing the number of elements generated in the sequence. The property should have a public getter and a private setter. - Define an abstract method called
GetNext()that returns an element of typeTof the specific sequence.
- Create a class called
FibonacciSequenceGeneratorthat inherits fromSequenceGenerator<int>. - Provide a constructor that initializes two first values of the sequence.
- Implement the
GetNext()method to generate the next Fibonacci number based on the previous and current values. The Fibonacci sequence starts with two initial values (e.g., 0 and 1), and each subsequent number is the sum of the previous two.
-
Create a class called
IntegerSequenceGeneratorthat inherits fromSequenceGenerator<int>. -
Provide a constructor that initializes two first values of the sequence.
-
Implement the
GetNext()method to generate the elements of the sequence based the following rule:$x_1 = 1, x_2 = 2, x_{n + 1} = 6 x_n - 8 x_{n - 1}, n = 2, 3, ... ,$ .
Data for tests: { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, , n = 10
-
Create a class called
DoubleSequenceGeneratorthat inherits fromSequenceGenerator<int>. -
Provide a constructor that initializes two first values of the sequence.
-
Implement the
GetNext()method to generate the elements of the sequence based the following rule:$x_1 = 1, x_2 = 2, x_{n + 1} = x_n + x_{n - 1} / x_{n}, n = 2, 3, ...,$ .
Data for tests: {1, 2, 2.5, 3.3, 4.05757575757576, 4.87086926018965, 5.70389834408211, 6.55785277425587, 7.42763417076325, 8.31053343902137}, n = 10
-
Create a class called
CharSequenceGeneratorthat inherits fromSequenceGenerator<int>. -
Provide a constructor that initializes two first values of the sequence.
-
Implement the
GetNext()method to generate the elements of the sequence based the following rule:$x_1 = a, x_2 = b, x_{n + 1} = (x_n + x_{n - 1}) % 26 + 'A', n = 2, 3, ...,$ wherea, b-char.
Data for tests: {'A', 'B', 'B', 'C', 'D', 'F', 'I', 'N', 'V', 'I'}, n = 10
-
Use a delegate type to implement a generalized generator of the
n-first members of a sequence specified by a recurrent formula for elements of typeTaccording to the rule$x_1 = a, x_2 = b, x_{n+1}=f(x_n, x_{n - 1}), n = 2, 3, ...$
Note The solution will not compile until all required types with required members are implemented. For a smoother development experience, we recommend initially declaring all necessary types and creating "stub methods" as follows:
public returnType MethodName(parameters list)
{
throw new NotImplementedException();
}This approach allows you to build and run your project incrementally while implementing each method.