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;
}

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions