Homework 1 (Game of Life) FAQ

Q: You said I need to use Qt Creator to write my homework, but I prefer a different editor (Visual Studio, Xcode, Eclipse, Netbeans, vim, emacs, etc.). Can I use my favorite editor instead of Qt Creator?
A: Probably not. We don't support this. We are giving you out a starter project in Qt Creator's format, so if you were trying to use a different editor, you'd have to disassemble that starter project and put it back together in your editor's format, which might be difficult. Also, if you have any problems getting things to work in your editor, we will not be willing to help you fix them.
Q: I'm having trouble getting Qt Creator to work! Help!
A: Please make sure you followed the instructions in our Working at Home page. If you are still having trouble, please see SL Reid Watson's Tricky C++ Issues page for some possible solutions.
Q: When I try to compile my program I see an error message, "cannot open output file ...\Life.exe: Permission denied". What does it mean? How do I fix it?
A: It means that your Life executable is still running from the last time you ran/tested the program a moment ago. Make sure to shut down any previously running instances of your program. Click Qt Creator's "3 Application Output" tab and click any of the red square "stop" sign buttons you see. You might also need to open your operating system's Task Manager to stop them all.
Q: How do I construct a Grid? I tried saying new Grid but it didn't compile.
A: Constructing an object in C++ has a different syntax than in Java. Instead of saying new, you just write a statement such as:
Grid<type> name;

For example, if you wanted to declare a grid of doubles and call the variable myGrid, you would write:

Grid<double> myGrid;
Q: Do I have to use a Grid on the assignment? Can I just use an array?
A: Yes, you must use a Grid. Using an array will not receive full credit.
Q: Can I use one of the STL containers from the C++ standard library, instead of a Grid?
A: No; you should use the Grid.
Q: I already know a lot of C/C++ from my previous programming experience. Can I use advanced features, such as pointers, on this assignment?
A: No; you should limit yourself to using the material that was taught in class so far.
Q: Can I add any other files to the program, other than life.cpp? Can I add some classes to the program?
A: No; you should limit yourself to life.cpp and functions defined in that file.
Q: I am having trouble reading the grid from the file, character-by-character. How do I detect the line endings and how do I know how many characters to read?
A: We don't recommend reading the file character-by-character. Instead, repeatedly call getline on the file and then process that entire line. If the line contains an integer or numeric token, call stringToInteger to convert it.
Q: How do I count the neighbors of a cell?
A: Examine the eight squares around it. Be careful not to go out of the bounds of the grid, if the square you're examining is on an edge of the grid. Also be careful not to count the current cell itself as a neighbor. We suggest inserting temporary debugging statements to cout to show you what your program is examining along the way. For example, as you look at each square, print the row/column numbers, along with how many neighbors you count for that cell or which cells you think have living neighbors in them.
Q: I am having trouble reading the input files. It always crashes with a "file not found" error. What is wrong?
A: Remember that the input files are in the same directory as your program, so if the user types "foo.txt" you need to open "foo.txt" in your code with no path or directory name in front of the file name. The grid input files should be found in the starter ZIP file in the res subdirectory of the overall project. That's also where you can put your own custom mycolony.txt file later when you make it.
Q: What does this error mean?
error: invalid initialization of non-const reference of type 'Grid<foo>&' from an rvalue of type 'Grid<foo> (*)()'
A: This can happen when you declare your Grid in the wrong way:
Grid<type> name();   // no
Grid<type> name;     // yes

For example, if you wanted to declare a grid of doubles and call the variable myGrid, you would write:

Grid<double> myGrid;
Q: What does this error mean?
error: symbol(s) not found for architecture x86_64
A: This can happen when you are trying to call a function that you have not declared, or call a function with the wrong parameters. Remember that you need to declare function prototypes (the function's name and parameters followed by a semicolon) at the top of your program for main to be able to see them.

Try clicking the "4 Compiler Output" tab button near the bottom of Qt Creator and reading the detailed output about exactly what symbol was not defined.

Q: Why can't I pass an ifstream file input stream as a parameter?
A: You must pass it by reference.
Q: My output seems to be "jerky"; sometimes things won't print out when I think they should, and then later a bunch of output prints all at once. Why would this be happening?
A: It might have to do with \n vs endl and something called output buffering. When you print to cout, it doesn't always immediately send the output to the console. This is because sending output to the console is somewhat slow/expensive, so for example if you print a grid character-by-character, it is slow to individually print every single character. So cout has an internal buffer in which it stores the characters you tell it to print. Periodically, cout decides to flush out this buffer and print everything you told it to print.

One way to force cout to flush out all of its buffered output is to print endl. Note that it does NOT flush the output if you print "\n" instead of endl. So most of the time, if you're seeing weirdly delayed output, it's because you are doing cout << something << "\n"; instead of the preferred, cout << something << endl;

Another way to force cout to flush out any buffered output is to say, cout.flush();

Q: How do I do animation?
A: It's the same as doing a single tick to the next generation, but you do it repeatedly. Between ticks, pause the simulation (pause) and also clear the console text (clearConsole) so that the animation looks smooth.
Q: The expected output files don't appear to "clear" the console between frames of animation. Why not? Which should I follow, the spec or the expected output files?
A: You should follow the spec and clear the console between frames of animation. The expected output files can't really show the console clearing because there's no way to show that in a flat text file. You can still match their output by copy-pasting from the bottom "3 Application Output" tab of Qt Creator.
Q: I am trying to get the LifeGUI extra feature to work, but my program crashes every time. Why?
A: Make sure not to declare it as a global variable. Declare it inside of main.
Q: I am doing the LifeGUI extra feature, but when the program is done, it does not actually exit; it just hangs. How can I make it exit properly?
A: At the end of main, you can call the function exitGraphics(); to shut down the program.
Q: Will my solution get full credit? Is it written in the style you want? Will I get marked off for this code?
A: In general we cannot answer these kinds of questions. We call this "pre-grading." The section leader/TA/instructor can't look over your entire program for mistakes or tell you exactly what things you will get marked off for; we don't have the resources to provide such a service, and even if we did, we want you to learn how to gain these intuitions on your own. We'll grade you on the guidelines in the homework document, and we can help you with specific issues and questions about your code, but we cannot pre-evaluate your entire program for you or give you advance warning about every possible mistake or violation.
Q: The assignment writeup says your sample solution has a certain number of lines or functions. I don't have exactly that many. What have I done wrong? Will I be lose points?
A: You don't have to exactly match our counts. They are just there as a sanity check. If your numbers are WAY off from ours, you may be solving the problem in the wrong way.
Q: Is my mycolony.txt file okay? Will it get full credit?
A: Our grading is pretty lenient on a creative part aspect like this. If it meets the criteria in the assignment spec, it should get full credit, even if it is not particularly creative or exciting.
This document and its content are copyright © Marty Stepp, 2014. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the authors' expressed written permission.