Docsity

Solved Problem for Assignment 6 - Introduction to Programming | CS 1110, Assignments of Computer Science

Toggle sidebar
bg1
CS 101 Unpledged
CS 101 Page 1 of 3 Fall 1996
Homework VI
Assigned in Laboratory IX
Part 1 Due in Laboratory X
Final Part Due in Laboratory XI
Please perform the following activities. This assignment is unpledged. You may work with one other person in your
laboratory session. You are allowed to talk with others, but your work must be your own.
Objective
We develop our first classes. The advantages of object-oriented design and implementation should become apparent.
Problem
The problem is identical to that described in homework V.
The Department of Energy (DOE) is in the process of developing a robot that can be used in hazardous environ-
ments. The robot, HERO (Hazardous Environment Robot Observer), is controlled by simple commands. HERO
understands the following commands:
When HERO executes a movement command (U, D, L, or R) it moves in that direction. It moves a distance that is
specified by the last set movement distance command (M) executed. The speed command (S) tells HERO how fast
to execute commands. The argument for the speed command is milliseconds. HERO delays n milliseconds before
reading and executing the next command. Both the arguments to the speed and movement commands are integers.
To help DOE develop HERO, you have been asked to write a program that displays the actions of HERO. Your pro-
gram reads a file of HERO commands and displays HERO’s action in a display window. Since HERO’s intended
purpose is to find hazardous materials, the program should indicate when HERO encounters hazardous material.
Whenever HERO crosses a region with hazardous material that region should be highlighted on the screen.
Command Action
U or u Move up
D or d Move down
L or l Move left
R or r Move right
S or s nSet speed to n
M or m nSet movement distance to n tenths of a centimeter
pf3

Partial preview of the text

Download Solved Problem for Assignment 6 - Introduction to Programming | CS 1110 and more Assignments Computer Science in PDF only on Docsity!

Homework VI

Assigned in Laboratory IX

Part 1 Due in Laboratory X

Final Part Due in Laboratory XI

Please perform the following activities. This assignment is unpledged. You may work with one other person in your laboratory session. You are allowed to talk with others, but your work must be your own.

Objective

We develop our first classes. The advantages of object-oriented design and implementation should become apparent.

Problem

The problem is identical to that described in homework V.

The Department of Energy (DOE) is in the process of developing a robot that can be used in hazardous environ- ments. The robot, HERO (Hazardous Environment Robot Observer), is controlled by simple commands. HERO understands the following commands:

When HERO executes a movement command (U, D, L, or R) it moves in that direction. It moves a distance that is specified by the last set movement distance command (M) executed. The speed command (S) tells HERO how fast to execute commands. The argument for the speed command is milliseconds. HERO delays n milliseconds before reading and executing the next command. Both the arguments to the speed and movement commands are integers.

To help DOE develop HERO, you have been asked to write a program that displays the actions of HERO. Your pro- gram reads a file of HERO commands and displays HERO’s action in a display window. Since HERO’s intended purpose is to find hazardous materials, the program should indicate when HERO encounters hazardous material. Whenever HERO crosses a region with hazardous material that region should be highlighted on the screen.

Command Action

U or u Move up

D or d Move down

L or l Move left

R or r Move right

S or s n Set speed to n

M or m n Set movement distance to n tenths of a centimeter

A HERO command file has the following format: 20.0 20. 9.0 9.0 2.0 2. 0.0 0. S 100 M 10 D D D D D D L

This first line is the width and height in centimeters of the display window. The second line is the coordinates of the hazardous waste region and the size (width and height) of the waste region. The third line is the starting coordinates of HERO. Following these three lines (which must be present in a HERO command file) are HERO commands.

Your program should open the command file hero.dat, create a display window of the indicated size, draw the haz- ardous waste region (which should be yellow), and draw HERO at its starting coordinates. To represent HERO on the display use a 1.0 centimeter by 1.0 centimeter blue square. The program should read HERO commands and update the display to simulate the movements of HERO. The program should terminate when the last command is executed.

When HERO enters the hazardous waste region, the region should be displayed as red. When HERO exits the haz- ardous waste region its color should be returned to yellow.

If HERO attempts to move beyond the boundary of the left edge of the display window, HERO should appear at the right edge of the display window. Similarly, if HERO attempts to move beyond the boundary of the right edge of the display window, HERO should appear at the left edge of the display window. When HERO is at the top or bottom edge of the display window, the action is similar. If HERO attempts to move beyond the top edge of the display win- dow, it should appear at the bottom of the display window. If HERO attempts to move beyond the bottom edge of the display window, it should appear at the top of the display window.

Revised implementation

For this assignment we want to use object-oriented design and implementation techniques to realize a solution to the problem. If you analyze the above problem statement, clearly we need an object to represent the robot HERO and an object to represent the hazardous waste region. You should redo your solution using C++ classes that can be used to create HERO and a hazardous waste region. If you did Homework V using objects, then you are ahead of the game. However, you may wish to polish your solution.

Notes

You must show and turn a listing of your class declarations to your laboratory assistant during Laboratory X. Your laboratory assistant will give you some initial feedback on your class definitions. You need not submit your class dec- larations electronically.

Please submit your program electronically before the beginning of Laboratory XI. You should submit five files. The files to submit are:

robot.h Contains the class definition for the robot. robot.cpp Contains the implementation for the robot. hazard.h Contains the class definition for the hazardous waste region. hazard.cpp Contains the implementation for the hazardous waste region. hw06.cpp Contains the function ApiMain() and all other code needed to complete the assignment.