Question: 9 . 2 3 . 2 : Reimplement the Bug class using a different internal representation. 5 4 1 7 0 8 . 3 4
: Reimplement the Bug class using a different internal representation.
qxzqy
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 cm The up reset, and getposition 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 cm Of course, their implementation will be quite different.
#include
#include
using namespace std;
class Bug
public:
Provide the public interface for getposition, reset, and up
Your code goes here
private:
string climbed;
;
Implement the getposition, reset, and up member functions
Your code goes here
int main
Bug bugsy;
Bug itsybitsy;
bugsy.reset;
itsybitsy.reset;
bugsy.up;
bugsy.up;
cout bugsy.getposition endl;
cout "Expected: endl;
itsybitsy.up;
itsybitsy.up;
itsybitsy.up;
cout itsybitsy.getposition endl;
cout "Expected: endl;
for int i ; i ; i bugsy.up;
cout bugsy.getposition endl;
cout "Expected: endl;
bugsy.up;
cout bugsy.getposition endl;
cout "Expected: endl;
return ;
#include ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
