Writ c code to overload subscript operator for String class-00473
This subjective question is related to the book/course vu cs302 Digital Logic Design. It can also be found in vu cs302 Mid Term Solved Past Paper No. 2.
Question 1: Writ c++ code to overload subscript[] operator for String class.
#include <sstream>
#include <string>
using namespace std;
class BoundsException {
public:
BoundsException(int x) : _index(x) { }
void what() {
cout << "index out of range : " << _index << endl;
}
private:
BoundsException() { }
int _index;
};
class BCheckString : public string {
public:
BCheckString(const string s) : string(s) { }
Answer:
#include <iostream>#include <sstream>
#include <string>
using namespace std;
class BoundsException {
public:
BoundsException(int x) : _index(x) { }
void what() {
cout << "index out of range : " << _index << endl;
}
private:
BoundsException() { }
int _index;
};
class BCheckString : public string {
public:
BCheckString(const string s) : string(s) { }