100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COSC 1436 C++ Exam Questions with All Correct Answers $12.99   Add to cart

Exam (elaborations)

COSC 1436 C++ Exam Questions with All Correct Answers

 5 views  0 purchase
  • Course
  • COSC 1436 C++
  • Institution
  • COSC 1436 C++

COSC 1436 C++ Exam Questions with All Correct Answers Given an int variable count that has already been declared, write a for loop that prints the integers 50 through 1, separated by spaces. Use no variables other than count. - Answer-1. for(count=50;count>0;count--){ 2. cout<<count&...

[Show more]

Preview 2 out of 9  pages

  • August 29, 2024
  • 9
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • COSC 1436 C++
  • COSC 1436 C++
avatar-seller
Scholarsstudyguide
COSC 1436 C++ Exam Questions with
All Correct Answers
Given an int variable count that has already been declared, write a for loop that prints
the integers 50 through 1, separated by spaces. Use no variables other than count. -
Answer-1. for(count=50;count>0;count--){
2. cout<<count<<" ";
3. }

Write a statement that increments the value of the int variable total by the value of the
int variable amount. That is, add the value of amount to total and assign the result to
total. - Answer-total+=amount;

Given that two int variables, total and amount, have been declared, write a sequence of
statements that:
initializes total to 0
reads three values into amount, one at a time.
After each value is read in to amount, it is added to the value in total (that is, total is
incremented by the value in amount). - Answer-1. total=0;
2. for(int i=1;i<=3;i++)
3. {
4. cin>>amount;
5. total+=amount;
6. }

Given that two int variables, total and amount, have been declared, write a loop that
reads integers into amount and adds all the non-negative values into total. The loop
terminates when a value less than 0 is read into amount. Don't forget to initialize total to
0. - Answer-1. total=0;
2. do
3. {
4. cin>>amount;
5. if(amount>0)
6. total+=amount;
7. }
8. while(amount>=0);

Write a for loop that computes the following sum: 5+10+15+20+...+485+490+495+500.
The sum should be placed in a variable sum that has already been declared and
initialized to 0. In addition, there is another variable, num that has also been declared.
You must not use any other variables. - Answer-1. for(int num=1;num<=500;num++)
2. {

, 3. if((num%5)==0)
4. {
5. sum+=num;
6. }
7. }

Given int variables k and total that have already been declared, use a for loop to
compute the sum of the squares of the first 50 counting numbers, and store this value in
total. Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no
variables other than k and total. - Answer-1. total=0;f
2. for(k=1;k<=50;k++)
3. total+=k*k;

Given int variables k and total that have already been declared, use a while loop to
compute the sum of the squares of the first 50 counting numbers, and store this value in
total. Thus your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no
variables other than k and total. - Answer-1. total=0;
2. k=1;
3. while(k<=50)
4. {
5. total+=k*k;
6. k++;
7. }

Given an int variable n that has been initialized to a positive value and, in addition, int
variables k and total that have already been declared, use a do...while loop to compute
the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n
equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no
variables other than n, k, and total. - Answer-1. total=0;
2. k=0;
3. do
4. {
5. total+=k*k*k;
6. k++;
7. }while(k<=n);



Given an integer variable strawsOnCamel, write a statement that uses the auto-
increment operator to increase the value of that variable by 1. - Answer-
strawsOnCamel++;

Given an integer variable timer, write a statement that uses the auto-decrement
operator to decrease the value of that variable by 1. - Answer-timer--;

Consider this code: "int v = 20; --v; cout << v++;". What value is printed, what value is v
left with? - Answer-19 is printed, v ends up with 20

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller Scholarsstudyguide. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $12.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

62890 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$12.99
  • (0)
  Add to cart