DESCRIPTION
Complete the classes using the Specifications given below. Consider default visibility of
classes, data fields, and methods unless mentioned otherwise.
Specifications
class definitions:
class Counter:
data member:
int[] data
visibility : public
Counter(int[] data):Constructor with public visibility
method definition:
getCount()
return: String
visibility: public
class ExceptionZero : Exception:
method definition:
ExceptionZero(String message) : base(message)
visibility: public
class ExceptionOne : Exception:
method definition:
ExceptionOne(String message) : base(message)
visibility: public
Task
Class Counter
-define the data members as per the given specifications.
-define the constructor with public visibility.
-the array data will contain 0 or 1 always.
-Implement the below methods for this class:
-String getCount():
Write a code that gives the output on the below conditions -
1. If the count of zeros is even and the count of one is also even then
return "Great".
2. If the count of zeros is odd and the count of one is also odd then
return "Great".
3. If the count of zeros is even and the count of one is odd then
throw ExceptionOne with a message "One comes odd times".
4. If the count of zeros is odd and the count one is even then
throw ExceptionZero with a message "Zero comes odd times".
Class ExceptionZero : Exception:
-Define ExceptionZero class derived from the Exception class.
Class ExceptionOne : Exception:
-Define ExceptionOne class derived from the Exception class.
Sample Input
int[] data = {0,1,0,1,1,1,1};
Counter c = new Counter(data);
string res = [Link]();
[Link](res);
Sample Output
Great
Instruction
Files in which you have to write the code:
Counter/[Link]