Computers and Technology
Computers and Technology, 01.07.2020 15:01, Rodny1047

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;
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:30, kieraweems2034
Communication is the exchange of information. true false
Answers: 2
image
Computers and Technology, 22.06.2019 15:30, alexdub9649
What is a costume plot? why is it important to a film or theater production?
Answers: 2
image
Computers and Technology, 22.06.2019 19:20, mayaparness
Write a program that prompts the user to input a string. the program then uses the function substr to remove all the vowels from the string. for example, if str = "there", then after removing all the vowels, str = "thr". after removing all the vowels, output the string. your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.
Answers: 2
image
Computers and Technology, 23.06.2019 09:30, jason9394
Facial expressions and gestures are examples of messages.
Answers: 3
Do you know the correct answer?
C++ A class BCheckString that is derived from the C++ Standard Library string class performs bounds...

Questions in other subjects: