CIS 1033 - Fundamentals of Programming

Bob Comer, Professor, CIS/CSC


Chapter 5 Homework
Due Wednesday, June 23

Click here for answers.

  1. What does the following loop print?:
  2. int count;
    
    count = 1;
    while (count <= 10)
    {
       count = count + 1;
       cout << count << ' ';
    }
  3. Rearrange the order of the statements in the loop in question 1 so that it prints the integers 1 through 10. Do not rewrite any of the code.
  4. When the following code is inserted in a program and executed, it reads the first price and then the computer "hangs". Find the problem and correct it.
  5. int quantity;
    float price, cost;
    
    cout << "Enter item price (or -1 to quit): ";
    cin >> price;
    while (price > 0);
    {
       cout << "Enter quantity for this item: ";
       cin >> quantity;
       cout << endl;
       cost = price * quantity;
       cout << "The cost for " << quantity
            << " items at " << price
            << " each is " << cost
            << endl;
       cout << "Enter item price (or -1 to quit): ";
       cin >> price;
    }
  6. The following segment of code is supposed to print the odd integers between 0 and 10. It has 2 errors in it. What is the output of the code as written? Rewrite the code to correct the errors.
  7. int num;
    
    num = 1;
    while (num != 10)
    {
       num = num + 2;
       cout << num << ' ';
    }
  8. Write C++ code to read 20 integers and count how many times the integer 100 appears in the input. You must use a loop.
  9. Write a loop that sums the integers from 1 through 10.
  10. Write a loop that reads a list of integers from the keyboard and counts how many negative integers are input and how many positive integers are input. The loop should stop when zero is input. Then print the count of negative numbers and the count of positive numbers with appropriate labels.


Return to Fundamentals Home Page

URL: http://www.austin.cc.tx.us/comer/cis1033/
Copyright: Ó 1999 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to: Bob Comer
Last updated: March 2, 1999

Austin Community College is an equal opportunity educator and employer.