HW6 - Solutions

HW6 - Solutions - EC327IntroductiontoSoftwareEngineering...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
EC327 Introduction to Software Engineering HW #6 Solutions Problem 1 [90 points] #include <iostream> #include <list> #include <vector> #include <cstdlib> #include <time.h> using namespace std; class Animal { public : string name; vector< int > myvector; vector< int >::iterator it; Animal(string name) { this ->name = name; } virtual int move(string ani, int step) { return 0; }; }; class CTortoise : public Animal{ public : CTortoise (string name) : Animal(name) { for ( int i=0; i<50; i++) myvector.push_back(i); it=myvector.begin(); } int move(string ani, int step) { *it = *it + step; cout << ani << " crawls " << step << " steps forward, is at step " << *it << endl; return *it; } }; class CHare : public Animal{ public : CHare (string name) : Animal(name) { for ( int i=0; i<50; i++) myvector.push_back(i); it=myvector.begin(); } int move(string ani, int step) { *it = *it + step; cout << ani << " jumps " << step << " steps forward, is at step " << *it << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
return *it; } }; class CChicken :
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

HW6 - Solutions - EC327IntroductiontoSoftwareEngineering...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online