COSC175 Loop HW- Work with One Partner

Type in Word. Work with a partner and submit one copy per pair.


Partner 1: Name _______________________________


Partner 2: Name _______________________________




Write c++ statements for each of the following:

  1. Write the statements that allow you to input a series of numbers and print whether they are odd or even. Entering 0 causes the program to quit.
  2. Write the statements to input numeric exam scores from a file and output the appropriate letter grades.
  3. Write a loop that will continuously input and print the names of contest participants, until QUIT is entered in place of the name.


Implement (4-8) twice, first using a while loop and then a for loop:

  1. Write code to print Towson University 10 times.
  2. Write code to print the numbers from 1 to 10.
  3. Write code to print the numbers from 10 to 1.
  4. Write code to print the following numbers:

2 4 6 8 10 12

  1. Write code that prints your name 5 times.


  1. Write code that will input a number and print the number, the square of the number, and the cube of the number. Continue the operation until 999 is entered.
  2. Write code that will request the length and width of a rectangle until 0 is entered for either the length or the width. Print the area and perimeter for each set of inputs.
  3. Write code that reads in integers from a file and then counts and prints out the number of positive integers and negative integers. If a value is zero, it should not be counted. The process should continue until end-of-file occurs.





  1. What is the output for the following loop?

int number;

number = 1;

while (number < 11)


    number = number + 1;

    cout << number << endl;




  1. What is the output for the following loop?

int number;

bool done;

number = 2;

done = FALSE;

while (!done)


    number = number * 2;

    if (number > 12)

        done = TRUE;

    cout << number << endl;


  1. What is the output of the following if the file contains: 2 3 4 5 6 7

int sum, num;

sum = 0;

infile >> num;

while (infile)


   if (num % 2 == 0)

            sum = sum + num;

    infile >> num;


cout <<  sum << endl;



  1. Write a program that prints out the sequence of all the hour and minute combinations in a day, starting with 1:00 and ending at 12:59.










Write the complete code and perform 3 traces. Pick good test data.

16.   Design an algorithm that will prompt for, receive, and total a collection of payroll amounts entered from the user until a sentinel amount of 999 is entered. After the sentinel has been entered, display the total payroll amount to the screen.


17.   Design an algorithm that will read a series of integers from the user. The first integer is special, as it indicates how many integers will follow. Your algorithm is to calculate the sum and average of the integers (excluding the first) and display these values to the screen.


18.   Design an algorithm that will prompt for and receive the measurement for the diameter of a circle and calculate and display the area and circumference of the circle. Your program is to continue processing until the sentinel of 9999 is entered.


19.   A file of student records contains name, gender (M or F), age, in years, and marital status (single or married) for each student. Design an algorithm that will read through the file and calculate the numbers of married men, single men, married women and single women. In addition, for each single man under 30, display "Bachelor".


The input statement looks like:    infile >> name >> gender >> age >> maritalStatus;