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++?
A: The machine code is the language which the computer hardware understands and executes. It is preferable to write programs in a high level language such as C ++ because it is much easier to understand and learn this machine language.
2. What does a compiler do? What kinds of errors are reported by a compiler?
A: A computer translates high level language into machine code. While a compiler reports errors such as syntax errors.
3. What does the linker do?
A: A linker takes one or more machine code modules generated by a compiler and combines them into a single executable program.
4. What is an algorithm?
A: An algorithm is a list of instructions set up for completing a task
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. A: Inputs are the diameter and cost of each of the three different size pizzas Outputs are the size of pizza with the lowest cost per inch b. Identify the processing needed to convert the inputs to the outputs. A: Area of each pizza in square inches = pi * (diameter / 2)^2 Cost per square inch = cost / area c. Design an algorithm in pseudocode to solve this problem. Make sure to include steps to get each input and generate each output. 1. Get diameter of first size pizza and cost of first person 2. Find area of first pizza 3. Find cost per square inch of first pizza 4. Get diameter of second size pizza 5. Find area of second pizza 6. Find cost per square inch of second pizza 7. Get diameter of third pizza 8. Get cost of third pizza 9.