CSCI 261 - Programming Concepts - Spring 2021

Lab 7B - Starcraft

This lab is due by Tuesday, April 20, 2021, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Concepts


This assignment exercises your skills for working with input & output file streams to process data to be graphically displayed.


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 the terminal. In the assignment, you will use the new data and draw a star map similar to the one shown here (ahhhh - cool!):


Data File


To begin, create an empty project 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 main.cpp file in the same directory.

Your job is to read the data that is within this file, make modifications to the data in order to draw the data, and write the new data out to a file. 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.

All output should be written to a new file named ModifiedStars.txt.


Coordinates


Each axis in the star coordinate system goes from -1.0 to +1.0 and the origin (0, 0) is at the center. 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 the origin (0, 0) in the upper-left corner of the picture, and the maximum x and y values are the width and height of the window, 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.

To verify the modifications are correct, the first line of the stars.txt file is:

0.994772	-0.023164	-0.099456	4.610000	28	3

The first line of your output should be:

638	327	4.61

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 has the following fields:

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


Lab Submission



You will submit your solution to this lab with the rest of Set7. Detailed instructions for doing this are posted in Assignment 7.


This lab is due by Tuesday, April 20, 2021, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.