# Output and Lt Essay

659 Words3 Pages
COMP122
Week 1 Homework

Part 1: Complete the following problems.

1. What is machine code? Why is it preferable to write programs in a high level language such as C++?

2. What does a compiler do? What kinds of errors are reported by a compiler?

3. What does the linker do?

4. What is an algorithm?

5. Bob enters a pizza shop and notices there are three different sizes of pizzas available. Sizes are given as the diameter of the pizza in inches. The cost of a pizza is based on the size. Bob would like to know which size of pizza has the lowest cost per square inch.

a. Identify the inputs and outputs for this problem.

b. Identify the processing needed to convert the inputs to the outputs.

c. Design an algorithm
b. Declare and initialize an int variable temp to 10 and a char variable ch to 'A'. c. Add 5 to the int variable x which already exists. d. Declare and initialize a double variable payRate to 12.50. e. Copy the value from an existing int variable firstNum into an existing int variable tempNum. f. Swap the contents of existing int variables x and y. (Declare any new variables you need.) g. Output the contents of existing double variables x and y, and also output the value of the expression x + 12 / y - 8. h. Copy the value of an existing double variable z into an existing int variable x.

5. Given the following variable declarations:

int x = 2, y = 5, z = 6;

What is the output from each of the following statements?

a. cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; ", y = " &lt;&lt; y &lt;&lt; ", z = " &lt;&lt; z &lt;&lt; endl; b. cout &lt;&lt; "x + y = " &lt;&lt; x + y &lt;&lt; endl; c. cout &lt;&lt; "Sum of " &lt;&lt; x &lt;&lt; " and " &lt;&lt; z &lt;&lt; " is " &lt;&lt; x + z &lt;&lt; endl; d. cout &lt;&lt; "z / x = " &lt;&lt; z / x &lt;&lt; endl; e. cout &lt;&lt; "2 times " &lt;&lt; x &lt;&lt; " = " &lt;&lt; 2 * x &lt;&lt; endl;

6. Given the following variable declarations:

int a = 5, b = 6, c;

What is the value of a, b, and c after each of the following statements executes? Assume that the statements execute in the sequence given.

a. a = b++ + 3; b. c = 2 * a + ++b; c. b = 2 * ++c -