preview

Comp122 Study Guide

Satisfactory Essays

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++? Machine code it the language that the computer understands. High level languages are better because they are easier to understand and work with. 2. What does a compiler do? What kinds of errors are reported by a compiler? A compiler translates one computer language into another. It also pics up errors in the program being put together. 3. What does the linker do? A linker takes multiple object files, and turns them into an executable program 4. What is an algorithm? The list of instructions to complete a task on a program 5. Bob enters a pizza shop and notices …show more content…

21 % 5 answer: 1 d. 3 - 5 % 7 answer: 3 e. 17.0 / 4 answer: 4 f. 8 - 5 * 2.0 answer: -2 g. 14 + 5 % 2 – 3 answer: 12 h. 15.0 + 3.0 / 2.0 answer: 16.0 2. Given the following variable declarations: int num1 = 10, num2 = 20, newNum = 30; double x = 5.0, y = 8.0; Determine which of the following assignment statements are valid. For each invalid statement, explain why it is invalid. Assume that each statement immediately follows the above variable declarations. a. num1 = 15; b. num2 = num1 - 18; c. num1 = 5; num2 = 2 + 6; num1 = num2 / 3; d. num1 + num2 = newNum; e. x = 12 * num1 - 15.3; f. num1 * 2 = newNum; g. x / y = x * y; h. num2 = num1 % 2.0; i. newNum = static_cast (x) % 5; j. x = x + 5; k. newNum = num1 + static_cast (4.6 / 2); 3. For each of the following lines of variable declarations, identify it as valid or describe what makes the line invalid. Line 1: n = 12; valid Line 2: char letter = ; invalid, don't put “letter” Line 3: int one = 5, two; invalid, “One” and “two” not valid inputs Line 4: double x, y, z; valid 4. Write C++ statements that accomplish each of the following: a. Declare and initialize int variables x to 25 and y to 18. 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

Get Access