QA 4
Q1: Do we need to consider situation where there are two lowest unit prices? Q2: Do we need to cout the total with delivery as well as without delivery? Q3: How do I compare and find the min of four unit prices? Q4: How do I write comments for a function? Q5: Do I need comments at the declaration too? Q6: Can I return a void instead in: double add_tip (double total_price)? Q7: If the user wants to order another pizza, does the current total need zeroed out or added to the new total? ------------------------------------------------------------------------------- Q1: Do we need to consider situation where there are two lowest unit prices? A1: No, your 1st cheaper comparison will assign to best_price the current unit_price. If this is .07 then the next comparison will NOT be cheaper, therefore it will be the first cheapest. ------------------------------------------------------------------------------- Q2: Do we need to cout the total with delivery as well as without delivery? A2: Yes need to print total, Only print word "delivery" if chosen. ------------------------------------------------------------------------------- Q3: How do I compare and find the min of four unit prices? A3: As in lecture, we said: a) min gets assigned the first unit price for pizza A calling, best_deal() b) Then loop thru calling best_deal() for other pizzas B, C, D c) Test in loop whether cheaper. If true, assign the new unit price to min ------------------------------------------------------------------------------- Q4: How do I write comments for a function? A4: Please refer to the CSE 9A Lab Guide, last page for a sample of a "commented" good style program. Notice that above each function definition is a comment explaining its task. e.g. // void show_menu(double, double, double, double) // Displays the choice of pizza (A-D) with the corresponding diameter, // and the input prices. The input prices are passed .... void show_menu(double, double, double, double) { ... } ------------------------------------------------------------------------------- Q5: Do I need comments at the declaration too? A5: Detailed comments above the function definition and a 1 liner comment at declaration should do it. e.g. // Display menu price & choices void show_menu(double prA, double prB, double prC, double prD); ------------------------------------------------------------------------------- Q6: Can I return a void instead in double add_tip (double total_price); ? A6: Use the function declarations as they are given to you, PA#4 is based on learning functions, return values, and "pass by value". Returning a double helps, because using "pass by reference" in PA#5, things will change! ------------------------------------------------------------------------------- Q7: If the user wants to order another pizza, does the current total need zeroed out or added to the new total? A7: No initialization of total to zero. Please notice the sample output. The first amount of $10.98 PLUS $15.98 is a total of $26.96 + 15% tip --> $31.00 (We did this in class) -------------------------------------------------------------------------------