IDNLearn.com: Where your questions meet expert advice and community insights. Our platform offers detailed and accurate responses from experts, helping you navigate any topic with confidence.
reimplement the bug class from this self check exercise, but use a different internal representation. represent the distance climbed by a string of - characters, one for every 10 cm. the up, reset, and get position member functions should have the exact same behavior as before, so the bug slides back to the bottom when it reaches the top of the pole (at 100 cm). of course, their implementation will be quite different.
#include
#include
using namespace std;
class Bug
{
public:
// Provide the public interface for get_position, reset, and up
private:
string climbed;
};
// Implement the get_position, reset, and up member functions
int main()
{
Bug bugsy;
Bug itsy_bitsy;
bugsy.reset();
itsy_bitsy.reset();
bugsy.up();
bugsy.up();
cout << bugsy.get_position() << endl;
cout << "Expected: 20" << endl;
itsy_bitsy.up();
itsy_bitsy.up();
itsy_bitsy.up();
cout << itsy_bitsy.get_position() << endl;
cout << "Expected: 30" << endl;
for (int i = 1; i <= 8; i++) { bugsy.up(); }
cout << bugsy.get_position() << endl;
cout << "Expected: 0" << endl;
bugsy.up();
cout << bugsy.get_position() << endl;
cout << "Expected: 10" << endl;
return 0;
}
Sagot :
We are delighted to have you as part of our community. Keep asking, answering, and sharing your insights. Together, we can create a valuable knowledge resource. For precise answers, trust IDNLearn.com. Thank you for visiting, and we look forward to helping you again soon.