-std=c++14
switch.
A Stub is a routine that doesn't actually do anything other than declare itself and the parameters it accepts and returns something that is usually the values expected in one of the 'happy scenarios' for the caller. Stubs are used commonly as placeholders for implementation of a known interface, where the interface is finalized/known but the implementation is not yet known/finalized. The stub contains just enough code to allow it to be compiled and linked with the rest of the program.
Help is readily available for resolving compiler errors. The CPTR 124 tutors (see the posted schedule) probably can help you diagnose most of the compiler errors. Since we will encounter more esoteric issues than CPTR 124 students, the CPTR 124 tutors may not be able to resolve all problems. If they cannot help you or you need help with compiler errors at other times, send me the offending source code and I'll help you resolve the problem.
/W4
for Visual C++,
-Wall
for g++).
The warnings are generated for a reason. Do not be satisfied until your
code compiles cleanly (no warnings, no errors)
under the strictest scrutiny.
You should examine any compiler warnings very carefully because often they infer subtle bugs in your code. For example, consider
i
to v.size()
yields a warning
about comparison of an int
to an unsigned
. This
is because i
's declared type is int
, but
v.size
returns an unsigned value (technically a
vector::size_type
).
Often this warning may be ignored without harm,
but what if in this case v
's
size is zero (that is, the vector v
is empty)? The expression
v.size() - 1
evaluates to 4,294,967,295, not –1!
The condition of the for
is initially true when you
would expect it to
be false. Take warnings seriously, and do not be content until
your code compiles without any warnings.
new
eventually should be freed up with a corresponding
delete
. You should be vigilant to
prevent memory leaks but also be careful when deallocating
memory—common mistakes include attempts to reclaim space not
allocated with new
, freeing live memory that will be used
later, and attempting to delete
the
same memory more than once. While each of these memory
deallocation problems may
appear trivial on the surface, you must remain vigilant because
even experienced developers can be plagued by memory management
issues when implementing complex data structures.
Using vectors, smart pointers, and other
features of modern C++ eliminates many of these memory management
concerns.
cout
s or cin
s) within code implementing
collections such as lists, trees, etc.). Clients of your
code are responsible for I/O. You are welcome to add debugging
statements during development, but please remove them when you
submit you code. Any stray output from your
implementation code may interfere with a testing framework used to
evaluate your code for correctness and completeness.
Debug builds do pay a significant cost in terms of execution speed, so when it is time to process a large data set rebuild your project in Release mode. You will not be able to use the debugger and the Debug-mode run-time checks will not apply, so lurking errors may cause your program to crash without much helpful information. In return, your program will run much, much faster.
i
as something more than
a for
loop control variable or a nondescript
parameter is sketchy. Please be consistent
with your spacing and indentation. Pick a
style (K&R, ANSI, GNU, etc.) and use it throughout your
program. Your IDE (if any) may be able to assist you in
consistent formatting.
Be consistent with how you name variables, constants, types, functions, etc.
You should be using comments to clarify code that is not obvious. Functions should be documented sufficiently;
consider:
Really? What if n
is zero? Where applicable,
your function comment should include the function's behavior
under exceptional circumstances. A better
description for the particular function
above would be
Please do your best to limit the length of each line of your source code to 80 characters or less.
In short: The appearance of your submitted code should be of high quality, something that you would be proud to include in a publication.
Points |
Qualification |
0 |
Program does not compile or fails to address the assigned problem. |
1–7 |
Program compiles without errors and addresses various aspects of the assigned problem but contains logic errors or is functionally incomplete. |
8 |
Program compiles, behaves correctly in most situations, but it exhibits some incorrect behavior or is slow performing some activities. |
9 |
Program compiles, behaves correctly in all situations, and performs efficiently in all situations. |
10 |
Program compiles, behaves correctly in all situations, performs efficiently in all situations, uses consistent style, good naming practices, and is well commented. |
Compiler warnings will not affect the assignment's grade; however, review the remarks above about the dangers of ignoring compiler warnings.
Hours Late | Score Adjustment |
---|---|
< 24 | –1 |
24–48 | –5 |
> 48 | Not accepted |
Note: No assignments will be accepted after the due date of the final assignment.
Including your name reassures me that the code I am grading actually is the person's code that I think it is. It also ensures that you will get the proper credit you're due. The honor statement reminds you that, unless specified otherwise, each assignment represents an individual effort and copying others' code is forbidden.