C++ PROGRAMMING
Question 1 (5) Write an overloaded function max that takes either two or three parameters of type double and returns the largest of them. Test your overloaded function in a program with the appropriate function calls and displays on the screen to demonstrate that the overloaded function works. Question 2 (5) Write a C++ program that includes a function to calculate the discount applicable on the price of an item. Your function should have three arguments: the price as a reference parameter to a double, the discount as a double value, and a bool to indicate if the discount is calculated as a percentage or a fixed amount. Call the parameter to indicate whether the discount is a fixed amount, or a percentage, fixed. When fixed is true, it will indicate that the discount is a fixed amount and when it is false, the discount is a percentage. Your function should calculate the discount and modify the price of the item accordingly. Your function should check that the discount is not negative and that the price does not drop to zero or below zero after applying the discount. Use the assert () function to ensure that the discount is not negative and that the price does not drop to zero or below zero once the discount is applied. Test you program with the following input, and submit the output for all the cases: 235.97 7.35 false 5430.55 120.00 true 856.00 -12.5 false 120.00 130.00 true NB: Note that you are expected to use the assert macro in this question.
C++ PROGRAMMING
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am