Collaboration on this lab exercise is strongly ENCOURAGED. The exercise is intended for practice, not assessment -- most people who try should get all participation points. Feel free to ask for help from, and provide help to, others. You shouldn't blindly copy solutions from one another (or from anywhere else) nor simply write code for someone else (even if you explain it as you write), but you can certainly help each other debug, give plenty of suggestions and hints, **explain** why things work or don't work, etc. If you get done early, feel free to walk around and help others.
Lab Practical Exam 1: Functions and Control Flow (while and if-else statements)
Choose a partner to work with on this lab
With your partner, define a structure of type Product. The member variables should be code (int), wholesale_price (double), retail_price (double), number (int), and reorder_val (int).
Also with your partner discuss the pre and post-conditions for the following two functions. Then one partner should write the first function, initProduct, and the other partner should write the second function, outputProduct.
Write the definition of an initiation function:
void initProduct(Product& new_product)
This function should initialize all member variables of the passed Product object.
The function should prompt the user for the product code, the wholesale price, the number in stock, and the reorder value for this product.
The function should only allow the user to enter values between 1000 and 9999 for the product code.
All products have a 10% markup, so the function should calculate the retail price as 1.1 times the wholesale price.
Write a driver program to test this function.
Write the definition of an output function:
void outputProduct(Product new_product)
This function should output your Product information in the following format:
code W cost R cost # in stock Reorder # ---- -------- -------- ---------- --------- 1111 $ 10.00 $ 11.00 15 50 2222 $ 100.00 $ 110.00 100 10 3333 $ 5.00 $ 5.50 12000 100
Your output function should just output one Product object. So, the preceding example would need 3 calls to this function to output the 3 products (1111, 2222, 3333). So, the column headings would need to be output before these function calls. You could do this with a function that just outputs the heading.
Write a driver program that uses a stub for the initProduct function to test this output function.
Once the two functions have been tested and you feel confident they work correctly, you and your partner should now work on the main together that uses their function along with your function. If you get done testing your function before your partner, you should help them finish testing their function before starting on the main function.
Your program should prompt the user to enter info for 3 products. Then output the inventory in the above format. That means for this part you will declare 3 objects of type Product.
Modify your program so that it allows the user to enter as many products as they want and make it print the output to a file (inventory.dat) instead of the screen. That means you will only declare one object of type Product and put your functions in a do-while loop that asks the user if they want to continue.
Please feel free to help your fellow labmates reach this point!!
The following exercises are for your own benefit. You are not required to do these. In fact, they may contain material not covered in class or lab yet. As such, the TAs will give priority to helping students on the previous sections.
Challenge 1: