CSE 701 Practice Test 2: Chapters 4-5 McMaster University, Fall 2024 |
Table of contents |
Instructions ^You have 1 hour to solve the exam. The only allowed material is the course lecture notes. You are not allowed to write anything on the printed notes or modify them in any way before or after printing, but you can use a highlighter. Computers, phones, tablets, and other digital devices cannot be used during the exam. |
Introduction ^We are going to write a C++ class The class has three constructors:
Note that a rectangle has 4 sides, but we only need to store 2 values, since the top and bottom sides are both equal to The class has four member functions:
The class also has one friend function:
Finally, the class has two related external functions:
In each part of the test, please make sure to use correct syntax and to closely follow all the guidelines we learned in class! |
Part 1: Setter function (20 points) ^The class is encapsulated, meaning that the user cannot set the private
If any of the invariants are not satisfied, Write down the code for the |
Part 2: Constructors (15 points) ^Write down the code for the three constructors, ensuring that the class invariants are checked upon construction. |
Part 3: Getter functions (10 points) ^Write down the |
Part 4: Insertion operator (15 points) ^Write down the |
Part 5: Scaling operators (20 points) ^Write down the |
Part 6: Test program (20 points) ^Write down the Your test program should do the following:
The output of your program is expected to be exactly as follows: |
Note for the practice test ^The real test will be very similar to the practice test. You will also be asked to create a class according to specified parameters. It is highly recommended to solve the practice exam on paper, so you can get used to writing code on paper. However, once you are done you should copy your code to a computer and make sure it compiles and the test program produces the expected output. |