University of Lethbridge - CPSC
RecurrenceSequence.cpp
Assignment 2 - Recurrence - SM 25This page explains each function in your RecurrenceSequence class. For every method, you’ll learn what it does and how it works in simple steps before seeing the full code.
You will need to use the assert library in your code so make sure to include this near the top of your file: #include <assert.h>
RecurrenceSequence() - Default constructor
This function runs when you create a new object with no input values. It sets all internal numbers to zero and sets the sequence pointer to nullptr, meaning the array doesn't point to anything yet.
RecurrenceSequence::RecurrenceSequence() {
seq = nullptr;
a = b = p = q = length = 0;
}RecurrenceSequence(int aVal, int bVal, int pVal, int qVal, int len) - Parameterized constructor
This function runs when you want to create a sequence with specific values. It:
Stores the given values (a, b, p, q, and length)
Creates space in memory for the full sequence
Calls
generateSequence()to calculate and fill in the array
RecurrenceSequence::RecurrenceSequence(int aVal, int bVal, int pVal, int qVal, int len) {
a = aVal;
b = bVal;
p = pVal;
q = qVal;
length = len;
seq = new int[length];
generateSequence();
}Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 27 more lessons in University of Lethbridge - CPSC.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.