Style guidelines
For this course, you are expected to indent your code and use white space appropriately to display your program structure. Generally, the style used in all the textbooks for code layout is appropriate; an example appears below. You are also expected to choose reasonably informative names for variables and functions, and to accompany each function by a comment that describes the function's purpose, the arguments it expects, and the value (if any) it will return.
Our code follows the convention used in the Astrachan and Mercer textbooks of prefixing the names of private class variables by "my". This reduces confusion that results from the similarity of private variable names and the names of accessor functions that return their values.
Each of your functions should fit on a terminal screen; that is, none of your functions should contain more than 24 lines of code.
We strongly encourage you always to use braces around loop bodies and if/else actions, even though these actions may consist only of a single statement.
Layout example
// Comments on variables may go here int x; // or here // Format 1: Comments describing a function that go before it // may be formatted like this. This same format works for // variables and general commentary about an entire program or // section of a program. /* Format 2 (C-style): Here is another possible format for extended comments at the front of a source file or before function or variable declarations. */ int F (float a, float b, float &x, int n) { if (n < 0) { cerr << "Erroneous input to F: << n << endl; exit (1); } else if (n == 0) { // note that single statements return 0; // should be bracketed too for safety } else { for (int i=0; i<n; i++) { // code is indented here } } switch (...) { case 1: x = n; break; case 2: { int local_variable; ... } default: ... } }