Do this by the end of Mar 5, 2023 ================================= 21.1) Start working on Chapters 24 and 25 or 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). 21.2) For Practice Test 4, start Question 4. Use the rules in Dailyhomework 21.3 (below). 21.3) This will prepare for a question on the 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 th e 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 this by the end of Mar 2, 2023 ================================= 20.1) Do ptr5.c, ptr6.c (from Update 15), review ptr1.c, ptr2.c (from Update 16). 20.2) Look at Question 10 about files on Prac Test 4 (Update 18). Go through the steps in Update 19 to solve it. Do this by the end of Feb 28, 2023 ================================== 19.1) Test 3 will have 4 questions. One is similar to Prac Test 3 Question 12. The second is similar to Prac Test 3 Question 13. The third and fourth are from a mixture of the skills in Prac Test 3 Questions 3 and 4, as well as from the class's webpage Update 15, Programs ptr5.c and ptr6.c, and Update 16, Programs ptr1.c and ptr2.c. These topics are also covered in Labs 6 (week of Feb 22), 7 (week of Mar 1), and 8 (week just before Spring Break). 19.2) Continue to work on the Required Assignment Three (FoodBank). Look back at the DailyHomework notes 13.2, 13.3, 13.4, 13.5, 14.2, 14.3. Do this by the end of Feb 26, 2023 ================================== 18.1) Last class and in the Labs in the next 8 days (Lab 7), we did (and will do) the case of functions that have simple variables as their parameters (that is, no And symbol). These are examples Question 6, 9 and 12 of Practice Test Three. 18.2) The new topic today is cases where the parameter has an And symbol. These are called pass-by-reference or pass-by-address. The earlier, simple case, is called pass-by-value. The only difference in the pass-by-address case, is that when we come to the RETURN statement, we need to do one more new step just before we quit the function, we must transfer the values from within the DUNGEON to outside to the caller, only for those which are pass-by-address. 18.3) We are doing Prac Test Three's Question 7, and then Question 13 in class today. The Lab 8 ( right after spring break, and just before Test 3) will cover Question 13 and 10. 18.4) Now is the time to seriously start the Food Bank assignment, so review the Dailyhomework notes from two weeks ago, and get going. Do this by the end of Feb 23, 2023 ================================== 17.0) Repeat 16.2 17.1) Practice Test 3, Question 6. This is a trace of a function, which we will sometimes refer to as a DUNGEON. In this style of problem, we see the "int main" line, and we immediately do our first step: we write MAIN then we see the main variables, so we write our workspace to look like MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 then we do the printf (line 7), so in our output box, we get ______________ | a=2 b=3 c=5 | |______________| then, we try to do line 9, and say uh-oh, we have a function call, we write it in our workspace: MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 a = f (b, a, b+c) and we start to do new work, that will let us carefully trace the function. We do steps S1, S2, and S3. MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 a = f (b, a, b+c) S1 MAIN b | a | b+c S2 ########################### we BUILD THE WALL | | | S3 DUNGEON c | b | a | (I have said this since 2010 long before other people twisted its meaning.) Then we start to do the work of tracing: MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 a = f (b, a, b+c) S4 3 2 8 (came from 3+5) S1 MAIN b | a | b+c S2 ########################### we BUILD THE WALL S3 DUNGEON c | b | a We drop those values of our Step 4 (S4) into the Dungeon MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 a = f (b, a, b+c) S4 3 2 8 (came from 3+5) / S1 MAIN / b | a | b+c / S2 #######|################### we BUILD THE WALL | | | S3 DUNGEO| c | b | a | ---|-----|------ \ | | \ | | S5 3 | 2 | 8 We start doing the Dungeon steps: We see that we have a local variable, sum, so we write it to the table's side MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 a = f (b, a, b+c) S4 3 2 8 (came from 3+5) S1 MAIN b | a | b+c S2 ########################### we BUILD THE WALL S3 DUNGEON c | b | a | sum <---- S6 ---|-----|-------|------ | | | S5 3 | 2 | 8 | Now we do Line 18 (USING ONLY DUNGEON VALUES): MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 a = f (b, a, b+c) S4 3 2 8 (came from 3+5) S1 MAIN b | a | b+c S2 ########################### we BUILD THE WALL S3 DUNGEON c | b | a | sum <---- S6 ---|-----|-------|------ | | | S5 3 | 2 | 8 | 13 (add 3,2,8) Line 19 tests sum (which is 13) versus 24 (which is a*c i.e. 8*3) Because the test is false, we skip line 20. Doing line 21, sum (i.e., 13) is not Less than b*c (i.e., 3*2), so skip line 22. Then line 24 says "return"; when we see return we need to do THREE new steps. These 3 steps are: Fill Envelope; Fly Envelope; DUNGEON goes poof, up in smoke. Fill Envelope _______ |\ /| | \___/ | | | | 16 | |_______| Fly Envelope to replace the calling "f" and its parenths and contents. Then poof the DUNGEON. So, our workspace looks like: MAIN a | b | c ---|-----|----- | | 2 | 3 | 5 _______________ a = |\f (b, a, b+c)/| <--------- Erase this f and parens | \ / | Replace by 16. | \_________/ | | | | 16 | |_______________| So, our line (number 9) is a = 16, so our final workspace looks like MAIN a | b | c ---|-----|----- | | 16 | 3 | 5 Hence, line 10 causes our updated output box to be _______________ | a=2 b=3 c=5 | | a=16 b=3 c=5 | |_______________| 17.2) Next, do Question 9. It is a double DUNGEON, so need to solve the inner dungeon first, and then use its result (envelope) as a number that is needed by the outer dungeon. Questions 12 and 9 will also be covered in the Lab next week. Do this by the end of Feb 19, 2023 ================================== 16.1) Test is on Wednesday, Feb 22, during class. Try to arrive 5 minutes earlier than you normally arrive. Three questions on the Test TWO: a diamond twist, a calendar twist, and twist on the tracing question of Practice Test 2, Question 1. Silent test, do not bring any calculators/phones. 16.2) Repeat Dailyhomework 15.3 and 15.4. 16.3) If you have time start looking at Question 6 on Practice Test 3. Do this by the end of Feb 16, 2023 ================================== 15.1) (This topic is not on Test TWO or THREE, but will help you understand several important issues in programming, including how to use a flag.) We have covered prime testing in class today (Prac Test Two, Q 6). You must work out a deep understanding of how prime-ness is tested. Understand how first you assume something is prime, and then have a set of potential challengers who are trying to disprove the assumption. If (any) one of them succeeds, the assumption is undermined/shattered; if none succeeds, the assumption must be true. The deep issue here is understanding how to use the logic of the prime-property (that there is no number in between 2 and N-1 that will evenly divide N) to set up a process (with a bunch of steps) that sets up a hypothesis and then will systematically provide the challengers. The main code in the program is: int n; scanf ("%d", &n); int isprime=1; for (int i=2;ireq_amt[0]) { don_amt[found] -= req_amt[0]; //reduce the donation 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; i 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.). 5.2) Now, try Practice Test One's Question 5. Next week's Lab will cover Question 6, and maybe (if time permits) Question 7. 5.3) We will work through Update 7, which is about Assignment ONE, part C. Do this by end of Jan 19, 2023 ============================== 4.1) Read and examine the program ifpitfalls.c in Chapter 6 of the lectures. 4.2) Labs this week (Wedn, Thurs and Mon) will do more on the If statement. 4.3) Labs (in Engineering One, Room 188 or 187) are at the following 9 times: Wednesday at 3:30pm Engg One, Room 187 Thursday at 3:30pm Engg One, Room 188 4:30pm Engg One, Room 188 5:30pm Engg One, Room 188 6:30pm Engg One, Room 188 7:30pm Engg One, Room 188 Monday at 9:30am Engg One, Room 188 10:30am Engg One, Room 188 11:30am Engg One, Room 188 If you can, bring a laptop to the labs. Try to attend at least 1 Lab Session out of the times listed above. If you are not able to attend even one of the 9 sessions, please send email to nlobo@ucf.edu; we might email you a recording of a Lab. 4.4) Issues about IF: a. It is a fork in the road, so must make one choice, cannot do both pathways. This IF statement is sometimes called a control statement because it controls which statements will be run. b. The line (or lines) within the IF can be thought of as being protected by the IF test (or question or condition); that is, the line/s are only done if the test is TRUE. Similarly for the ELSE, its lines are only done if its IF is false. c. If the lines within the IF are only one, then we do not need the curly brackets to surround the lines. If the lines are more than one, then to ensure that they happen as a group, we must use the curly brackets to surround these lines. d. It is OK to have only the IF-part and no ELSE part. e. Note that this is the first type of statement that we do not put a semi-colon at the right end of the statement. So far, it is IF, ELSE, INT MAIN (VOID){, #include, and #define f. There is such a thing as a NESTED-IF, will see it in the Lab this week. g. The part that is the test or question must be enclosed with a pair of parens. h. The lines within the IF or within the ELSE, if these lines not special lines (like IF statements), then they generally must end with a semicolon; 4.5) Do Practice Test One, Question 2 (this will be repeated in the Lab). 4.6) Do Parts A and B of the Assignment One. There is a TA simply for Required Assignments and all programming issues. Please send that TA email (hung.tran@ucf.edu), if you need help. Also, see bottom of class page to see how this TA can help with Mac usage. 4.7) Download the .pdf file forloop.pdf (update 5) and read it and understand it. This is a different type of control statement, giving REPETITION. 4.8) Download the program forloop.c (from Chapter 7) and run it, and study it carefully. 4.9) Ensure that you understand how to quickly count how many times a for-loop is going to run. e.g., "for(i=17;i<27;i++)" runs 10 times. "for(i=17;i<27;i+=2)" runs 5 times. "for(i=26;i>16;i--)" runs 10 times. Finish the steps below by end of Jan 17, 2023 (do a little each day) ==================================================================== 3.1) Ensure that you complete the submission of Assignment Zero before tonight. (See Update 2 on the class webpage). 3.2) Read Chapter 5's sections Conditional Expressions, if-else Construct (Note that author of webpage may have error, so 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