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).
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.
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
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.
A5: Remember, 1st line of function definition (header) is like the function
declaration.
inline void add_tip ( double & rprice)
{ ... }
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".
A8: POINTERS
1) Look at PA handout, page 6
2) Used ONLY in calc_price();
3) Function declaration, Step b)
void calc_price( double *p_price, int n_person);
4) Function call, Step d)
calc_price( &my_price, num_person);
5) Function definition
void calc_price( double *p_price, int n_person)
{
*p_price += 3.98; ... // Through pointer, change my_price in main()
}
A9: REFERENCE TYPES
1) Used ONLY in add_tip();
2) inline used ONLY in add_tip();
3a) IF ONLY a function definition
inline void add_tip(double &rprice){rprice=...;} // change my_price in main()
3b) IF a function definition AND function declaration
inline void add_tip(double &rprice); // function declaration
inline void add_tip(double &rprice){rprice=...;} // function definition
