logo

Defending Against Confusion

   

Added on  2019-09-22

7 Pages3161 Words293 Views
 | 
 | 
 | 
COMP20005 Assignment 1, 2017s1Last updated: April 28, 2017Oldest entries are at the bottom.Items 1-10 were in place when this page was first released on 5 April.Submission InstructionsThe submission process was illustrated starting at around the forty-three minute mark of the lecture on Friday 7 April. Review that lecture section if you are havingtrouble withsubmit.Information and Resources23.Programs that Crash on dimefox: Note that ondimefoxthe programs are being executed in non-interactive mode, and partial output doesnotautomatically get captured if the program crashes. This can make ithard to determine where it is in the program that the problem is occuring. Best bet is to put a commandfflush(stdout);after each Stage's output is complete, so that anything generated by that stage is guaranteed to be captured in the output stream. You can add this after any otherprintf()statements in the program too, if you want to be sure that youwant to capture every ounce of output generated. Then what you see withverifyshould be the same as what you would have seen if you had run the program interactively at the command-line. You may leave thefflush()statements in place when you submit, or include them as part of what is controlled byDEBUG, see #19.22.Upper Bound on Arrays: A couple of students have said that on their computers the 50,000 limit cannot be achieved, that their programs fails with a Segmentation Fault error if multiple arrays of that size are declared aslocal variables in themain(). You may decrease the limit to 20,000 if you are experiencing this problem.21.Assert? (A question from "an awestruck & brainwashed programming student"). The sample solution to 2015 hasassert.hincluded. If you includethis, it gives you access to the functionassert()and enables you to write things in your program like:22. /* compute average */23. assert(denominator>0);24. avg = numerator/denominator;where you are sure that the denominator will be positive, and you think the program is correctly computing the things you want, but if something has gone wrong (bizarre data, or weird unexpected input combinations, or
Defending Against Confusion_1

whatever) you want to get a "soft crash" rather than a "hard crash". What happens is that the expression in the assert gets tested at runtime, and if it is not true, the program will halt at this point, and print the line number and file nname, and the assertion that failed. Try it if you like!20.Stage 4 Output: Yes, one of the input files you have been given (data00031.txt) doesn't comply with the specification, because it doesn't fit the description of "you may assume that each year that is represented in the input will have data for all twelve months (so that the scores are always out of 24)". This question came up at the beginning of the lecture on Monday 24April; please listen to that before asking again about it. My program generates 0/2 for that data file, and 0/24 will also be regarded as being correct for this data file. Ok?19.DEBUG, huh? Student question, "Sir-oh-illustrious-one, I noticed in your program yesterday that you had a#define DEBUG 0, what was that about?" Yes, good question. At the top of the program I have20. #define DEBUG 0and then right through the program I can do things like if (DEBUG) { printf("line %3d, x = %d\n", __LINE__, x); }which doesn't do anything whenDEBUGis zero, but prints out the program line number and the value ofxwhenDEBUGis 1. This lets you put helpful debuggingprintf()s right through your program, and then switch them all "off" by changingDEBUGto 0. Then they can stay there in the code, inactive, in case they are needed again later. The constant__LINE__(two underscore characters on each side) gets expanded to the current line number by the compiler when it is processing your program. (Just make sure thatDEBUGis zero when you submit your final version, of course.)18.File Operations: Student question, "Can we usefopen()in our programs? No, on no account should you be usingfopen()in your programs. The data that your program will execute on in the test harness will be supplied via redirection ofstdin. If you try and open a named file usingfopen()your program willfail.17.Stage 4 Output: I have had this question several times now, "When we're given between 6 and 9 years of data, how should it be printed out in Stage 4? I agree that the spec doesn't cover this case, and so anything reasonable/sensible will be accepted. But for concreteness, if you want to betold what is reasonable/sensible, feel free to implement this rule: "at most 5 lines at the beginning, followed by a -- if any lines are omitted, followed by
Defending Against Confusion_2

at most five lines from the end, with no lines duplicated". Both of these next examples would fit that rule:18. Stage 419. -------20. 2009: score is nn/2421. 2010: score is nn/2422. 2011: score is nn/2423. 2012: score is nn/2424. 2013: score is nn/2425. 2014: score is nn/2426. 2015: score is nn/2427. 2016: score is nn/2428.29. Stage 430. -------31. 2006: score is nn/2432. 2007: score is nn/2433. 2008: score is nn/2434. 2009: score is nn/2435. 2010: score is nn/2436. --37. 2012: score is nn/2438. 2013: score is nn/2439. 2014: score is nn/2440. 2015: score is nn/2441. 2016: score is nn/24wherennis the score you have to calculate.16.Debugging: Yes, I do sometimes take a look at programs if you are stuck (debugging is also fun!), and can usually identify issues that might be givingyou your problems. But please don't just mail me a screenshot, or paste a little bit of program fragment into an email -- I'll want to see the whole program. Sosubmitit ondimefoxso that I can see all of it (and what happens when it executes)beforesending me a nice email that says "Dear Sir, I'm really truly enjoying your lectures, and indeed I am beginning to seejust how much fun programming could be (and I would very definitely to make it even more fun in the future), but I have a slight problem right now that is detracting from the immense fun experience. Would you mind, oh-inspirational-one, taking a look at my current submission and see if you canexplain why" and then summarize the symptoms of the problem that you are having. I wouldn't go so far as to say that I answer such emails in order of decreasing obsequiousness, but the ones that are truly sucky do certainly make me smile...15.Question from a student: On the first page, you state that it is 45 years for the data from 1971-2016 inclusive. Wouldn't it actually be 46 years including both 1971 and 2016?: Yes, you are right. That's a mistake, 1971-2016 is indeed 46 years.
Defending Against Confusion_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents