Name: ____________________________________________________ Alpha:
_____________Section: ________
Describe help received: _________________________________________________________________
See the bottom for how to submit your work.
Due: Before 0800 on next class day
- (10 pts) Read lecture notes for today. Honestly declare
how you read the notes.
- (10 pts) I read the notes carefully. I have a good understanding of the topics therein.
- (10 pts) I read the notes carefully, but I don't really understand the following points well:
- (0 pts) I didn't read the notes carefully.
- [10pts] Consider the following program, which is supposed to compute
the sum of the integers from 1 to 10.
#include <iostream>
using namespace std;
int main()
{
int i = 1;
while(i <= 10)
{
int sum = 0;
sum = sum + i;
}
cout << sum << endl;
return 0;
}
|
- The program doesn't compile. What kind of error messages will you get from
the compiler?
- Annotate the above code fix this
error (and any other errors)
so that the program both compiles and works properly.
|
- [10pts] Consider the following program. What will be the output? Try to
solve it manually instead of compiling and running the code. We will ask
this kind of question in the exam.
int a = 1, b = 2;
while(a <= 10)
{
if( a % 2 )
{
a = a + b;
b = b + 2;
}
else
{
a = a + 1;
b = b - 1;
}
cout << a << " " << b << endl;
}
| output:
|
- [70pts]
Write a program that reads four integers
s, e, a, b from the user.
The program must print out every number that satisfies the following conditions
at the same time:
- The printed number must be at least
s.
- The printed number must be at most
e.
- The printed number must be a multiple of
a.
- The printed number must be a multiple of
b.
The program should print these numbers in increasing order.
Note: your source code must use a while loop.
Example of running your program:
$ ./hw
Enter four integers: 10 102 4 6
12 24 36 48 60 72 84 96
$ ./hw
Enter four integers: 9 100 3 9
9 18 27 36 45 54 63 72 81 90 99
$ ./hw
Enter four integers: 1000 1500 30 21
1050 1260 1470
Turn in (Due: 0800 on the next class day)
- Written portion: Print out this homework assignment and
annotate your answers to the written portion. Turn in the hardcopy in class.
- Programming portion: