CMSC 160
Fall 2018
10/11/2018
More with Loops
Due:  Fri, Oct 12
8am


Assignment:    (7 points)

These programs are individual assignments.
Remember that these programs should have a comment at the top of the file stating your name and what the program does.

yellow bar separator

0)   Get the file   sentinel.cpp   from the server.   Run it and see what it does.   Does it work as the comment indicates?  (Hint:  no)
  1. understand why the program does not work.
  2. modify the program so that it reports the right answer for the total
  3. modify the program so that it also reports the number of classrooms that collected over 50 boxtops.
  4. modify the program so that it also reports the maximum number of boxtops collected by a classroom.
  5. modify the program so that it also reports the average number of boxtops collected by classrooms.

End result:  the program should read in integers from the user until they type a negative number.   The program should then report:
  • the total boxtops
  • the number of classrooms that collected over 50
  • the largest number of boxtops collected by a classroom
  • the average number of boxtops collected
Handin:
handin  cmsc160   labboxtops  sentinel.cpp

yellow bar separator

1)    A population of animals currently has 5000.   Projections are that the population will increase at 4% a year.     How long will it take for the population to double in size?
Write a program that determines and reports the answer to this question.

Handin:
handin  cmsc160   labpopulation  yourfilename.cpp

yellow bar separator
2)  
For each of the following snippets:
  1. Try to predict what it does
  2. Type the code in to a program, run it and see if you were right.
  3. If you were wrong, understand what happened.  Ask questions as necessary.

1 for (int x = 0; x < 5 ; x++)
    cout << "LAB" ;
for (int x = 0; x < 5 ; x++)
    cout << x;
    cout << "LAB" ;
for (int x = 0; x < 5 ; x++)
{
    cout << x;
    cout << "LAB" ;
}
2 int a;
int b = 20;
for ( a = 11; a < b; a++)
{
    cout << "Great Lab" << endl;
    if (b > 18)
        b = b - 1;
    cout << a << "  " << b << endl;
}
cout << a << "  " << b << endl;
for (int x = 0; x < 5 ; x++)
{
    cout << "LAB" ;
}
cout << x;
for (int i = 10; i >0; i--)
    cout << i << endl;