Question: Create a program in c++ that will read the text file, input.txt, included in this assignment. The first line has an integer that shows how

Create a program in c++ that will read the text file, input.txt, included in this assignment. The first line has an integer that shows how many values are in the data file. Each line contains a force in Newtons. The force is written in Cartesian coordinates (12.3i 34.5j). The first number is is x component. The second number is the y component.

Your program will read the first integer to determine how many lines to read. For each line, your program should read in the two parts of the force into two float type variables. The program should calculate the magnitude and direction for each pair of numbers that it reads:

magnitude= Fx2+Fy2
direction=tan1FyFx
Assume that all forces are directed into the first quadrant (positive x and positive y).

The program should then output the magnitude, a tab, the direction in radians, a tab, the x component, a tab, the y portion, and a newline character. The output can go to the screen, but it should also go to a file called output.txt.

Where there are any errors in the input, the program should skip that line, and write to the screen and to the output file: "Error reading line XX." where XX is the line number at which the error occurred. A missing number is an error. A missing i or j is also an error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!