Nothing FROM THIS PAGE NEEDS TO BE TURNED IN. YOU JUST DO THIS daily TO KEEP UP. 26.1) The Test Four on Friday, April 5, will allow the student to commence the test a few minutes earlier, and will also end a little later than the normal class time. If you are able to, plan to arrive and be seated by 9:15am, and plan to stay till 10:25am. Students arriving between 9:20am and 9:30am will be given a few additional minutes after 10:25am in a different room (which they will be led to at 10:25am). 26.2) For the picture writing question, if the question says that the picture length (height) and width are multiples of 5, then be prepared (for example) to handle a situation where you are being asked to blacken the fourth (vertical) strip from the left. 26.3) For the file question, you will be shown a sample input file and a sample output file; make sure that you look at them carefully to understand what is the baby-logic being expected from the program that you will write. 26.4) For the sort question, to avoid confusion about which (second, third, fourth, etc) line is being asked to be printed, the FIRST time that print is called, will be marked in the code with a comment. 25.1) The final exam questions are the following: 1) T4Q1 2) T4Q2 3) T4Q3 4) T4Q4 5) T3Q2 6) T3Q3 7) T3Q4 8) T2 Trace Frequency Star Plot 9) Baseball Question from Prac Final Exam 10) Random Words Question from Prac Final Exam 11) Advanced Structure-Function Question (Ques 4 on Prac Final Exam) 12) "Nasty Trace" 12 questions, 6 of which are code writing, and 6 of which are trace (one of the trace is Nasty Trace). 24.1) For the files question, follow the following example: These 5 notes accompany the videos (Update 16): Note 1: The problem to be solved is: ====== Write a complete program (with all the headings, etc.) that reads in a positive integer n, and thereafter on n subsequent lines there are three items per line (an int Land-Survey ID, a positive float value Length, and a positive float value Width, which represent the sides of a rectangular plot of land). All this is from a file. Before you read the integer n from the file, you must prompt for the filename as a string that is certain to be less than 30 chars long. Open the file, read what you need to, and for each line, determine if the area of the plot of land exceeds 500; if it does exceed, then write all three values (ID, Length, and Width) to an output file (after each set of three values is written, write a \n character to the file). (It is assumed that you know that Area is obtained by Width multiplied by Length). You must prompt for an output filename string (again, max 30 chars). After writing all the needed sets of three values, write the Land-Survey ID that has the overall highest value for Length (also write that winning Length). You should assume there is only one entry with this highest Length. Remember to close both files before returning, and do not use a struct for this program. DO NOT check for any errors. Note 2: The solution to the "Baby" stage, or "Logic" stage is: ====== The starting program #include int main() { int n; int id,len,width; scanf("%d", &n); for(i=0;i 500) printf("%d %d %d", id, len, width); } system("pause"); return 0; } Note 3: Changes that are needed to do Files (for reading) ====== Changes needed to do (reading) files: FILE* fp1; fp1 = fopen("inputfile1.txt", "r"); fscanf(fp1, ... fclose(fp1); Note 4: Changes that are needed to do Reading and Writing of files: ====== Changes needed for reading and writing files: FILE* fp1; FILE* fp2; fp1 = fopen(word, "r"); fp2 = fopen("outputfile1.txt", "w"); fscanf(fp1, ... later, do, as needed, fprintf(fp2, ... fclose(fp1); fclose(fp2); Note 5: Final Program: ====== #include int main() { FILE* fp1; FILE* fp2; int n; int id,len,width;char word[30],word2[30]; printf("type input fname:") scanf("%s",word); printf("type output fname:"); scanf("%s",word2); fp1 = fopen(word, "r"); fp2 = fopen(word2,"w"); fscanf(fp1,"%d", &n); for(i=0;i 500) fprintf(fp2, "%d %d %d", id, len, width); } fclose(fp1); fclose(fp2); system("pause"); return 0; } 23.1) Test 4 is Friday April 5. It has only 4 questions: a tracing question with the sort program, and three code-writing questions; the three writing questions are 1) picture-writing to transform a picture, 2) structures in functions, and 3) a files program. 22.1) Remember, we have Test 3, next class day. It has only 4 questions, they are very very similar to Prac Test 3, Questions 14, 15, 16, and 17. 22.2) Start doing Assignment 4 (See Update 0). 22.3) We will do more Struct learning during the labs this week. 22.4) Test 4 has 4 questions: one for writing Pics, one for structs, and one a tracing question for Sorts, and lastly a file question. 22.5) Review and study the files videos (Update 16). 21.1) Review the notes on structs 21.2) Here is how to approach the actual question Two for Test 4. (Practice Test 4, Questions 4, 5, and so on). 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 parameterss 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 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 undersore 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. 20.1) Here are the steps you would use for Trace of a Double-Function non-Vegas-Protected Question (such as Prac Test 3 Question 15). This approach of passing arguments is normally called PASS-BY-VALUE. Step 1: Make a variable table for Main, and fill in its values. Step 2: Write down the line in the Main that calls the function (This will help you to know why you went to a Dungeon, and what has to be done when you return from it). We will refer to this as the Calling Line. Having written this line, it is clear that you must now BUILD THE WALL for the Dungeon, We will call it Dun-1 (because we know in advance that we will need a Dun-2 as well). So, draw the wall and put the name MAIN above the wall, and DUN-1 below the wall. Step 3: Write the variable names that are to be in the MAIN list , put them above the wall; you will get this list from the Calling Line (See Step 2). Step 4: Below the wall, write the list of names of the variables, obtained from the Function Header line (which is the line that leads the definition of the function, also sometimes available from the second line in the program.) Step 5: Draw the vertical lines to keep the silos separate in the dungeon. Step 6: Put the values of the variables for above the wall (get them from Main's table). You will STALL on this step due to having a second call to the function, So, proceed to Step 8, and then follow its sub-steps. Step 7: Drop the values from Step 6 through the silos into the variable table BELOW the wall. Step 8: This is the STALL step. So, first start a second dungeon, call it Dun-2 Draw its wall and write MAIN above, and DUN-2 below. Then do the above steps Step 3, 4, 5, 6, and 7 for this second dungeon; call them Steps 3', 4', 5', 6', and 7'. Note that there will not be a stalling happening on 6' this time. So, first do 3' and 4' properly: 3' will get its list from the second call to the function (look at the Caling Line in Step 2 for help here). Then 4' will get its list from the Function Header line again (so, you will notice that both Step 4 and 4' produce the same list... of course, this is no coincidence, this is simply because they are coming from the same source of information, namely the Header Line). Then get values for 6' from the Main's table (notice that there is no stalling happening this time), and drop them below the wall to do Step 7'. Proceed to Step 9. Step 9: Now, you must do the actual lines that are listed in the actual function. This will involve adding a new column to the DUN-2 for any LOCAL variables that are declared (in our case, there may be a variable named Sum). Then finish all the lines, using only the values from within the dungeon; do these steps till you come to a RETURN. At a RETURN, do Step 10: Step 10: To do a RETURN, break it into 3 parts: Firstly, fill an ENVELOPE with the value that is obtained from the expression after the word RETURN. Secondly, Send the envelope to replace the name of the function in the appropriate place in the calling line. This means going to the original Step 6 and putting the value in the place of the function name at the top of the silo. Then (thirdly, this is the third part), erase the complete dungeon (Dun-2), and proceed to Step 11. Step 11: Now that you are unstalled at Step 6, do the following: Do Step 7, then do Step 9 above, but you are doing it in the area of Dun-1; this time, when you arrive at the RETURN, do the 3 parts of Step 10, but at the second part, you will not put the value at the top of a dungeon table, instead you will put it on the line that you wrote for Step 2. Then, finish the third part (erase Dun-1), and return to the line of Step 2, and finish it; that is, finish the EQUAL-SIGN's work, which is to change the value of the variable on the Left-Hand-Side, in the Main's table. Then proceed to the line which is after the line that was written for Step 2. 20.2) To do a problem like Practice Test Question 16 (a double function Vegas-protected situation), the new idea is that at the RETURN step, you need to do parts 1 and 2 as before, but before you do part 3, you must do a new part 3 (so, the new part 4 will now be the Erase Dungeon part). For our new part 3, we must send back through the silos, upwards, the values of any variable that are AMPERSAND-STAR paired, these are the non-Vegas-protected variables, and normally called PASS-BY-REFERENCE, or also normally called PASS-BY-ADDRESS. If we carefully follow the steps from 20.1, and remember to do this new part at the RETURN step, we will get the correct results. 20.3) Ensure that you have started studying for the last question on Test Three. In the Practice Test Three, it is Question 17. You must start by quickly reading over Required Assignment Four. This is the picture processing program. So, you need to know that in the program assign4.c, you should (for now, for Test 3) simply focus on the function ADDTOPIXELS. Your task in this type of question is to trace the actions of the ADDTOPIXELS function, and print out the final table of size 3 times 3, i.e., nine numbers. We now look at Practice Test 3's Question 17; for help we provide the solution method. Given: ====== void changepixels (int** pic) { int i,j; for (i=NR-1;i>0;i--) ( for (j=0; jreq_amt[0]) { don_amt[found] -= req_amt[0]; //reduce the donati on table's amount; //remove the request as above for (i=1;i for (index=0; index<5; index++) { This starts a for loop that wil run (apparently, but we need to verify) 5 times Everything that is within this loop's { and } will run (5 times). the first of such (to be repeated 5-times) things is > for (stars=0; stars< (maxfreq - freq[index]); stars++) > printf(" "); So, you need to figure out what this new for-loop does. Well, it is a loop controlled by the counter "stars". To figure out how many times this new loop will run, we need to make sense of (maxfreq - freq[index]). We know that maxfreq is 4, and we know that index is zero. So, we look up our array table and find that freq[zero] is 2 (because the prior code had seen 2 a's.) This give us that (maxfreq - freq[index]) is 4 - 2, which is 2. Hence we can suspect that this new loop will run twice.What does it do each time it runs? Within it, it prints one space. Hence, it must be that the net effect of it running is that it "prints two blanks". The next thing in the original for-loop is a third for-loop > for (stars=0; stars< (freq[index]); stars++) > printf("*"); that we can see runs up to (freq[index]), which is 2. Its controllee is to print one "*", that means the net effect of running this third for-loop will be to "prints two stars". Thus in the output so far we have: __** The next thing is a "%c \n", ('A' + index). > printf("%c \n", ('A' + index) ); Well, index is still zero, so 'A' + zero is just 'A', so our output line will be: __**A__ Finally, we print the "\n" to leave that line and go to the next. The original loop has now completed one pass through itself, so it now does index++, which means index becomes One, and the original loop now goes through for a second pass (with index now being 1). This same process will have been repeated five times, before quitting completely. (Note that 'A' + 1 will be the character 'B' at the next step). Finish the steps below by end of Jan 29, 2019 (do a little each day) ==================================================================== 8.1) For the calendar program (Practice Test Two, Q. 9), first use the hint given there. Read the hint. So, need a FOR loop, then need a statement to check if "i" is the last day of the week. But will need to ensure that the early part of Calendar, the days that are reserved for the previous month, are accounted for properly, when you check to see if this is the last day of week. This will give us code that looks like: for (i=1; i<=days; i++){ printf(" %2d",i); if ( (start-1 +i)%7==0) printf("\n"); Then you also need code to actually print the spaces for the previous month, so that our new start location is correct, when we print the first date. 8.2) Here is the complete calendar program: #include #include int main() { int i, start=3, days=31, p; for (i=1; i16;i--)" runs 10 times. 5.5) Read CAREFULLY Part C of Required Homework Assignment 1. Next class we will do additional loops, and we will discuss this Part C problem, so, you can start and complete it after that. HERE ARE THE MOST IMPORTANT STEPS FOR TODAY: 5.6) Make very sure that you know how to write a program (from the very first line to the last line) that will simply read in a number and do something to it, like compute a percentage of it, or convert it to farenheit, or compute its squared value, 5.7) Make very sure that you now know how to write a program (from the very first line to the last line) that will read a quantity in and will do something involving an IF statement (maybe, also include an ELSE statement). 5.8) Now, the next thing to focus on is how to embed the idea from 5.6 or 5.7 within a FOR loop. So, for example, you could read in a number and square it (and print out the squared value), but the new task is to put this code within a for-loop that runs 25 times. This means that 25 numbers will be read in and their squared values will be printed out, one at a time. 5.9) Now, 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.). 5.10) Now, try Practice Test One's Question 5, then Question 6, then 7. Finish the steps below by end of Jan 15, 2019 (do a little each day) ==================================================================== 4.1) When studying chapter 4's sleep.c, ensure you are learning how to use the division and the mod (percent) operations correctly to get to parts of numbers. That is, this a quantitative skill you are learning, not just a way to do a particular programming sentence. The quantitative skill is that of how to get at the integer parts that make up a bigger number, and then how to get to the left-over remainder when the integer parts are taken away. You need to think of at least four other situations where this operation to separate out the parts, would come in handy. 4.2) Read Chapter 5's sections How to use Prewritten ..., How to use C Math ... Make sure that you are understanding that the result from the calling of the function, you should think of it that the result comes and replaces the calling words. This is similar to how functions work in a Mathematics situation. That is, when you say "x has some value, and you use x-cubed", then what happens is that you must think that the x-cubed value comes and replaces the words "x-cubed". So, if x is 5, the then value of 125 comes and replaces the words "x-cubed". So, make sure that you think of it as a replacement that happens whenever you have a function call. 4.3) Download quadratic.c run it, and erase and re-create. 4.4) Download quadratic2.c, tempconvert.c, tempconvert2.c, priceisright.c, ltrgrade.c, wage.c, slope.c, scholarship.c. Run them, examine the programs carefully, try to re-create them one at a time from a blank canvas. 4.5) Finish Question 2 of the Practice Test. 4.6) Completely Finish Part B of Required Homework Assignment 1. Finish the steps below by end of Jan 13, 2019 (do a little each day) ==================================================================== 3.1) Ensure that you complete the submission of Assignment Zero before tonight. (See Update 1 on the class webpage). 3.2) Do Dailyhomework 2.10 3.3) Download arithmetic.c and grade.c. Run both of them and study them carefully. Ensure you can explain why the outputs turn out to be what they are. 3.4) Finish (Update 3) Part A of Required Homework Assignment 1 (do not submit yet). 3.5) Ensure that for Chapter 4's sections Use of Printf, and Formatting Output Spacing, ensure that you tried out a variety of formatting spacings. 3.6) Ensure that you understand Integer Division, i.e. why 13/4 evaluates to 3 3.7) Read Chapter 5's sections Conditional Expressions, if-else Construct 3.8) Do Practice Test 1's question 2. 3.9) Download sphere.c, easytax.c, tall.c, sleep.c, digits.c and run all. 3.10) Try to re-create easytax.c, tall.c, sleep.c, and digits.c from a blank canvas. It is very important that you begin to learn how to manipulate data to get the kind of desired effect of digits.c Finish the steps below by end of Jan 10, 2019 (do a little each day) ==================================================================== 2.1) At this point you need to have been able to run at least three programs, and got the black screens working for them. You need to have understood what integers are, then you should have tried something with floats, doubles, and chars. Ensure that you know that for printing them, you know that you use %d, %f, %lf, and %c respectively. Ensure that you understand that in a program, first you write the four-ish lines that you always need, then you put a gap in to write the rest of the code, then in that gap you first declare your variables, and then you do something with them. But, you cannot use a variable on the right-hand-side of an EQUAL sign if you have not yet given it a value. (also, you cannot use it in printf yet till you give it a value). Ensure that you are remembering that a single EQUAL sign means BACKWARDS-ARROW. 2.2) Read the Notes for Chapter 3, IO.pdf. 2.3) Make sure you write programs that have statements such as a++; or a += 10; ensure you understand the meanings of these statements. 2.4) Download feettomile2.c, and learn about the use of scanf. For additional programs that you might have written for 1.5 (such as a sales tax program, or area of a rectangle), modify them to read in most of the quantities, and get expertise using the scanf in a variety of situations. 2.5) Invent other simple mathematical calculations, such as, converting kilograms to pounds; write programs for these cases. 2.6) Download arithmetic.c and grade.c. Run both of them and study them carefully. Ensure you can explain why the outputs turn out to be what they are. 2.7) Ensure that you understand the percent operator that is used to get the remainder of a calculation. 2.8) Read the Notes for Chapter 4. 2.9) Make sure that you go to Update 0 and follow the steps for doing the webcourses submission before the end of Friday, Jan 11. 2.10) For 2.11, 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 as the first line, and to add the line system("pause"); just before the return statement. (These two lines are only needed for DevC++, and are to be removed for CodeBlocks or for Linux systems. Make sure both programs (i.e., hello.c and feettomile.c) run on your computer. When you run each one, it should produce output on the black screen (or white screen on a mac, or on the terminal on Linux) 1.3) After you have verified that you can run both programs in 1.2, erase each one, and try to write it yourself without looking at any notes. Get help from the notes to finish each program. Finally, keep repeating 1.3 until you are able to write each program by starting from an empty page and without any help from notes. 1.4) Read Lecture notes, Chapter 2 (the title is Introduction, First Program), skipping the sections called A Brief Intro to Pointers, and Another Method To Visualize Pointers. (You can also skip the section titled "Side Note about Main ...") 1.5) Understand all the four types of variables in Chap 2 (the four are int, float, double, and char). Try writing feettomile.c as floats. Make up additional calculations, such as computing the amount of tax from a six percent sales tax on a ten dollar purchase. Do these (new) programs both ways, first with ints and then with floats. Note that the formats needed for printing them to the screen (with the printf statement) are: %d, %f, %lf and %c for the four types above. Keep in mind that programming is similar to organizing any large operation. When you order a BigMac, the store does not go out and start by killing the cow, harvesting the wheat for the bun, and plucking the vegetables. The store has them all ready to go in proper positions, so that the Sandwich-Artist can easily get the parts needed to finish completing the bun and feed you fast. Getting all the parts ready to finish the job is what programming is. Other example programs to try writing are: 1) compute the area of a rectangle, from its length and width; 2) compute the area of a triangle, from its base and height; 3) compute the total Financial Aid from the two numbers: grants and loans; 4) calculate the sum total of the cost of four textbooks; 5) grandma gave N (like 200) dollars to be divided among Q grandkids, how much will each kid get? 6) compute the Soccer World Cup Year which will be, say, five, World Cups tournaments from now (which you can assume is 2019). 1.6) Look in "Notes" under "Language Basics Chapter 3"; download the "Notes", the file is titled IO.doc. Skip to the ending sections titled Increment and Decrement Operators, and Other Shorthand Assignments; read them carefully. Make sure you write programs that have statements such as a++; or a += 10; ensure you understand the meanings of these statements. 1.7) Download feettomile2.c, and learn about the use of scanf. For additional programs that you might have written for 1.5 (such as a sales tax program), modify them to read in most of the quantities, and get expertise using the scanf in a variety of situations. https://sourceforge.net/projects/orwelldevcpp/