Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started