QUESTION 1:
// Declare a user-defined exception
class NegativeValException : public exception { // LINE-1
public:
virtual const char* what() const throw() {
return "Negative value";
}
};
// Declare a user-defined exception
class ZeroValException : public exception { // LINE-2
public:
virtual const char* what() const throw() {
return "Zero";
}
};
int main() {
int i;
cin >> i;
try {
if (i < 0)
// Throw the exception object
throw NegativeValException(); // LINE-3
else if (i == 0)
// Throw the exception object
throw ZeroValException(); // LINE-4
QUESTION 2:
template <class T, int n> // LINE-1
class container {
T arr[n]; // LINE-2
int i;
public:
container() : i(-1) { }
void operator=(char data) {// LINE-3
QUESTION 3:
template <class T, int n> // LINE-1
void mysequence<T,n>::setVal(int i, T value) { // LINE-2
items[i] = value;
}
template <class T, int n> // LINE-3
T mysequence<T,n>::getVal(int i) { // LINE-4
return items[i];
}
0 Comments:
Post a Comment