Dailyhomework: DO NOT TURN ANYTHING IN, simply do for your own learning. Some new notes: Problem made up in class on March 29: Assume you are given: struct MenuItem { int itemID; float cost; }; struct CustomerRequest { int itemID; int quant; float totalBill; }; Write only a function ComputeBill which takes one struct MenuItem and another struct CustomerRequest if the items in both agree, it will compute the total cost and fill up the unfilled field in CustomerRequest and return this complted struct via the functions name. if this is being done a flag which was passed by adress to the function must be set to 1. Do as much as you can before the end of March 24 ================================================ 23.1) Begin to work on Assignment 4 (Update 19). Here are some suggested steps for finishing it. 1) Write a starting program that will read in the information from the input file. Show yourself that reading is being done correctly by printing out the values that you are reading in (print simply to the screen, not to another file). For this step to work correctly, you will need to set up multiple FOR-loops. 2) Store the quantities that are read in in Step 1, store them as needed by the assignment. Read the assignment carefully to create the correct data structures (array of structs), then store the quantities, and then print from these structures. 3) For each day's entry from the file, now compute the actual time worked that day. Devise a correct formula for this step, print out the actual time worked each time and see if it correct. 4) Then start to enter the time worked in the array of structs, and continue to implement the logic of taxation and so on. 23.2) Remember that in Test 4, there will be 3 questions: a structure/function question, a files question, and finally a question related to linked lists which we will study as our next topic in class. Do as much as you can before the end of March 10 ================================================ 22.1) Today we are going to study how to use files for input and output. We will look at Update 19 to understand the steps needed to work with files. The example problem used will be Question 10 from Prac Test 4 (Update 17). 22.2) Look at Question 10 about files on Prac Test 4 (Update 17). Go through the steps in Update 18 to solve it. 22.3) This files question is important both to students barely trying to scrape a passing grade of C, and to those trying to get an A. Both groups MUST get this question perfectly perfect on the final exam. So, definitely try hard to study for this before Test Four, and use Test Four as a means to see how good you are, and what additional studying you need to do to get this question perfectly finished on the final exam. Do as much as you can before the end of March 7 =============================================== 21.1) Examine structure/function questions from Practice Test FOUR. Repeat review the solution to Question 4a. Then study the solution to Question 4B. It is employing pass-by-address parameters. 21.2) Work on Question 6 of Practice Test FOUR. Do as much as you can before the end of March 5 =============================================== 20.1) This will prepare for the structure-function question on Test FOUR. Notes on how to do the questions on passing structures to functions (Test 4) Step 1) write the function name (typically f, or some given required name) Step 2) write a blank underscore to the left of this name Step 3) put a pair of parens (with lots of space in between), to the right of the function name Step 4) read the question carefully to determine how many parameters are needed; put that number minus one, number of commas in parens. Eg. if four params are needed, then use 3 commas. Step 5) carefully put each param in with its type. The type always precedes the variable name. Types can be such as int, char, float, int*, or struct gas. Note that if it is a struct, then it needs both words: struct and the required name for that struct. This requirement to say both words is only if the struct is defined in the way shown in class, this would not be used if using typedef. Step 6) carefully figure out if any of the params are pass by value or pass by reference (pass by reference is also sometimes called the address of something). Step 7) read carefully several times to ensure that the function header line is completed correctly. Step 8) Put a pair of open-close braces (with many lines in between them) to contain the function code. Step 9) declare any obviously needed local variables Step 10) start to write up the logic that is needed to access the struct components and manipulate any data (such as, filling in new struct components of local variables, or pass by reference params). Ensure that components are accessed by using the period between the variable and the component, e.g., a.part or (*a).part (which could/should be written as a->part) Step 11) carefully read the instructions to see what is to be returned and under what logic e.g., return 1, or return 0, or return a (where a is a struct) Step 12) when you know the type of what is being returned (only one such type can exist in the function) write that type in for note 2 (the blank underscore that is to the left of the function name). Step 13) if nothing is to be returned by the return statement, then do not put any return statements, and write void in the place for note 12. Do as much as you can before the end of March 3 =============================================== 19.1) Test 3 will have 4 questions. The fourth is similar to Prac Test 3 Question 13. The third is similar to Prac Test 3 Question 12. The second is a mixture of the skills in Prac Test 3 Question 4, Program ptr6.c (at Update 14), and Programs ptr1.c and ptr2.c at Update 15. The first is based on ptr5.c at Update 14, but it will involve more variables and their pointers. These topics are also covered in Labs 6, 7, and 8. 19.2) Today, we will start a new topic, Structs. We start working on Chapters 24 and 25 of the Lectures. STRUCTS are extremely important to the future work you will do in this class and in the next class for majors (Computer Science One). Different from arrays (which collect data of the same type), a struct holds data together that is held together by some concept that we humans want to keep the parts of that concept together. To prepare for this question of Test Four, we will spend two weeks of Lectures, and Lab 9. Do as much as you can before the end of February 27 =================================================== 18.1) For the foodbank program, try to complete option One and option Four. Then, later, start option Two. Here is how to proceed: If you do not know how to start the food-bank program, do the following steps: Step 1: start with bankinclass.c (Lectures website, see Chapter 7) or start from assign 2 Part C Step 2: Gut (remove) the contents of each option Step 3: compile to ensure no damage during surgery (Make sure code is compilable. Repeat Step 2 and 3 till success) Step 4: Now copy daily homework 17.2 into option 1 of your program, after making all the code be "cleaned up" Step 4.1 for the comment line that says "prompt", put in REAL CODE Step 5: Now declare everything to make option 1 work i.e., must compile Step 5.1: Copy 2 array declarations from the assign 3 instruction sheet. Make up the 3rd array "char word[20];" Step 5.2: Declare don_count, don_quant, found, i; Step 5.3: Run it. Put stuff in as input, example: milk 20 Step 6: Put in part of Option 4 from 17.3 Step 7: Then RUN with: 1 MILK 20 1 EGGS 30 1 MILK 14 4 1 EGGS 7 1 MILK 13 4 Step 8: Fix anything that does not work perfectly. Do not proceed to option 2 or option 3 till these 8 steps have been completed. 18.2) Food Bank, Option 2 is simply an easier version of option 1, you only always need to put the new entry in the Req_Inv_Type table, and the amount in Req_Amount Table. This means you do not need to search for the word in the Request Table. 18.3) Food Bank, Option 3 is: if (choice==3) { if (req_count == 0) { message 1 : No hunger } else if (don_count == 0) { message 2 : Scrooges in this town } else { // request does not find a match in donations found = -99; for (i=0; ireq_amt[0]) { don_amt[found] -= req_amt[0]; //reduce the donat ion table's amount; //remove the request as above for (i=1;i int main(void) { int i, start=3, days=31, p; for (i=1; i16;i--)" runs 10 times. 4.8) Let us focus on Practice Test One's Question 4. Its solution involves first writing a for loop that runs 50 times. So, as your first step, write for (i=0;i<50;i++) Then, you are told that the loop must read in 50 numbers: So, Write: for (i=0;i<50;i++) { scanf("%d", &NumFromKeyboard); } Note how you must get to the point where you are comfortable writing a simple for-loop as above, based on the problem sheet. Now that you have the 50 numbers coming in, one at a time, each one of them being temporarily available in NumFromKeyboard, you can examine each one immediately after the scanf. The problem sheet tells us to check to see if the number is greater than 100. So, our next step is to expand the code to: for (i=0;i<50;i++) { scanf("%d", &NumFromKeyboard); if (NumFromKeyboard > 100) ... } The ... should be replaced by whatever we are being asked to do. We are being asked to add each number into an adder that will tally up these big numbers. The tally needs to be initialized to zero (per the problem sheet). So, our next step is: sum = 0; for (i=0;i<50;i++) { scanf("%d", &NumFromKeyboard); if (NumFromKeyboard > 100) sum += NumFromKeyboard; } Finally, we incorporate the requirement that the tally gets multiplied by 85. We get: sum=0; for (i=0;i<50;i++) { scanf("%d", &NumFromKeyboard); if (NumFromKeyboard > 100) sum += NumFromKeyboard; } sum *=85; printf("%d", sum); To wrap up, we merely need to declare all our variables, and put the starting lines (#include, etc.) and the ending lines (return zero, etc.). Do as much as you can of all this before the end of January 16 ============================================================== 3.1) Ensure that you complete the submission of Assignment Zero before Friday night. (See Update 2 on the class webpage). 3.2) Read Chapter 5's sections Conditional Expressions, if-else Construct (Note that the author of Lectures webpage may have an error, so you need to change .pdf to .doc, if needed) 3.3) Practice Test One (see Update 3 on class page). Do Question 1. These are all you must know for Test One Question 1. = += ++ 8%3 %3d %7.4f scanf printf ("P=_%7d ... do not ignore the single _ int/int gives truncated answer %M.Pf means *** . -------- \ P / \ P+1 / \ D / 1. P spaces after . 2. then P+1 for the . 3. then put in the quant that goes before . 4. Then, count up all used, say D 5. if D