answerLab1: (for project 2 use)

section: 1 (11:00-12:15)

section: 2 (2:00-3:15)

Name:______

Question #1.3: What happens when you remove the asterisks (i.e., *) before the lines you just added?

Undo your change.

Question #1.4: What happens when you remove the /* at the very beginning of the file?

Undo your change.

Question #1.5: What happens when you remove just the / at the very beginning of the file?

Undo your change.

Question #1.6: What happens when you remove just the first * (right after the / at the beginning of the file?

Undo your change.

You should have a good idea where this comment starts.

Question #1.7: Where do you suppose this opening comment ends?

Another way to introduce a comment is with //, two slashes. This type of comment is used to indicate the algorithm steps in the program.

Question #1.8: Remove one of the //s in the program. What happens when you compile the code?

And, yet again, make sure your program is restored back to a compilable state.

Includes

You'll find two lines that use the #include directive right after the opening comment. These lines tell the compiler that it needs to access some library files. They're necessary for some of the operations that the program does.

Question #1.9: What happens when you delete one of the #include lines?

Question #1.10: What happens when you add some spaces before a #include?

Question #1.11: What happens when you move one of the includes to the end of the file?

Remember to restore your file after each question.

The Program: int main()

The main program is designated by main(). The main algorithm must be encoded in this function.

Question #1.12: What happens when you drop the parentheses: main() becomes just main?

Question #1.13: What happens when you drop the int before main()?

Question #1.14: What happens when you replace the curly braces (i.e., { and }) with parentheses (i.e., ( and ))?

Question #1.15: What happens when you add extra spaces before the int?

Again, restore your program after each question so that it compiles and executes correctly.

Input and Output

The input and output statements for Steps 1, 2, 3, and 5 all begin with either cin or cout followed by objects that should be displayed and used to read in values. The objects are separated with the operators and .

Question #1.16: What happens when you replace a cout with cin?

Question #1.17: What happens when you remove a ?

Question #1.18: What happens when you remove a ?

Question #1.19: What happens when you replace a with ?

Question #1.20: What happens when you replace a with ?

And yet again, restore your program after each question so that it compiles and executes correctly.

Declarations

Before we can use a variable in a C++ program, we must first declare it. The leg1 and leg2 variables are declared with this line:

double leg1, leg2;

Question #1.21: What happens when you delete this line?

Question #1.22: What happens when you move it after Step 4?

Question #1.23: What happens when you move it before main()?

Be sure to return your file to this original state.

Semicolons

Semicolons end almost every C++ statement.

Question #1.24: What happens when you remove a semicolon from one of the statements?

Question #1.25: What happens when you add an extra semicolon?

Question #1.26: What happens when you add some extra spaces before a semicolon?

You might be a bit worried about the #include directive; it doesn't have a semicolon!

Question #1.27: What happens when you add a semicolon after an #include directive on the same line?

Question #1.28: How do statements and directives differ with respect to semicolons?