While it is crucial to write clean and error-free code during the examination, we understand that minor syntax errors, such as missing semicolons or other similar issues, may occur. Therefore, we want to reassure you that these syntax errors will not heavily impact your grading.
Write a program that has a base class named Quad. This class should have four member data variables (floats) representing side lenghts and a virtual function Area, which just returns 0. It should also have a method for setting the data variables. Derive a class Rectangle from Quad and override the Area method so that it returns the area of the Rectangle. Write a main function that creates a variable of type pointer to Rectangle and assigns a Rectangle to it which is created on the heap. Set the side lengths to some positive values, which actually form a rectangle. Use the Area function to calculate the size of the rectangle and print this out.
Do you see any issues with the modelling of the rectangle? If so, suggest improvements to the rectangle class which overcome the problem.
Short questions (perhaps I will ask this as multiple choice):
- What is the difference between i++ and ++i ?
- What is the difference between public , private and protected class access rights ?
- How do the same access rights work if the class also has a superclass with some kind of access rights? (Which functions are visible and what are not?)
- What is the syntax for documenting a Doxygen function?
- What does the life cycle of an object look like (when is the constructor called , when is the destructor called, what happens in between?)
- How to get elements from an array ?
- How do you get elements from an array of pointers ?
- How do you get the nth element when the array contains only pointers?
- What is the difference between a pointer and a reference and how do they work in the context of classes. (How to access variables/methods?)
- The nature of the delete command, when to delete and when to delete .