How Can You Track the Path of a Destruction Droid in C++?

  • Comp Sci
  • Thread starter Wanna-be Eng.
  • Start date
  • Tags
    C++ Program
In summary, the "C++ Destruction Droid program" is a software program designed to control destructive robots for various purposes. It utilizes the C++ programming language and its high performance and efficiency to create a powerful control system. While it was initially intended for destructive purposes, it can also be used for non-destructive applications. However, caution and proper care must be taken when using the program to ensure safety.
  • #1
Wanna-be Eng.
2
0

Homework Statement


Problem Destruction Droid Introduction Life was easy and happy on the third moon of Sirius 8: people lived and worked in the many peaceful
colonies. However, the Klingon Empire decided to extend its control to this part of the galaxy: they
landed a Destruction DroidTM
on the surface of the moon. The Destruction DroidTM
will go to one
colony and destroy it completely. If we knew which colony is targeted by the Destruction DroidTM, then
we could concentrate our forces to defend that colony. Fortunately, we have intercepted the commands
transmitted to the Destruction DroidTM, thus it is possible to determine its destination. Your task is to
write a program that determines the unfortunate colony where the Destruction DroidTM
goes.

One of the nice things about this moon is that it is almost completely flat, hence everything can be
described easily with two coordinates. East is x
direction, North is y
direction.

Input Each input file begins with a line containing four integers:

n<=500, the number of commands,
m<=100, the number of colonies,
x and y, the starting coordinates of the Destruction DroidTM

The first line is followed by n
lines containing one command each. There are 5 different commands:

LEFT p : turn left p degrees
RIGHT p : turn right p degrees
FASTER p : increase the speed with p units
SLOWER p : decrease the speed with p units
WAIT p : the Destruction DroidTM goes for p time units in the current direction with the current speed

Speed is given in coordinate units per time units. It can be assumed that the commands do not increase
the speed above 500 or below 0. After landing, the Destruction DroidTM faces North(y direction), and
its speed is 0. The commands LEFT, RIGHT, FASTER, and SLOWER are executed in zero time: the
Destruction DroidTM does not move during these commands.

The last m lines of the input describe the colonies. Each lin ebegin swith a name of length at most 20,
which does not contain any space characters. The name is followed by the two coordinates of the colony.

Output You have to output the name of the colony where the Destruction DroidTM will be after executing the
commands.
Write a newline character afterthe name ofthe colony. It canbe assumedthattheDestruction DroidTM will be at a distance of at most 10 from some colony, and there is a unique such colony. It is possible that the Destruction DroidTM goes through some other colonies while executing the commands, but we do not care about that. Sample Input 5 4 0 0

FASTER 10
WAIT 10
RIGHT 135
SLOWER 5
WAIT 28
Aaaa 0 0
Bbbb 100 100
Cccc 0 100
Dddd 100 0

Sample Output

Dddd

Homework Equations



all c++ you can get :biggrin:

The Attempt at a Solution



I was thinking about using functions. Is it necessary to use clases? I'm not sure how to make the program calculate the last position of the droid. I'll come up with some code, probably tommorrow.
 
Last edited:
Physics news on Phys.org
  • #2
Whether to use functions or classes is up to you, it depends on your preference.

In the end, you will have coordinates for the position of the droid, which you need to compare to the coordinates of the colonies. I would use the following algorithm:
Code:
  int nearestColonyIndex = -1, theDistance = 0, smallestDistance = -1;
  for(i = 0; i <= count(colonies); i++) {
    theDistance = distance(droidCoordinates, colonies[i].coordinates);
    if(nearestColonyIndex == -1 || theDistance < smallestDistance) {
      smallestDistance = theDistance;
      nearestColonyIndex = i;
    }
  }
  cout << "The nearest colony is at index " << i << " and is named " << colonies[i].name << endl;

  int distance(int x1, y1, x2, y2) {
    // Calculate distance (squared) by Pythagorean theorem
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  }
 
  • #3
I managed to do the program, now I need to know how to access a .txt file, so i can take data from it, and also modify data. Using functions and stdio library
 
  • #4
Use the functions whose prototypes are in stdio.h - fopen() for opening a file, fclose() for closing it when you are done, and either fscanf() or fread() for reading from the file. Presumably you have a textbook or at least some documentation that describes these functions and how to use them.
 

Related to How Can You Track the Path of a Destruction Droid in C++?

1. What is the purpose of the "C++ Destruction Droid program"?

The purpose of the "C++ Destruction Droid program" is to create a software program that can simulate and control destructive robots for various purposes, such as military or industrial applications.

2. How does the "C++ Destruction Droid program" work?

The "C++ Destruction Droid program" utilizes the C++ programming language to create a set of instructions and algorithms that control the actions and behaviors of the destruction droids. These instructions are compiled and executed by a computer, allowing the droids to carry out their designated tasks.

3. What makes the "C++ Destruction Droid program" different from other programming languages?

C++ is known for its high performance and efficiency, making it a popular choice for programming applications that require speed and precision. The "C++ Destruction Droid program" utilizes these features to create a powerful and effective control system for the destruction droids.

4. Can the "C++ Destruction Droid program" be used for non-destructive purposes?

While the program was designed for controlling destruction droids, it can also be used for non-destructive purposes such as data analysis, game development, and scientific simulations. The versatility of the C++ language allows for various applications of the "C++ Destruction Droid program".

5. Is the "C++ Destruction Droid program" safe to use?

As with any software program, the "C++ Destruction Droid program" must be used with caution and proper care. It is important to properly test and debug the program to ensure the safety of both the droids and the surrounding environment. Additionally, it is crucial to have trained professionals monitor and operate the program to prevent any potential accidents or errors.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
19
Views
3K
  • Programming and Computer Science
Replies
3
Views
970
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
4K
  • Sci-Fi Writing and World Building
Replies
7
Views
2K
Back
Top