I have no idea ho to write a program for this problem and i am new to C++ so I really needhelp!!

Consider the following file called "raw_points.txt". The first line of this file contains a count of how many pairs of coordinates are specified in this file. The remaining lines contain pairs of (x,y) coordinates, one pair per line and separated by a space:

raw_points.txt

15

0 1.38

87 0

32 32

3.2 6.4

1.25252 0.680254

1.6877 0.137556

0.819814 1.75999

0.638961 1.96114

0.17001 1.81526

0.205019 1.84396

1.0151 1.74458

0.666519 1.38482

1.11389 0.72383

0.0639877 1.71702

0.197969 1.75414

If you calculate the radial length of each coordinate pair using the Pythagorean Theorem you get lengths ranging anywhere from 1.33 to 87. Let's normalize the numbers so that the radial length is always exactly 1.0.

As a rationale, imagine that we're wanting to convert the numbers into a table of cosine and sine values of the angle represented by each coordinate pair. This is useful in many situations - for example, many video games and computer graphics applications need "normal maps" that indicate the angle that each pixel on an image is "facing" - when lighting calculations are applied, this makes a flat picture of a rock surface look 3D due to the resulting highlights and shadows.

The formula to take a raw coordinate pair (x,y) and normalize it as (x',y') is simple:

x' = x / r

y' = y / r

where r is the radial length of (x,y) - which itself is:

r = sqrt( x2 + y2 )

Here's the same data but with normalized coordinate pairs:

normalized_points.txt

15

0 1

1 0

0.707107 0.707107

0.447214 0.894427

...

0.112146 0.993692

Notice how the numbers are still proportionally the same relative to one another - the polar direction stays the same but the polar distance becomes 1.0.

Assignment

Make a proj8 directory. Use Vim to create the file "raw_points.txt" - copy the raw_points.txt contents from above, start editing a file by the same name, go into insert mode, and type SHIFT+INSERT to paste the numbers in.

Next, write a program to load the data from raw_points.txt, convert it, and save it as normalized_points.txt. Here are some guidelines.

Appendix A at the end of this assignment lists some relevant file commands you'll need.

Open the file "raw_points.txt" as an input filestream.

Open the file "normalized_points.txt" as an output filestream.

Read in the count of how many points there are from the input file.

Write the count out to the output file (with an endl) and then repeat the following that many times:

Read in an x value.

Read in a y value.

Calculate the radial length of (x,y).

Divide both x and y by r.

Write x and y to the output file, separated by a space and with a cursor return at the end.

Close both the input and the output file.

Compile and run the program. Nothing should print to the screen - if it does, you're accidentally printing to the screen instead of to the output file. If you type "cat normalized_points.txt" you should see the same numbers as shown in the example above.

Also have your program work with command line arguments instead of "hard-coding" the filenames in. You should be able to type:

./proj8 raw_points.txt normalized_points.txt

and have the program figure out what two filenames you typed as you ran the program. Note that the specific filenames "raw_points.txt" etc. should no longer be present in your source code.