Answered step by step
Verified Expert Solution
Link Copied!

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

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;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

Solve for x: 2(3x 1)2(x + 5) = 12

Answered: 1 week ago