CSC 1513 Programming Fundamental Individual Project
CSC 1513 Programming Fundamental Individual Project
Test Output:
Q. 2. Write a method called `isVanilla` that returns `1` if its argument is a vanilla array.
Otherwise it returns `0`.
A This class CheckVanilla is used to check if the array is vanilla or not. Being a vanilla array
means all its elements are made up of the same digit.
There are three methods in this class:
• isVanilla()
• isVanillaElement()
• setVanillaWith()
There is an attribute vanillaWith that is used to store the digit that the array is supposed to be
made up of for being a vanilla array. The isVanillaElement() method is used to check if the
element in the parameter is made up of the same digit as the vanillaWith attribute. The
setVanillaWith() method is used to set the vanillaWith attribute. The isVanilla() method is
used to check if the array is vanilla or not. If the array is vanilla, it returns 1. If the array is not
vanilla, it returns 0.
Logic behind vanilla element
To check if an element is vanilla element, we need to check if the element is made up of the
same digit as the vanillaWith attribute. The modulus by 10 is used to get all the digits in the
element. While loop is executed and if either of digit in the element is not the same as the
vanillaWith attribute, it returns 0.
Test Cases:
For the test cases given in the question, following is the test code:
Test Output:
Q. 3. Write a function named isZeroBalanced that returns 1 if its argument is a zero-balanced
array. Otherwise it returns 0.
A This class CheckZeroBalanced is used to check if the array is zero-balanced or not. Being a
zero-balanced array means all its elements sum to 0 and for each positive element n, there
exists another element that is the negative of n. This class has two methods:
• isZeroBalanced()
• existsInArray()
isZeroBalanced() is used to check if the array is zero-balanced or not. If the array is zero-
balanced, it returns 1. If the array is not zero-balanced, it returns 0. existsInArray() is used to
check if the element in the parameter is the negative of another element in the array. If the
negative of the element is found in the array, it returns the index of the negative element. If
the negative of the element is not found in the array, it returns -1. Here, negative is for the
positive number as the element. If the element is negative, it returns the index of the positive
element. If the positive of the negative element is not found in the array, it returns -1.
Test Cases:
For the test cases given in the question, following is the test code:
Test Output:
Q. 4. Write a function named isDaphne that returns `1` if its array argument is a Daphne
array. Otherwise it returns `0`.
A This class `CheckDaphneArray` is used to check if the array is Daphne or not. Being a
Daphne array means all its elements are either all odd numbers or all even numbers.
Test Cases:
For the test cases given in the question, following is the test code:
Test Result:
Q. 5. Write a function named isBalanced that accepts an array of integers and returns 1 if the
array is balanced, otherwise it returns 0.
A This class CheckBalanced is used to check if even indexed element is even and odd indexed
element is odd.
There are three methods in this class:
• isBalanced()
• isEven()
• isOdd()
isEven() is used to check if the element in the parameter is even. isOdd() is used to check if
the element in the parameter is odd. isBalanced() is used to check if the array is balanced or
not. If the array is balanced, it returns 1. If the array is not balanced, it returns 0.
Test Cases:
For the test cases given in the question, following is the test code:
Test Output: