Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2nd time posting this question. I'm having a hard time trying to get the commands to communicate with the classes and the floor. We have

2nd time posting this question. I'm having a hard time trying to get the commands to communicate with the classes and the floor. We have to have separate classes. I think i'm on the right path. I just dont know how to have them communicate to each other. Please help. image text in transcribedimage text in transcribedimage text in transcribed

Here is what i have so far. I think i have to pass them through as parameters? I tried different ways but cant seem to figure it out. Please help!

Direction.h : #ifndef Direction_H #define Direction_H

class Direction { private: char direction; public: Direction(); void setdir(char); char getdir(); };

#endif Direction_H

Pen.h below:

#ifndef PEN_H #define PEN_H

class Pen { private: bool up = true;

public: Pen(); void setpen(); };

#endif PEN_H

Position.h Below:

#ifndef POSITION_H #define POSITION_H

class Position { private: int x; int y; char floor[20][20]; public: Position(); int getxDir(); int getyDir(); void display(); }; #endif POSITION_H

Turtle.h Below:

#include #include "Direction.h" #include "Direction.cpp" #include "Pen.h" #include "Pen.cpp" #include "Position.h" #include "Position.cpp"

#ifndef TURTLE_H #define TURTLE_H using namespace std;

class Turtle { private: /ot sure what would go here?

public: Turtle(); };

#endif TURTLE_H

Direction.cpp below:

#include "direction.h" #include

using namespace std;

Direction::Direction() { direction = 'E'; } void Direction::setdir(char a) { direction = a; } char Direction::getdir() { return direction; }

Pen.cpp Below:

#include #include "Pen.h" using namespace std; Pen::Pen() { up = true; } void Pen::setpen() { if (up == true) up = false; else up = true; }

Position.cpp below:

#include #include "Position.h" using namespace std; Position::Position() { x = 0; y = 0; } int Position::getxDir() { return x; } int Position::getyDir() { return y; } void Position::display() { for (int i = 0; i

} } }

Turtle.cpp below:

#include #include "Turtle.h" using namespace std;

Turtle::Turtle() { Direction d(); Pen t(); Position p(); }

Driver.cpp below:

#include "direction.h" #include "Pen.h" #include "Position.h" #include "turtle.h" #include "direction.cpp" #include "pen.cpp" #include "Position.cpp"

#include using namespace std;

int main() { int choice; int choicePosition1; int choicePosition2; char choiceTurn; int choiceMoveHowMany; char choiceBrush; int choiceJumpHowMany;

cout

cout

if (choice != 9) {

switch (choice) { case 1: //move position cout > choicePosition1; cin >> choicePosition2; break; case 2: // turn cout > choiceTurn; Direction(choiceTurn); break;

case 3: // move forward cout > choiceMoveHowMany;

case 4: //print

case 5: // change brush cout > choiceBrush;

case 6: //start over\ erase---- need to make constructor

case 7: //jump cout > choiceJumpHowMany;

case 8: // see menu again ? why if looking at it right now?

default: { cout

}

}

else if (choice == 9) { cout

Last time i posted this a someone replied there wasn't enough information. I think this should be enough info to help now. Thank you everyone.

The Logo language, made the concept of turtle graphics famous. It was a mechanical turtle that walked around and drew shapes. The turtle holds a pen in one of two positions, up or down. While the pen is down the turtle traces out shapes as it moves, while the pen is up, the turtle moves about freely without writing anything. This is similar to the way some line draw programs work. You are to design such a program CODE: Use a 20 by 20 array or floor which is initialized to zeros. Keep track of the current position of the turtle at all times, the direction it is heading, and whether the pen is currently up or down. Assume that the turtle always starts position 0,0 on the floor with its pen up, heading to the right or east. The set of turtle commands your program must process are: WN + change pen position turn move forward print change brush erase/start over jump see menu again end program 000 O command 1 is to act as a toggle command 2 is to rotate 90 degrees from current direction ( direction of rotation is user supplied) command 3 is to move forward x units ( x is user supplied ) command 4 will print/display the entire floor command 5 will present four different character/brush options command 7 will jump/move the turtle to a new position (x,y) on the floor, which are user supplied There must be at least a turtle class (turtle.h, turtle.cpp) a pen class (pen.h, pen.cpp) a direction class ( direction.h, direction.cpp), a position class (positiion.h, position.cpp) and a driver with the name cs132_P1_driver.cpp.. The driver must not contain any function prototypes/implementations: place them in separate files It should be noted, that the position is not part of the turtle, hence the details should be hidden from the turtle (le its own class, and separate implementation. ) Likewise for direction.. When an object exhibits a "has a ..." relationship - called composition of classes ) in OOP- separate classes are used. For example, the turtle object has no special privileges of the position object. A turtle walks on the floor, le uses the position class though its interface. Does the turtle need to know the size of the floor? The turtle uses the floor but that's about it. If an object exhibits a " is a ..relationship, then inheritance is used. Assuming the turtle is near the center, heading east the following would draw a 12x12 square 3 12 S wNWNWN The Logo language, made the concept of turtle graphics famous. It was a mechanical turtle that walked around and drew shapes. The turtle holds a pen in one of two positions, up or down. While the pen is down the turtle traces out shapes as it moves, while the pen is up, the turtle moves about freely without writing anything. This is similar to the way some line draw programs work. You are to design such a program CODE: Use a 20 by 20 array or floor which is initialized to zeros. Keep track of the current position of the turtle at all times, the direction it is heading, and whether the pen is currently up or down. Assume that the turtle always starts position 0,0 on the floor with its pen up, heading to the right or east. The set of turtle commands your program must process are: WN + change pen position turn move forward print change brush erase/start over jump see menu again end program 000 O command 1 is to act as a toggle command 2 is to rotate 90 degrees from current direction ( direction of rotation is user supplied) command 3 is to move forward x units ( x is user supplied ) command 4 will print/display the entire floor command 5 will present four different character/brush options command 7 will jump/move the turtle to a new position (x,y) on the floor, which are user supplied There must be at least a turtle class (turtle.h, turtle.cpp) a pen class (pen.h, pen.cpp) a direction class ( direction.h, direction.cpp), a position class (positiion.h, position.cpp) and a driver with the name cs132_P1_driver.cpp.. The driver must not contain any function prototypes/implementations: place them in separate files It should be noted, that the position is not part of the turtle, hence the details should be hidden from the turtle (le its own class, and separate implementation. ) Likewise for direction.. When an object exhibits a "has a ..." relationship - called composition of classes ) in OOP- separate classes are used. For example, the turtle object has no special privileges of the position object. A turtle walks on the floor, le uses the position class though its interface. Does the turtle need to know the size of the floor? The turtle uses the floor but that's about it. If an object exhibits a " is a ..relationship, then inheritance is used. Assuming the turtle is near the center, heading east the following would draw a 12x12 square 3 12 S wNWNWN

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago