Question

Sample input/output Program2 Please enter heading for waypoint 1 in degrees: 50 Please enter distance to waypoint 1 in meters: 2671 Move on heading due East for 1716.94 meteras Move on heading due North for 2046.06 motors Please enter heading for waypoint 2 in degrees: 170 Please enter distance to waypoint 2 in meters: 8329 Move on heading due Weat for 8202.34 meters Move on heading due North for 1447.03 meters Please enter heading for waypoint 3 in degrees: 260 Please enter distance to waypoint 3 in meters: 1920 Move on heading due West for 333.66 meters Move on heading due South for 1890.79 meters Please enter target bearing in degrees: -12 Please enter target range in meters: 200 Run Silent, Run Deep Students took possession of a WWII submarine named the Sword-Fish, which is diesel electric with no electronics on board and a small electrical computer, then set out to sink the enemy. The compass on the sub is worn out and only the East, North, West and South markers are distinguishable, and hence can only navigate in those four directions. Write a program as follows: Asks the user for the magnitude (distance), in meters, and the heading, in degrees of the navigation to - -Decompose the vector into x and y components and output the magnitude and direction (North, West Fire torpedo on heading -11.4 degroes with a spread of 2 degrees South, or East are the only reliable headings on the subs compass) of the x component and then the y component. The x component is the magnitude multiplied by the cosine of the angle. The y component is the magnitude multiplied by the sine of the angle. Determine compass direction depending on weather the vector component is positive or negative This step has to be repeated for waypoints two and three. Ask the user for the target bearing (-30 to 30 degrees) and range (distance in meters). Output a firing solution as follows EMPLATE: must use this #includestdieb int main(void) - - Range 100 to 499 500 to 999 1000 to 1499 1500 to 2000 Tor x0.05 x 0.08 Bearing bearing x0.10 Bearing+ bearing x0.12 Return O; Bearing bea Target Torpedo spread 5 degrees 14 to -1 0 to 14 No input validation is required, assume user will enter values of correct type and range Note: Create variables to store data as needed.Only using 'if', 'else', 'else if' statements PLZ.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the C code.I hope that i have provided sufficient comments for you better understanding.

#include <stdio.h>
#include <math.h>

//define value of PI
#define PI 3.14159265

//This will return absolute value
double absolute(double);

int main ()
{
double degree,distance,resdegree;

//Take inputs for the 3 way points

//1st INPUT
//Take degree as input
printf("Please enter heading for waypoint 1 in degrees : ");
scanf("%lf",&degree);

//Take distance as input
printf("Please enter distance to waypoint 1 in meters : ");
scanf("%lf",&distance);

//print the x component that is cos component
//If direction is in 1st and 4th quadrant then East direction else West
if( (degree>=270&&degree<=360) || (degree>=0&&degree<=90) )
{
printf("Move on heading due East for %f meters\n",distance * cos( degree*(PI/180.0) ) );
}
else
{
printf("Move on heading due West for %f meters\n",-distance *cos( degree*(PI/180.0) ) );
}
//print the y component that is sin component
//If direction is in 1st and 2nd quadrant then North direction else South
if(degree>=0&&degree<=180)
{
printf("Move on heading due North for %f meters\n",distance * sin( degree*(PI/180.0) ) );
}
else
{
printf("Move on heading due South for %f meters\n",-distance * sin( degree*(PI/180.0) ) );
}

//2nd INPUT
//Take degree as input
printf("Please enter heading for waypoint 2 in degrees : ");
scanf("%lf",&degree);

//Take distance as input
printf("Please enter distance to waypoint 2 in meters : ");
scanf("%lf",&distance);

//print the x component that is cos component
//If direction is in 1st and 4th quadrant then East direction else West
if( (degree>=270&&degree<=360) || (degree>=0&&degree<=90) )
{
printf("Move on heading due East for %f meters\n",distance * cos( degree*(PI/180.0) ) );
}
else
{
printf("Move on heading due West for %f meters\n",-distance *cos( degree*(PI/180.0) ) );
}
//print the y component that is sin component
//If direction is in 1st and 2nd quadrant then North direction else South
if(degree>=0&&degree<=180)
{
printf("Move on heading due North for %f meters\n",distance * sin( degree*(PI/180.0) ) );
}
else
{
printf("Move on heading due South for %f meters\n",-distance * sin( degree*(PI/180.0) ) );
}

//3rd INPUT
//Take degree as input
printf("Please enter heading for waypoint 3 in degrees : ");
scanf("%lf",&degree);

//Take distance as input
printf("Please enter distance to waypoint 3 in meters : ");
scanf("%lf",&distance);

//print the x component that is cos component
//If direction is in 1st and 4th quadrant then East direction else West
if( (degree>=270&&degree<=360) || (degree>=0&&degree<=90) )
{
printf("Move on heading due East for %f meters\n",distance * cos( degree*(PI/180.0) ) );
}
else
{
printf("Move on heading due West for %f meters\n",-distance *cos( degree*(PI/180.0) ) );
}
//print the y component that is sin component
//If direction is in 1st and 2nd quadrant then North direction else South
if(degree>=0&&degree<=180)
{
printf("Move on heading due North for %f meters\n",distance * sin( degree*(PI/180.0) ) );
}
else
{
printf("Move on heading due South for %f meters\n",-distance * sin( degree*(PI/180.0) ) );
}

//Take input for target and range
printf("Please enter target bearings in degrees : ");
scanf("%lf",&degree);

printf("Please enter target range in meters : ");
scanf("%lf",&distance);

//Checking for the given condition on range
if(distance>=100&&distance<=499)
{
resdegree=degree+ absolute(degree*0.05);
}
else if(distance>=500&&distance<=999)
{
resdegree=degree+ absolute(degree*0.08);
}
if(distance>=1000&&distance<=1499)
{
resdegree=degree+ absolute(degree*0.10);
}
if(distance>=1500&&distance<=2000)
{
resdegree=degree+ absolute(degree*0.12);
}

//Checking for the given condition on target bearing
if( (degree>=-30&&degree<=-15) || (degree>=15&&degree<=-30) )
printf("Fire torpedo on heading %f degrees with a spread of a 5 degrees\n",resdegree);
else if( degree>=-14 && degree<=14)
printf("Fire torpedo on heading %f degrees with a spread of a 2 degrees\n",resdegree);
return(0);
}
double absolute(double n)
{
if(n<0)
return -n;
return n;
}

Below is the screenshot of output-

Instead of checking the direction by applying condition on degree 3 times,you can make a function which will make the code more appealing and easy to understand and you won't need to write the same piece of code again & again.But as mentioned in the question,I only used if and else .

Hope i have answered your question satisfactorily.Leave doubts in comment section if any.

Add a comment
Know the answer?
Add Answer to:
Only using 'if', 'else', 'else if' statements PLZ. Sample input/output Program2 Please enter heading for waypoint...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A long current-carrying wire, oriented North-South, lies on a table (it is connected to batteries which...

    A long current-carrying wire, oriented North-South, lies on a table (it is connected to batteries which are not shown). A compass lies on top of the wire, with the compass needle about 3 mm above the wire. With the current running, the compass deflects 10 degrees to the West. At this location, the horizontal component of the Earth's magnetic field is about 2e-5 tesla. What is the magnitude of the magnetic field at location A, on the table top, a...

  • please show explanation! thank you Each of the electrons in the beam of a television tube...

    please show explanation! thank you Each of the electrons in the beam of a television tube has a kinetic energy of 10.0 keV. The tube is oriented so that the electrons move horizontally from north to south. The vertical component of Earth's magnetic field points down and has a magnitude of 52.0 ut. (Ignore the northward component of Earth's field.) In what direction will the electron beam deflect? O north O east O west o down O up south Submit...

  • answer b please. I dont need part a i got that already. i tried to solve...

    answer b please. I dont need part a i got that already. i tried to solve b but my answr was wrong. 092619 LifeHist-BIO 3250 a Amazoncom: Watch The Ka The Expert TA | Human x + v thttps//usb06ca.theexpertta.com/Common/TakeTutorialAssignment.aspx Cass Mansgement HW chapter 3 Begin Date: 9/5/2019 12:01:00 AM- Due Date: 9/14/2019 11:59:00 PM End Date: 12/31/2019 11:59:00 PM (9%) Problem 11: has a velocity of 2.1 m/s in a direction 33° east of north relative to the Earth. It...

  • Why is the component of A-y 61.40 but also 25? Help explain please the first displacement,...

    Why is the component of A-y 61.40 but also 25? Help explain please the first displacement, B the second, and C the third. We can estimate from the diagram that the vector sum R is about 10 m, 40° west of north. The angles of the vectors, measured counterclockwise from the +x axis, are 58, 216, and 270°. We have to find the components of each. Practice Problem 1.8 SOLVE The components of A are Consider four finalists in a...

  • what is the answer for part d please? (15%) Problem 4: I start walking. The 1st...

    what is the answer for part d please? (15%) Problem 4: I start walking. The 1st leg of my trip I walk da = 95 m at 8A = 15° south of east. The 2nd leg of my trip I walk dz = 95 m at 63 = 13° north of east. On my final leg I walk dc = 95 m at 0c = 63.5° north of west Choose the coordinate system so that x is directed towards the...

  • CProgramming using Dev C ++ #include <stdio.h> PLEASE NO math.h Corporate Sales Data Report Write a...

    CProgramming using Dev C ++ #include <stdio.h> PLEASE NO math.h Corporate Sales Data Report Write a program that read creates a structure for a company's divisions. The structure should have: Division name (North, South, East, West, and Central) Quarter (1, 2, 3, or 4) Quarterly sales · Your job is to write a program that will create a two-dimensional array of 5 rows (divisions) and 4 columns (quarters). The program should ask the user to enter in all four quarters...

  • please answer both questions ty so much Two forces are acting on a 0.250 kg hockey...

    please answer both questions ty so much Two forces are acting on a 0.250 kg hockey puck as it slides along the ice. The first force has a magnitude of 0.400 N and points 35.0 north of east. The second force has a magnitude of 0.580 N and points 65,0° north of east. If these are the only two forces acting on the puck, what will be the magnitude and direction of the puck's acceleration? Enter the direction as an...

  • 1) A steam ship is sailing along the Congo River at 10 mph and with a...

    1) A steam ship is sailing along the Congo River at 10 mph and with a heading of N 90" E. The current of the river is flowing from east to west at 10 mph. Use vector addition to calculate the movement of the ship. a) [20,0] mph b) [10,0] mplh c) 10,0] mph d) [0,10] mph e) (o,20] mph 2) Two parallel vectors both have an azimuth of 36. One vector has a length of 8 cm, and the...

  • Can someone please help me with D and E. Constants Part A To understand the magnetic...

    Can someone please help me with D and E. Constants Part A To understand the magnetic force on a straight current-carrying wire in a uniform magnetic field. Magnetic fields exert forces on moving charged particles, whether those charges are moving independently or are confined to a current- carrying wire. The magnetic force Fon an individual moving charged particle depends on its velocity and charge er. In the case of a current-carrying wire, many charged particles are simultaneously in motion, so...

  • Could you please help with the following parts: a. b. c. A system has the impulse response of. If the following signal is input into this system: Enter the output of this system (y[지) into the bla...

    Could you please help with the following parts: a. b. c. A system has the impulse response of. If the following signal is input into this system: Enter the output of this system (y[지) into the blank space provided (use π = pi in equations, eg. 1 +2cos(0.5pin) = 12 cos(0.5Tn)) The magnitude response of a discrete-time filter is plotted between the range-4T ώ +6x and is shown below. 10 -2 0 Normalised Radian frequency x Tm What type of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT