Question: 9 . 2 3 . 2 : Reimplement the Bug class using a different internal representation. 5 4 1 7 0 8 . 3 4

9.23.2: Reimplement the Bug class using a different internal representation.
541708.3480878.qx3zqy7
Reimplement the Bug class from the "Implementing a Simple Class" section, 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
/* Your code goes here */
private:
string climbed;
};
// Implement the get_position, reset, and up member functions
/* Your code goes here */
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;
}#include 3;
 9.23.2: Reimplement the Bug class using a different internal representation. 541708.3480878.qx3zqy7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!