讲解:C:COMP10002 Text QueryR、R

代写C基础作业,实现文本的查询。Submission InstructionsA complete submission is shown in the lecture recording starting at around the 10 minute mark of the class on 5 September.Information and ResourcesMeasuring speed: Note that when you have lots of output coming to the terminal screen, the scrolling and video-update processes can become time-consuming, making it seem like the program is executing slowly. If you want to measure the speed of your program, send the output into a file:myass1 word nerd bird slurred < pg11.txt > temp.txt Your program shouldn’t give an extended lag when you do this, the next prompt should appear within just one second (or if you have a really slow computer, maybe two seconds).What should Stage 1 output?: When I ran my program in class on Sept 8th, I didn’t have the right messages being generated for the “incorrect query” lines, I was missing the initial S1:. Your submitted programs should comply with the specification.Tricksy wicksy input: Hey, will we ever get command-line input strings likeass1-soln "" < alice-eg.txt orass1-soln "string with blanks" < alice-eg.txt that are not just single words? Answer: The latter of these two should be reported as a Stage 1 error, since the string you get via argv contains a non-alnum character. The former one won’t appear in any testing that I do, but you are welcome to also report strings of length zero as Stage 1 errors if you wish.Compilation: Dear Dr Moffat, (1) I have noticed that I cannot compile my program on dimefox without the flag “-std=c99” or higher. I was wondering if this is ok. (2) Is it ok to submit multiple files and how would I do this, as I have broken up my program into multiple header files. Answer: the compilation line I’ll be using on dimefox when testing your programs isgcc -Wall -o ass1 filename.c -lm The -lm is to get the maths library.Your program should be written in such a way that it compiles cleanly (no warnings) on dimefox with this command. Note that also means that you should be submitting a single file.Example Program: As an example of the standard of work that is expected (including the type and degree of commenting), here are:The 2013 Assignment 1 specificationThe skeleton program that was the starting point for the 2013 Assignment 1A sample solution to the 2013 Assignment 1.Note that you are not required to use structs in your Assignment 1 submission, but may do so if you wish to.Blank lines: Sir, what about blank lines? What about if the whole input file is empty? Answer: If you look at the outputs linked below you’ll see that blank lines are presemed to have line numbers, but don’t generate any output. A completely empty input file will generate the Stage 1 output, but no Stage 2 or Stage 3 or Stage 4 output.Apostophes and etc: Dear Sir, your output has the linesmany miles Iapos;ve fallen by this time?apos; she said aloud. apos;I must be getting S2: line = 2, bytes = 72, words = 15 but it seems you are counting “I’ve” as two words rather than one. Shouldn’t that be just one word? Answer: The definition of “word” we are working to makes it two words. (And, in any case, isn’t “I’ve” short for “I have”?)But Sir, if we count “I’ve” as two words, and one of the query terms is “v”, then won’t that mean there is a match that has to be counted? Answer: Correct, and that is what the specification intends and that is what my program does.Value of argc: Dear Sir, you say in the handout that argc of zero represents no query. But don’t you mean argc of 1? Answer: Yes, I guess I do… Access Denied on dimefox: Note that you won’t have an account yet on dimefox if you have never logged in to a lab machine so far this semester, for example, if you have been using your own computer for all the workshops, or if you simply haven’t attended any workshops. The symptoms of this will be an “access denied” message when you try and connect with scp/puttyscp or ssh/putty when you want to copy/submit your program. You will need to login to a lab machine, get you account initialized, and then wait a few hours for everything to percolate through the various processes involved with transferring those account details on to dimefox. Then you’ll be in a position to ssh/scp and eventually submit.If you still have problems after you have taken this step, and are sure you are using the right password (and can log in to other University services using it), send me an email confirming that you have taken all of these steps and still can’t get access to dimefox. Don’t leave this until the last minute. It is a problem that can’t be fixed in a minute!What Can Be Stored?: Dear Sir, you say “You can only retain five lines and their scores at any given time, plus the current line that is being processed”, do you mean that exactly, or do you really mean “You can only retain five data structures representing five lines (possibly, for example, in original as well as processed/parsed format) and their scores at any given time, plus the current line that is being processed?”. Answer:Yes, good question, and I mean: you can retain at most five instances of the data structure(s) that represent a single line.Error in Printed Handout: There was a small typo in the printed version of the handout that was ciculated in class on Friday 1 September that has now been corrected in the online version here: the very first example in the handout showsmac: ./ass1 < alice-eg.txt S1: No query specified, must provide at least one word mac: ./ass1 Lat 66 loNg 32 words < alice-eg.txt S1: query = lat 66 loNg 32 words S1: loNg: invalid character(s) in query mac: and it should be showingmac: ./ass1 < alice-eg.txt S1: No query specified, must provide at least one word mac: ./ass1 lat 66 loNg 32 words < alice-eg.txt S1: query = lat 66 loNg 32 words S1: loNg: invalid character(s) in query mac: with a lowercase “ell” in the second example commandline marked by the arrow.Marking Rubric: The marking rubric is linked here. Lines that do not apply to your program will be removed during the marking process; your mark will then be the sum of the lines that remain, positives and negatives. Marks won’t go below zero in each section, and won’t go below zero overall either.Attribution for Re-Used Code: It is ok to make use of code (for example, insertionsort, and/or getword(), and etc) from the book or from the lecture slides or from other published/public sources, but you should remember to add an attribution as a comment to each relevant function, saying where you got it from, what modifications you added to make it suit your purpose, and so on – exactly as you would when quoting some other author when writing an essay.Of course, the expectation is that the assembly and “glueing together” of these bits to make a final program will all be your own work, and that the “quoted” bits will be a relatively small fraction of the “new” output you are being asked to generate. So it is not ok to take a whole solution from somewhere else, even if it appears on the web; and it is not ok to solicit or commission a solution by posting the specification to a forum or web site and asking for “assistance” or “guidance” or “suggestions”. Just as it wouldn’t be ok to submit something you found online in response to an assignment that involved writing an essay.And a reminder of what it says in the specification: we will be using similarity-checking software across all the submissions, and we will be referring cases of suspected academic misconduct for disciplinary hearings run by the School of Engineering, and in the past those hearings have resulted (including multiple times in this subject) in students being awarded penalties including final marks of zero for the subject, regardless of their other components of assessment.Debugging (more): If a C program encounters a run-time error and exits, there might still be pending output that has not been written. This is a particular problem in the submit environment, because it can look like the program is failing before it generates any output at all. If in doubt, add fflush(stdout) function calls after each of your your debugging printf()’s (or even, add it to the macro), to force all pending output to be written immediately. You’ll then be able to get a much clearer idea of how far the program is getting before it fails.Debugging: Try putting thiC代写:COMP10002 Text Query代做留学生R语言、R作业调试s at the top of your program:123456#define DEBUG 1#if DEBUG#define DUMP_DBL(x) printf(&"line %d: %s = %.5f\n&", __LINE__, #x, x)#else#define DUMP_DBL(x)#endif& and then, later in your code, where you have a double variable (say) score, try1DUMP_DBL(score);& Then change DEBUG to 0 at the top of the program, compile it again, and then run it again. Get it?Can then add DUMP_INT and DUMP_STR, and get the extra output turned on whenever you need it to understand what your program is doing. Then turn it all off again with one simple edit.Trouble with newline characters: Text files that are created on a PC, or copied to a PC, edited and then saved again on the PC, may end up with PC-format two-character (CR+LF) newline sequence, see the Wiki page for details.If you have compiled your program on a PC, and it receives a CR+LF sequence, then getchar() will consume them both, and hand a single-character ‘\n’ newline to your program. So in that sense, everything works as expected. Likewise, on a PC when you write a ‘\n’ to stdout, a CR+LF pair will be placed in to the output file (or passed through the pipe to the next program in the chain).The problems arise when you copy your program and a PC-format test file to a Unix system and then try compiling and executing your program there. Now the CR characters get in the way and arrive via getchar() into your program as stand-alone ‘\r’ characters.The easiest way to defend against these confusions is to write your program so that it looks at every character that it reads, and if it ever sees a CR come through, it throws it away. That way, if you do accidentally get CR characters in your test files on the Unix server (or on your Mac) your program won’t be disrupted by them. Here is a function that you should use to do this:1234567intmygetchar() int c; while ((c=getchar())==\r) return c;& Then just call mygetchar() whenever you would ordinarily call getchar(), on both PC and Mac.Because most of you work on PCs (including in the labs), the test files that are provided have been created with the PC-style CR+LF newlines, and should work correctly when copied (use right-click->”Save as”) to a PC. With mygetchar() they can also be used on a Mac, but won’t interact sensibly using the standard getchar() function.To be consistent, the final post-submission testing will also be done using PC-style input files but will be executed on a Unix machine, meaning that all submitted programs will need to make use of mygetchar().You can use the “Preferences->Encodings” menu (“screwdrive/hammer Options->Encodings” in the PC version) in jEdit to select whether to use Unix (LF) or DOS/Windows (CR+LF) encodings in any test files that you create with jEdit. Note that this only applies to newly created files. jEdit will by default respect the formatting in any current files.Note also that jEdit doesn’t automatically add a newline after the last line of text files, you need to put it there explicitly yourself (just press enter one more time, so that jEdit thinks there is an empty line at the end of the file). Watch out for this problem if you are creating your own test files on Mac or PC. All the test files I supply will have a newline at the end of the last line of the file, including during the post-submission re-testing.If in any doubt, use od -a

in a Unix shell to look at the byte-by-byte contents of a file, and check which format is being used, and whether there is a final newline character (or final CR+LF pair). You can do this on a PC by starting the MinGW shell and then using cd to reach the right directory. There is an od version available within the MinGW shell on the PCs in the labs. On a Mac, Terminal is a Unix shell.Tabs: The default in jEdit is for tabs to be aligned every 8 character positions. Some of you have altered that to four (Preferences-]Editing-]Tab width), to reflect the layout that the programs in the book have. Then, on submission, the tabs have “appeared” in the output as being 8 again, which can make your program spill past the 80-character RH boundary. When I run the programs for marking, they’ll all get formatted with tabs reflecting 4 character positions, not 8. But don’t use any fewer than 4 in your jEdit (or other editor) settings.Magic numbers: Here is a summary of the rules about magic numbers:Where a number is totally self-defining, I’m happy for it to be used any number of times without a hash-define, provided the code is commented each time and/or explicitly sensible variable names are used. For example, in12/* compute percentage */pcent = 100.0 * count / totcount;& I wouldn’t expect 100 to have been hash-defined, since the comment explains the role of the 100, and it isn’t going to change, ever, even if other percentages are calculated in the program using 100 too.This rule also allows 0 and 1, of course, unless they represent something other than the additive and multiplicative identities, in which case they should be hash-defined.This rule also allows while (scanf("%lf%lf", x, y)==2), since the 2 is immediately obvious from the adjacent context (two variables to be read).Where a constant is one that is a fact that is in no way ever going to be varied, then provided it only appears once in the program and is explained with a comment, then it need not be hash-defined. The example here is the -32.0 in the temperature conversion computation, assuming that it is entirely within a function called Cels2Fahr or etc and that it isn’t used in other places scattered through the program. Anything of this type that appears even twice should be hash-defined.Where a factual constant is used more than once in a program, even if all occurrences are in a single function, it should be hash-defined.Where a constant is one that is clearly an artifact of the problem description or the program that implements the solution (for example, numbers like MAXINT, or the number of variables), then they must be hash-defined, even if only used once in the program.转自:http://ass.3daixie.com/2019011642253416.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,445评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,889评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,047评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,760评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,745评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,638评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,011评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,669评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,923评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,655评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,740评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,406评论 4 320
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,995评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,961评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,023评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,483评论 2 342

推荐阅读更多精彩内容