In today's studio you will explore how operators and functions can be used
to compare and modify the state of variables, using the enumerated types
you implemented in Studio 2 as an example. Specifically,
you will: (1) validate how different expressions behave with respect to the
relative precedence of the operators you declared and defined for those types;
(2) demonstrate that (without declaring or defining a specific version of it
for those types) the less-than operator (operator<) that is already
pre-defined for integer types can be used with your enumerated types due to
implicit type conversion; and (3) use algorithms, associative containers, and
iterators already provided by the standard library to compute the union and
intersection of sets of those enumerated types.
Please complete the following required exercises. I encourage you to please work in groups of 2 or 3 people on each studio (and the groups are allowed to change from studio to studio) though if you would prefer to complete any studio by yourself that is also allowed.
As you work through these exercises, please record your answers, and when
you finish them please log into Canvas, select this course in this semester, and
then upload a .txt file containing your answers on the Canvas page
for this studio assignment. Only one submission per team, please, and if
you need to re-submit it the person who originally submitted the studio should
please be the one to do that.
Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.
First, ssh into shell.cec.wustl.edu using your WUSTL
Key id and password and then use qlogin to log into one
of the Linux Lab machines and then confirm that the version of g++
there is correct (as you did in Studio 0). Then
cd into your directory for this course this semester, create a new
subdirectory for this studio, and cd into it.
Copy over the header (.h) and source (.cpp) files
where you declared and defined (respectively) the Pressure type
for Studio 2, into your directory for this studio.
Define a main function for your program, and in it declare a variable of the
Pressure enumerated type that is initialized to one of
the enumerated values. You should then write statements involving expressions
that use both the shift operator (with cout) and the (prefix)
increment operator you wrote for that type in Studio 2, which can demonstrate
which of those operators has higher precedence.
Compile and run your program, and as the answer to this exercise please show (1) the code you wrote for this exercise and (2) the output your program produced by running it, and explain briefly (3) which of the operators has higher precedence and (4) why that is shown by the output the code produced.
Copy over the header (.h) and source (.cpp) files
where you declared and defined (respectively) the Weekday type
for Studio 2, into your directory for this studio.
In the main function for your program declare additional variables of the
Pressure and Weekday enumerated types, which are
initialized to different enumerated values than the ones you had declared
previously. Without writing a specific less-than operator (operator<)
for either of those types, you should then write statements involving those
variables in expressions that use the less-than operator (operator<)
that is already provided in C++ (for integer variables), and print output
(to cout) that demonstrates that the operator works correctly
for comparisons of Pressure variables and for comparisons of
Weekday variables.
Compile and run your program, and as the answer to this exercise please show (1) the code you wrote for this exercise and (2) the output your program produced by running it, and explain briefly (3) why what is shown by the output the code produced reflects correct behavior of the operator in each case.
At the top of the source file for your main program (or in a header file that
it includes), include the standard <set> library header file.
In your main program declare two set associative container objects
for Weekday values and initialize them with (or insert into them)
different values from that enumerated type. Then iterate through each container
and print out the different values that each of them contains.
Compile and run your program, and as the answer to this exercise please show (1) the code you wrote for this exercise and (2) the output your program produced by running it.
At the top of the source file for your main program (or in a header file that
it includes), include the standard <algorithm> and
<iterator> library header files. In your main program declare
one more associative container object, for another set of
Weekday values.
Then, call the standard set_intersection function template
(from the <algorithm> library)
with begin() and end()
iterators for the set objects from the previous exercise, and a
standard inserter that is initialized with the set
object you declared for this exercise and that object's end() iterator.
Then, iterate through the set object you declared for this exercise
and print out the values that it contains (which should be the intersection of
the other two sets).
Compile and run your program, and as the answer to this exercise please show (1) the code you wrote for this exercise and (2) the output your program produced by running it.
In your main program declare another associative container
object for a different set of Weekday values.
Then, call the standard set_union function template
(from the <algorithm> library)
with begin() and end()
iterators for the original set objects, and a
standard inserter that is initialized with the set
object you declared for this exercise and that object's end() iterator.
Then, iterate through the set object you declared for this exercise
and print out the values that it contains (which should be the union of
the other two sets).
Compile and run your program, and as the answer to this exercise please show (1) the code you wrote for this exercise and (2) the output your program produced by running it.
For this studio, please turn in the following: