Q1: Is add_salad supposed to be another function that we call from main? Q2: Can you give me any helpful hints on how to go about solving this because I've spent hours trying all sorts of methods but I have failed so far. Q3: How can I put a call-by-reference parameter into: double add_salad (char deliver, int n_person)? Q4: What is the proper way of writing inline function? Q5: What's wrong with my inline function? inline void add_tip (price) {return price *= 1.15;} Q6: I know that void shouldn't have a value to return...but if it does't...what does it do here? inline void add_tip (price) {return price *= 1.15;}
Q1: Is add_salad supposed to be another function that we call from main? A1: Yes. Look at the PA (Programming Assignments) handout, page 7 Step b) It lists the function declarations as: double add_salad(void); double add_salad(char deliver, int n_person = 10); Look at Step e). It talks about add_salad() in great detail. Look at HINTS at the bottom of the page. Step 4) and then Step 5).
Q2: Can you give me any helpful hints on how to go about solving this because I've spent hours trying all sorts of methods but I have failed so far. A2: How about your notes from lecture? Did you write down the information from the blackboard specifically on PA#5? This was about 20 minutes of explanation, pseudocode,and hints. You also want to see the Proctors for specific questions. Also office hours. Maybe look at another student's notes for PA#5.
Q3: How can I put a call-by-reference parameter into: double add_salad (char deliver, int n_person)? A3: PA#5 asks to use only reference types (call by reference parameter) only with "inline void add_tip(double & rprice);" Therefore NOT with "double add_salad (char deliver, int n_person = 10); You will have to pass parameters (call by value). With any of these function calls: salad_price = add_salad ( ans ); // default 10 persons salad_price = add_salad ( ans, num_person); Note: salad_price = add_salad ( ); // calls void add_salad(void); for 20 persons
Q4: What is the proper way of writing inline function. A4: Function declaration from PA handout, page 7, Step b) inline void add_tip ( double & rprice); To make it inline, just place keyword "inline" in front: a) If you have both function declaration and function definition OR b) If you have only a function definition placed before its call.
Q5: What's wrong with my inline function?: inline void add_tip (price) {return price *= 1.15;} A5: Remember, 1st line of function definition (header) is like the function declaration. inline void add_tip ( double & rprice) { ... }
Q6: I know that void shouldn't have a value to return...but if it does't...what does it do here? inline void add_tip (price) {return price *= 1.15;} A6: Right, void does not return a value, therefore the compiler complains because you told it NOT to save any space for a return value. So it didn't. AND now you are trying to return a value! Remember you are using a reference type parameter. It is an alias for your argument you passed to the function. Therefore, you passed in the price from main(). add_tip() is accessing the original value and returns NO value. Do all the same function body AND do *NOT* use the keyword "return".

HOME || Course Description || Course Outline || Lab Hours || FAQ || Midterm || Final