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++?
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 …show more content…

- double payrate = 12.50; e. Copy the value from an existing int variable firstNum into an existing int variable tempNum. - tempNum = firstNum; f. Swap the contents of existing int variables x and y. (Declare any new variables you need.) - inttmp = x; - x = y; - y = tmp; g. Output the contents of existing double variables x and y, and also output the value of the expression x + 12 / y - 8. - cout << x << “ “ << y << “ “ << x + 12 / y – 8 << endl; h. Copy the value of an existing double variable z into an existing int variable x. - x = static

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 << "x = " << x << ", y = " << y << ", z = " << z << endl;
A: x = 2, y = 5, z = 6 b. cout << "x + y = " << x + y << endl; A: x + y = 7 c. cout << "Sum of " << x << " and " << z << " is " << x + z << endl; A: Sum of 2 and 6 is 8 d. cout << "z / x = " << z / x << endl; A: z / x = 3 e. cout << "2 times " << x << " = " << 2 * x << endl; A: 2 times 2 = 4

6. Given the following variable declarations:

int a = 5, b = 6, c;

What is the value of a, b, and c after each of

Get Access