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

devry comp122 week 3 homework

devry comp122 week 3 homework

Question

COMP122

Week 3 Homework

Complete the following problems.

1. What is the output from the following C++ code fragment?

int count = 1;

int y = 100;

while(count < 100)

{

y = y – 1;

count++;

}

cout << “y = ” << y << ” and count = ” << count << endl;

2. What is the output from the following C++ code fragment?

int num = 1;

while(num < 10)

{

cout << num << ” “;

num += 2;

}

cout << endl;

3. What is the output from the following C++ code fragment if the following values are the inputs to cin?

38 35 71 14 -10

int sum, num;

cin >> sum;

for(int j = 1; j <= 3; j++)

{

cin >> num;

sum += num;

}

cout << “Sum = ” << sum << endl;

4.What is the output from the following C++ code fragment if the following values are the inputs to cin?

38 35 71 14 -1

int sum, num;

sum = 0;

cin >> num;

while(num != -1)

{

sum += num;

cin >> num;

}

cout << “Sum = ” << sum << endl;

5. Write a do – while loop to get 20 numbers from the user and sum them together. Output the sum after the loop. Declare any variables you need.

6.What is the output from the following C++ code fragment if the following values are the inputs to cin?

58 23 75 176 145 -999

int num;

cin >> num;

while(num != -999)

{

cout << num % 25 << ” “;

cin >> num;

}

cout << endl;

7.What is the output from the following C++ code fragment?

int count = 10;

while(count– > 0)

{

cout << count << ” “;

}

cout << endl;

8.What is the output from the following C++ code fragment?

int count = 1;

do

{

cout << count * (count – 1) << ” “;

}while(++count <=5);

cout << endl;

9. Given the following C++ code fragment, answer the questions that follow.

int s = 0;

for(int i = 0; i < 5; i++)

{

s = 2 * s + i;

}

a. What is the final value of s?

b. If the expression i++ was replaced with i += 2 what would be the final value of s?

c. If a semi-colon is added following the right parenthesis of the for statement, what would be the final value of s?

10. Write a for statement to add all the multiples of three between 1 and 100. (ie. 3, 6, 9, … 99).

11. How many times will the loop bodies execute in the following loops?

a. int x = 5, y = 50;

do

{

x += 10;

}while(x < y);

b. int x = 25, y = 5;

while(x >= y)

{

x -= 5;

}

c. int y = 0;

for(int x = 5; x < 100; x += 5)

{

y++;

}

d. int x = 10, y = 1000;

while(x <= y);

{

x *= 10;

}

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