- What is whitespace?
- What is meant by freeform?
- What does it mean to maintain programs?
- What does C++ prefer most, uppercase or lowercase letters in programs?
- What are comments?
- Why are comments necessary?
- What does the compiler do when it sees a comment?
- What do all C++ comments begin with?
- What is the difference between a C-style comment and a C++-style comment?
- What happens when you nest C-style comments?
- True or false: Longer programs are more difficult to understand than shorter ones.
- True or false: You can substitute parentheses for braces if you feel that the parentheses are more readable.
- True or false: Comments are not Visual C++ commands.
- True or false: You can nest one C++ comment inside another.
- Match the special character on the left with that special character's description on the right.
Special Character Description [ Backslash < Left bracket } Right-angled bracket | Right parenthesis \ Forward slash (or just slash) ] Left-angled bracket { Left parenthesis ) Right brace ( Vertical line > Left brace / Right bracket There is no What's the Output? section in this unit. Find the Bug - Here is a comment and a C++ command (the return statement). Where is the problem?
// Go back to the IDE return;
- The following program contains three comment bugs. See whether you can determine what is wrong.
// This program computes taxes #include
void main() { The next few lines calculate payroll taxes // Computes the gross pay float gross = 40 * 5.25; float taxes = gross * .40; / Just computed the taxes cout "The taxes are " <<> Write Code That. . . - Tim Peterson wants to put his name at the top of his program using a comment. Write a comment that contains Tim's name using both the C++-style and the C-style approach.
- Here is the same program you saw earlier, with one difference: The programmer forgot to precede the comments with double slashes. After trying to compile the program, the programmer looked at the 20 or so error messages and realized what was left out. See if you can help the programmer correct the program by inserting the proper commenting symbols everywhere they go.
Filename: 1STLONG.CPP Longer C++ program that demonstrates comments, variables, constants, and simple input/output #include
void main() { int i, j; These three lines declare four variables char c; float x; i = 4; i is assigned an integer literal j = i + 7; j is assigned the result of a computation c = 'A'; Enclose all character literals in single quotation marks x = 9.087; x is a floating-point value x = x * 12.3; Overwrites what was in x with something else Sends the values of the four variables to the screen cout <<> - Hint: Count the number of double slashes you put in this program. If you did not add 18 double slashes (or if you added more than 18), try again.
Extra Credit - Of the following five lines, which contain useful comments and which contain redundant ones?
clog << '\n'; // Sends an end-of-line to the error log radius3 = radius1 + radius2; // Calculates radius3 // The following code contains a C++ program // The following code tracks your investments clog << '\n'; // Sends '\n' to clog
Comments