Lab 9: File Graphics

This assignment is pretty simple.

Create a new project

Create a new project folder for this lab. Then, using the file explorer tool on your system, copy these files from your Array Graphics lab into this new folder:

  • main.cpp
  • Graphics.h
  • Graphics.cpp
  • CMakeLists.txt

Now, start CLion. Once it has opened, close the active project if it remembers the last one you were working on. You should see a panel offering to open a project.

Select “Import Project from Sources” and navigate to the folder you created. Click on “Open Project”. CLion will complete the setup it needs to manage this new project.

Note

It is not strictly needed, but you can change the project name CLion uses to identify this project by editing the CMakeLists.txt file. Edit the line that says this:

  • project(ProjectName)

Change “ProjectName” to something like “FileGraphics”

Run this code to make sure it builds the robot image you submitted earlier.

Your Job

Now, make these changes to your code:

  1. Make sure the array you use for your data is “global”, meaning you set it up at the top of your program, outside of any other function. Place the array declaration after the “include” lines in the main.cpp file. Make the array 500 items big.
  2. In the main function, before the call to the graphicsSetup function, place code to open a data file named “robot.txt”. Use the lecture notes to see how to do this.
  3. After the file is opened, add code to read in all the numbers from the data file into your data array. Your loop should end when you run out of numbers in the file.
  4. Create the robot.txt file (using the editor in CLion if needed), and place all the data you had in your previous lab in the file. You can set this up as one “sgape” per line, with all the numbers needed for one shape on a line.

Warning

Make sure that you use spaces to separate the numbers. Commas will mess this up!

Also, make sure you copy this data file into the “cmake-build-debug” folder so your program can find the file!

  1. Run your program. You should see the same robot you created earlier.

What to turn in

I will need to see two files for this project:

  • main.cpp
  • robot.txt

You can upload both files at the same time in BB.