Each exercise this quarter is rated on a integer scale of 1 – 5, inclusive, with 1 being the "least time-consuming" and 5 being the "most time-consuming".
This difficulty scale is meant as a rough guide for you in predicting the amount of time to set aside for each exercise as you balance the work required for 333 with your other obligations. However, it is necessarily imperfect as everyone's set of circumstances and experiences with the exercises differ. If your experience with an exercise does not align with its rating, that is not a reflection of you or your abilities.
As discussed in lecture, C++ and C have a lot of similarities, yet can be different in a lot of ways. In this exercise, you will write your first C++ program from scratch that, like Exercise 1, parses user input to perform some arithmetic computation. We want you to compare your experience with this exercise and Exercise 1 to see some of the similarities and differences between C and C++.
Write a C++ program that:
For example, when we run our exercise and the user inputs the number 100, the interaction with the terminal should look like:
$ ./ex5 Which positive integer would you like me to factorize? 100 1 2 4 5 10 20 25 50 100 $
You should use the iostream library to read user input
from the terminal and to write to the terminal.
Specifically, you should investigate using std::cin,
std::cout, and std::cerr.
You can find more information by looking at
.
Since you will be reading in user input from stdin, you
should make sure your code handles various inputs from the user,
which may be in an unexpected format.
For this exercise, you should investigate to see how
std::cin parses input and checks for errors, and then
make sure your code utilizes this error checking for bad input.
Once you detect a bad input, please print out useful error message
and exit from the program –
do NOT try to loop and prompt the user again.
In general, write C++-style code when possible.
For example, although both printf and
std::cout can achieve the task of writing to the
terminal, you should use std::cout since this is a
C++ program.
cpplint
Since we are now dealing with C++ instead of C, you should no
longer use the --clint flag with
cpplint.py so that it does the proper checks for C++.
You may see some new warnings, so be sure to fix these as well!
Make sure that if you use any using directives, that
you list out each individual object/function you use, and not an
entire namespace.
In other words, do NOT use using namespace std;,
instead list out everything you are using from that namespace with
lines like: using std::cout;.
Submit the following file(s) by creating an ex5-submit tag in your exercise repo before the assignment deadline. The file(s) should be located in the exact directory listed below (there should be a folder titled ex5 with the ex5.cc files within that folder), including capitalization:
ex5/ex5.ccFor full credit, your code must:
attu, or CSE home VM).g++ and valgrind).$ g++ -Wall -g -std=c++17 -o ex5 ex5.cc
.cc file with
your name(s) and CSE or UW email address(es).cpplint.py).