CSE 333 24su Exercise 8
Due: Wednesday, July 10th, 2024 by 10:00 am; No
late exercises accepted.
Goals: Write a small procedural (no
classes or objects) C++ program from scratch,
learn the basics of C++ stream I/O,
and learn to use the cpplint
style checker for C++ code.
Description:
Write a C++ program that:
- Prompts the user for a positive integer (strictly >0)
- Prints out all integers that are factors of that integer;
feel free to used the simplest, brute-force factorization
algorithm you can think of (hint:
n%k==0
),
and you should print each
factor only once, in ascending order.
For example, if the user enters the number 100,
the interaction with the terminal should look like:
bash$ ./ex8
Which positive integer would you like me to factorize? 100
1 2 4 5 10 20 25 50 100
- Uses
std::cin
to read from the terminal and
std::cout
to write to the terminal
- Exits with an appropriate error code once it has processed
the user's input; there is no need to loop until they are "done".
As usual, your code must:
- Compile without errors or warnings on CSE Linux machines
(lab workstations, attu, or CSE home VM)
g++ -Wall -g -std=c++17 -o ex8 ex8.cc
-- do not
submit a Makefile
.
- Have no crashes, memory leaks, or memory errors on CSE linux
machines. (Suggestion:
valgrind
)
- Be contained in a single file called
ex8.cc
that compiles with the command g++ -Wall -g -std=c++17 -o ex8 ex8.cc
; do
not submit a Makefile.
- Follow the quality guidelines we covered in class, including
the formatting, modularization, variable and function names, and so on.
If in doubt, follow the Google C++ style guide.
We suggest using
cpplint
, but without the
--clint
option, which is for C code.
Note: cpplint warns about some issues that can be ignored for our
purposes, although it is unlikely to report any for this exercise.
Be sure that you understand (1) any warnings that remain and (2)
other deviations from the Google C++ Style Guide; you should be
able to explain why they do not present a problem. The class discussion
group is a good place for questions and discussion about these issues.
(For example: you may have a using namespace
directive in
your code if you don't want to write std::
everywhere for short exercises like this).
- Be robust: you should think about handling bogus input
from the user (if any), and you should handle hard-to-handle cases
(if there are any) gracefully.
- Have a comment at the top of each source file with your name,
and CSE or UW email address.
You should submit your exercise to the course Gradescope.