4.1k views
4 votes
Question 1:

The Wayfinder is an ancient piece of technology created as a means of navigating challenging stretches of space. The device connects to every piece of technology in the galaxy in order to detect planets and spaceships and then shown their location to the user. As it happens, locations of planets follow a specific distribution. A planet can exist at coordinates x,y only if
2x² + |2xy| + y² =10000
The user can use the Wayfinder to find nearby planets by input the range for x and y. Draw a flowchart and write a C++ program that models the Wayfinder. Ask the user to input a range for x and y, then print all possible planet coordinates. The program should also print the number of planets detected.
Hint: you can use pow(x,n) to get the value of xn and abs(x) to get the absolute value of x.

helpppppppppp!!!!!!!!!!

Sample output:

Question 1: The Wayfinder is an ancient piece of technology created as a means of-example-1

1 Answer

3 votes

Answer:

Following are the code to the given question:

#include<iostream>//header file

#include<math.h>//header file

using namespace std;

int main()//main method

{

long long x, x1, y, y1;//defining long variable

int count=0,i,j;//defining integer variable

cout<<"Enter a range for x coordinates: "<<endl;//print message

cin>>x>>x1;//input x and x1 value

cout<<"Enter a range for y coordinates: "<<endl;//print message

cin>>y>>y1; //input y and y1 value

for(i = x; i <= -x1; i++)//use nested loop that tests each coordinates

{

for(j = y; j <= y1; j++)//use nested loop that tests each coordinates

{

if(((2*pow(i,2)) + abs(2*i*j) + pow(j,2)) == 10000)//use if that checks condition as per the given question

{

cout<<"There is a planet at "<<i<<", "<<j<<endl;// print coordinates

count++;//incrementing count variable value

}

}

}

cout<<"Total number of planets detected are: "<<count<<endl;//print count value

return 0;

}

Step-by-step explanation:

In this code, inside the main method long "x, x1, y, and y1" and integer "count, i, and j" type variable is declared that uses a long variable to input value from the user-end.

In the next step, two nested loops have defined that test each coordinate and define if block that checks condition as per the given question and use i, j, and count variable to print value with the message.

User Ihsanberahim
by
6.6k points