Premium Essay

Week 2 Homework Comp122

In: Computers and Technology

Submitted By shelleyadkins
Words 300
Pages 2
COMP122
Week 2 Homework

Complete the following problems.

1. Suppose you are given the following variable declarations:

int x, y; char ch;

What values (if any) are assigned to x, y, and ch after each of these statements execute? Assume that the input to each statement is the same: 5 28 36

a. cin >> x >> y >> ch;
a) x = 5, y = 28, ch =3

b. cin >> ch >> x >> y;
b) x = 28, y = 36, ch = 5

c. cin >> x >> ch >> y;
c) x = 5, y = 8, ch = 2

d. cin >> x >> y; cin.get(ch);
d) x = 5, y = 28

2. Suppose you are given the following variable declarations:

int x, y; char ch;

What values (if any) are assigned to x, y, and ch after each of these statements execute? Assume that the input to each set of statements is as follows:

13 28 D 14 E 98 A B 56

a. cin >> x >> y; cin.ignore(50, '\n'); cin >> ch;
a) x = 13, y = 28, ch = 1

b. cin >> x; cin.ignore(50, '\n'); cin >> y; cin.ignore(50, '\n'); cin.get(ch);
b) x = 13, y = 14, ch = A

3. Suppose you are given the following variable declarations:

int x, y; double z; char ch;

Assume you have the following input statement:

cin >> x >> y >> ch >> z;

What values (if any) are stored in x, y, z, and ch if the input is:

a. 35 62. 78
a) x = 35 y = 62 ch = z = 78

b. 86 32A 92.6 b) x = 86 y = 32 ch = A z = 9206
c. 12 .45A 32 c) x = 12 y = some garbage value ch = some garbage value z = some garbage value

4. Write a C++ statement that uses the manipulator 'setfill' to output a line containing 35 asterisk characters.

Similar Documents

Premium Essay

Comp122 Assignment

...COMP122 Week 1 Homework Part 1: Complete the following problems. (13 points) 1. What is machine code? Why is it preferable to write programs in a high level language such as C++? (2 points) Machine code is a computer programming language that a computer hardware can understand and respond to. It is much easier to understand machine language and learn how to write programs using C++. 2. What does a compiler do? What kinds of errors are reported by a compiler? (1 point) A compiler helps translate human created code into machine code for the computer. A compiler reports any errors in the code, such as syntax errors. 3. What does the linker do? (1 point) A linker takes one or two machine codes and combines them into one program. 4. What is an algorithm? (1 point) Algorithms are a list of instructions set up to complete 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. (2 points) Input: diameter of the three different size pizzas and cost Output: size of pizza with the lowest cost per inch b. Identify the processing needed to convert the inputs to the outputs. (2 points) Area of each pizza in square inches= pi x (diameter divided by 2)^2 c. Design an algorithm...

Words: 805 - Pages: 4

Free Essay

Electrical Engineering

...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 machine code is consisting of a low level programming language that is executed by CPU. Writing a program in C++, a computer translate the C++ code in the machine code for the CPU to understand. 2. What does a compiler do? What kinds of errors are reported by a compiler? Compiler help translate high level programming language into machine code. That will report any syntax, type errors, and declaration errors. 3. What does the linker do? The linker takes in object of a library file which combines them into an module or load module. It can also converts object files into executable files. 4. What is an algorithm? An algorithm is a set of instructions to follow when writing any kind of programs. 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. The inputs are the diameter of each pizza and cost. The outputs are the prompt for the users to determine the diameter and cost of each pizza which he will finished the cost of per square inch. b. Identify the processing needed to convert the inputs to the...

Words: 1021 - Pages: 5