subject

C++ A class BCheckString that is derived from the C++ Standard Library string class performs bounds checking and throws an exception. The BCheckString class will have two member functions:
1) A BCheckString(string s) constructor that receives a string object passed by value and passes it on to the base class constructor. It just calls the base class constructor using its constructor initialization list.
2) A overloaded operator function, char operator[ ](int k), throws an exception, a BoundsException object (i. e., StrExcept()) if its parameter, k is out bounds (i. e., negative or greater than or equal to the length of the string), otherwise it will return the character at position k in the string with calling operator [] in the string base class.
main function that attempts to access characters that are within and outside the bounds of a suitably initialized BCheckString objects
#include
#include
using namespace std;
class StrExcept { }; //String Out of Bounds Exception
// COMPLETE
class BCheckString
{
public:
};

int main()
{
//Explain program to user
cout << "This program demonstrates bounds checking on string object.";
//Get string from user and create boundCheck string object
cout << "\nEnter a string: ";
string str;
getline(cin, str);
BCheckString h(str);
//Let user access characters at specified positions in the string
//COMPLETE
cout << "Legitimate string positions are: " << 0 << ".." << h. length() -1 << endl;
for (int k = 1; k <= 5; k++)
{
cout << "Enter an integer describing a position inside or outside the string: ";
int pos;
cin >> pos;
cout << "The character at position " << pos << " is " << h[pos] << endl;
}
return 0;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
Formula that contains a nested function that first calculates the average of the values in range e6: p6 and uses the round function to round that average to the nearest 10 dollars. use -1 for the value of the number digit argument. would the formula be =round(average(e6: p6),0
Answers: 1
question
Computers and Technology, 22.06.2019 21:00
Kirk found a local community college with a two-year program and he is comparing the cost with that of an out-of-state two-year school. what is the expected total cost for one year at the local community college if kirk lives at home? what is the expected total cost for one year at the out-of-state school if kirk lives on campus?
Answers: 2
question
Computers and Technology, 23.06.2019 08:30
Helen's credit card has an apr of 15.32% and a grace period of 17 days and helen pays her balance in the full every month. if her last billing cycle ended on september 26, 2009, and she made her payment on october 11, 2009, did she owe any interest on her last statement's balance?
Answers: 3
question
Computers and Technology, 24.06.2019 04:30
Write and test a python program to find and print the largest number in a set of real (floating point) numbers. the program should first read a single positive integer number from the user, which will be how many numbers to read and search through. after reading in all of the numbers, the largest of the numbers input (not considering the count input) should be printed.
Answers: 1
You know the right answer?
C++ A class BCheckString that is derived from the C++ Standard Library string class performs bounds...
Questions
question
Mathematics, 25.09.2019 05:30
question
Mathematics, 25.09.2019 05:30
Questions on the website: 13722360