LAB 10A - STAR FILE

Concepts

This assignment exercises your new skills for working with file streams.

Instructions

Your task for this lab is to read a data file containing star information, modify the information read, and write the new data to an output file. On Wednesday, you will read in the new data file you created and draw a star map similar to the one shown here (ahhhh - cool!) This lab will be due with Homework 10.

Data File

To begin, create an empty project (called Lab10A), and place the stars.txt file in the appropriate directory. As previously mentioned, an input file needs to be placed at the project level. You should see both your input file AND a .vcxproj file in the same directory.

Basically your job is to read the data that is within this file, make modifications to the data in order to draw the data, and then write the modified data to a new file called ModifiedStars.txt (for use on Wednesday). Each line of the data file contains information of one star, with each field separated by a tab. The meaning of each field (column) is described below. Note that data files often contain more information than is needed for a given purpose and that data files may contain outlying values that are also not needed for a given purpose. We suggest you take a look at the stars.txt as you read the following details about your input file.

Coordinates

Each axis in the star coordinate system goes from -1.0 to +1.0 and the center point is (0, 0). Thus, the x and y coordinate values for each star will all be numbers in the range -1.0 to +1.0.

The coordinate system used in our graphics library (SFML) has position (0, 0) in the upper-left corner of the picture, and the maximum x and y values are the width and height of the picture, in pixels.

Star Coordinate System          Graphics Coordinate System

Thus, to determine the location of each star to draw in our graphics library, you need to convert from the -1.0 to +1.0 range of the star coordinate system to the (0, 0) to (WIDTH, HEIGHT) range of the graphics library coordinate system. Declare WIDTH and HEIGHT as constants in your program, with both values set to 640 (which are defined for your screen size).

More specifically, if xStar is a double variable holding a star's x-coordinate in the range -1.0 to +1.0, to convert it to an integer pixel value in the range 0 to WIDTH, you would use the following:

int xPixel = (int)( ( xStar + 1 ) * WIDTH / 2 );

Similarly, if yStar is a double variable holding a star's y-coordinate in the range -1.0 to +1.0, to convert it to an integer pixel value in the range 0 to HEIGHT, you would use the following:

int yPixel = (int)( ( -yStar + 1 ) * HEIGHT / 2 );

Note the minus sign on the yPixel equation. We encourage you to plug a few coordinates into these equations, e.g., (-0.5,0.5) and (-0.5,-0.5), to ensure the equations are correct.

Putting It All Together

Even though we are only using the x, y, and brightness values, you will need to read all six values on each line of the data file. Make sure you read each of these into an appropriate type variable.

Each line in the output file has the following fields:

As discussed, do not include a line in your output file if the star brightness is greater than 8.0. Also, be sure to check your input/output files open appropriately and close them when you are done with them.