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:
Implement (4-8) twice, first using a while loop and then a for loop:
2 4 6 8 10 12
int number;
number = 1;
while (number < 11)
{
number = number + 1;
cout << number << endl;
}
int number;
bool done;
number = 2;
done = FALSE;
while (!done)
{
number = number * 2;
if (number > 12)
done = TRUE;
cout << number << endl;
}
int sum, num;
sum = 0;
infile >> num;
while (infile)
{
if (num % 2 == 0)
sum = sum + num;
infile >> num;
}
cout << sum << endl;
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;