Chat with us, powered by LiveChat devry comp122 week 1 homework | Writedemy

devry comp122 week 1 homework

devry comp122 week 1 homework

Question

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 in pseudocode to solve this problem. Make sure to include steps to get each input and generate each output.

Part 2: Complete the following problems.

1. Given the following expressions, what value would they have in a C++ program?

a. 13 / 4

b. 2 + 12 / 4

c. 21 % 5

d. 3 – 5 % 7

e. 17.0 / 4

f. 8 – 5 * 2.0

g. 14 + 5 % 2 – 3

h. 15.0 + 3.0 / 2.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<int> (x) % 5;

j. x = x + 5;

k. newNum = num1 + static_cast<int> (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;

Line 2: char letter = ;

Line 3: int one = 5, two;

Line 4: double x, y, z;

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 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 << “x = ” << x << “, y = ” << y << “, z = ” << z << endl;

b. cout << “x + y = ” << x + y << endl;

c. cout << “Sum of ” << x << ” and ” << z << ” is ” << x + z << endl;

d. cout << “z / x = ” << z / x << endl;

e. cout << “2 times ” << x << ” = ” << 2 * x << 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 – a++;

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order