” 写作ICS 45C程序、C++编程语言ICS 45C Fall 2020Project #2: Letter Never SentDue date and time: Monday, November 2, 11:59pmIntroductionOver my years of teaching, Ive become quite fond of a grading scale that I jokingly refer to as the Whatever I Want scale. Ofcourse, its not quite as open-ended as my glib joke about it; its a fair scale in the sense that any two students who perform ata particular level will receive The same grade though it is neither a straight scale nor a curve, requiring me instead todecide, at the end of the quarter, where to set cutpoints that divide the students who receive one grade from the students whoreceive another. This is the grading scale that Ill employ at the end of the quarter in this course.This project asks you to write a utility program that is given input via the standard input (i.e., std::cin) describing the set ofgraded artifacts for a course, the students enrolled in the course, and their scores on the various artifacts. Additionally, it isgiven a sequence of cutpoint sets describing the cutpoints (i.e., the number of total points necessary) to achieve various gradelevels. The programs output is twofold: the total score received by each student in the course and, for each cutpoint set, finalcourse grades for each student. The idea is for a tool like this to be used by a person to look at a few possible outcomes, todetermine whether the outcomes are fair. The program makes no determination about that fairness, though; it provides theraw materials for a person to analyze.Not surprisingly, you will need to write the program in C++, though there are some fairly heavy restrictions on what parts ofC++ youre permitted to use, as were still early in the process of learning it and Id like you to gain some experience withsome of the lower-level abstractions (most notably arrays, new, delete, and delete[ ]) before we layer less error-proneabstractions on top of them. Our goal in the early part of this course is to develop an understanding of what is happeningbehind the scenes in a C++ program, and its impossible to develop this understanding if you sit at too high of a level ofabstraction.Getting startedAs with the previous project, youll need to complete some chores before you can start working on this project. Be sure youread these instructions and follow them completely before proceeding.Refreshing your ICS 45C VM environmentEven if you previously downloaded your ICS 45C VM, you may need to refresh its environment before proceeding with thisproject, so that you have a copy of the project2 project template that youll need for this project.Log into your VM and issue the command ics45c version to see what version of the ICS 45C environment you currently havestored on your VM. Note, in particular, the timestamp; if you see a version with a timestamp older than the one listed below,youll want to refresh your environment by running the command ics45c refresh to download the latest one before youproceed with this project.2020-10-18 16:40:01Project #2 template addedIf youre unable to get outgoing network access to work on the ICS 45C VM something that afflicts a handful of studentseach quarter then the ics45c refresh command wont work, but an alternative approach is to download the latestenvironment from the link below, then to upload the file on to your ICS 45C VM using SCP. (See the Project #0 write-up formore details on using SCP.) Once the file is on your VM, you can run the command ics45c refresh_localNAME_OF_ENVIRONMENT_FILE, replacing NAME_OF_ENVIRONMENT_FILE with the name of the file you uploaded; notethat youd need to be in the same directory where the file is when you run the command.ics45c-2020fall-Environment.tar.gzCreating your project directory on your ICS 45C VMA project template has been created specifically for this project. It includes a gather script for preparing your files forsubmission when youre finished, support for running the memory-checking tool Valgrind (Memcheck) to test the memoryusage of your proram, as well as a sample input for your program (the same input that is specified in the project write-up), toprevent you from having to type it repeatedly.Decide on a name for your project directory, then issue the command ics45c start PROJECT_NAME project2 to create yournew project directory using the project2 template.Do not use the basic or project1 templates for this project! You may find that they are missing some new tools that youll beneeding in order to complete your work!The inputThe programs input is to be read from the standard input (i.e., std::cin). It is separated into four sections:A description of a courses graded artifacts, defining both a number of points possible and a relative weight for each.A description of the Students in the course, listing a student ID, a grade option, and a name for each.A list of the raw scores received on each graded artifact by students in the course.A list of cutpoint sets, describing the total score required to receive an A, B, C, or D, respectively. (This project assumesthat there are no +/- Modifiers on grades, and that there are no other kinds of grades such as Incomplete, though we willsupport Pass/NotPass grades; see below.)Each section is described in more detail below.Graded artifactsThe section describing graded artifacts begins with a positive integer, alone on a line, specifying the number of gradedartifacts. This is followed, on another line, by a sequence of positive integers separated by spaces, indicating the total pointspossible on each graded artifact. Finally, on one more line, there will be a sequence of positive integers separated by spaces,indicating the relative weight of each graded artifact. An example of this section would be:715 15 15 15 15 50 5012 12 12 12 12 15 25This example describes seven graded artifacts, the first five having 15 points possible and relative weights of 12, the sixthhaving 50 points possible and a relative weight of 15, and the last having 50 points possible and a relative weight of 25. Notethat, in this example, the relative weights add up to 100; in general, however, this will not always be the case.StudentsThe next section of input describes the students enrolled in the course. It begins with a positive integer, alone on a line,specifying the number of students enrolled. Given that positive integer n, there will be n additional lines, each consisting of anon-negative integer student ID, followed by a space, followed by the students grade option (G for letter grade or P forPass/NotPass), followed by another space, followed by the students name. Every character on the line after the gradeoption and space is Considered to be part of the students name. (Its important to note that the space following the gradeoption is not part of a students name.) An example of this section would be:5123 G Alex Thornton234 G Boo Thornton345 G Jane Student456 P Joe Student567 G Too-Many CoursesStudent IDs do not necessarily have to be three digits, and they do not necessarily all have to be the same number of digits.Raw scoresThe next section of input describes the raw scores earned by students on each graded artifact. The section begins with apositive integer, alone on a line, specifying the number of students for which raw scores are listed. Given that positive integern, there will be n additional lines, each consisting of a sequence of non-negative integers separated by spaces, the first ofwhich is a student ID, And the rest of which are raw scores for each graded artifact. If there are m graded artifacts, you canassume each of these lines will contain m + 1 integers (one student ID, followed by m raw scores), and that the scorescorrespond, in order, to the graded artifacts listed in the first section. Example:5345 14 14 14 14 14 45 45123 13 10 8 14 12 50 37456 12 9 15 13 11 38 26234 15 15 15 15 15 50 50567 8 4 0 10 0 24 12It is possible for a student to be listed in the previous section but not to be listed in this section. In that case, assume that thestudents raw scores are all 0. It is also possible for a student to be listed in this section who does not appear in the previoussection; in that case, ignore the students raw scores, as the student is assumed to have dropped the course.It is also possible for a raw score to be higher than the number of points possible on a graded artifact. This is to be interpretedas extra credit, and fits into the formula below as-is.Cutpoint setsThe last section of input is the cutpoint sets. This section begins with a positive integer, alone on a line, specifying the numberof cutpoint sets. Given that positive integer n, the next n lines will consist of four non-negative numeric values (possiblyincluding a decimal point and additional digits) that specify, respectively, the total points required for an A, B, C, or D in thecourse. Example:390.0 80.0 70.0 60.085.0 75.0 65.0 55.080.0 70.0 60.0 50.0Note that these are not percentages, necessarily; they indicate a total number of points necessary this is described in moredetail later in this write-up.You may assume that Each of the cutpoint values can safely be read into a variable of type double, and that the cutpointvalues on each line will be non-ascending (e.g., the total points required for a higher grade like A will never be less than thetotal points required for a lower grade like B or C).A complete example inputA complete example input for the program follows. It should be possible to copy and paste this into a shell window, or to savethis into a file and use redirection to send the files contents into your program as input. Additionally, this exact input file isprovided in the project2 project template, so you should find a copy of it in your project directory in a directory called inputs.(You might want to create other test inputs and place them in that directory, as well. You absolutely should be testing yourprogram with inputs other than the provided one, as we will be when we grade it. However, we wont be providing additionaltest scenarios. Its up to developers of programs to develop their own tests; thats part of the job.)715 15 15 15 15 50 5012 12 12 12 12 15 255123 G Alex Thornton234 G Boo Thornton345 G Jane Student456 P Joe Student567 G Too-Many Courses5345 14 14 14 14 14 45 45123 13 10 8 14 12 50 37456 12 9 15 13 11 38 26234 15 15 15 15 15 50 50567 8 4 0 10 0 24 12390.0 80.0 70.0 60.085.0 75.0 65.0 55.080.0 70.0 60.0 50.0Note that there is nothing that explicitly separates one section of the input from the next, though you will always be able to tellfrom context (e.g., the number of graded artifacts, the number of students, etc.) where one section ends and the next begins.Other requirements about the inputThe program must not print prompts (e.g., Enter the number of students) or any other output except for what is specified inthe section titled The output below.It is reasonable for your program to assume that the programs input will always be structured as specified here. It is fine foryour program to misbehave or even crash if given input that does conform to these specifications.It is safe to Assume that all integers will be small enough that they will fit into an unsigned int or int variable (using the ICS45C VM and the tools were using on it, the largest value that would fit in both of these kinds of variables is 2,147,483,647).Calculating the total pointsThe programs output is largely determined by the total score earned by each student in the course. In order to complete theprogram, youll need to understand the correct formula to use.In the example input above, there are seven graded artifacts defined:1. 15 points possible, with a relative weight of 122. 15 points possible, with a relative weight of 123. 15 points possible, with a relative weight of 124. 15 points possible, with a relative weight of 125. 15 points possible, with a relative weight of 126. 50 points possible, with a relative weight of 157. 50 points possible, with a relative weight of 25From this example, we can see that simply adding together the raw scores on the various graded artifacts wont work,because, for example, artifact #6 is being graded on a 50-point scale, but is worth only slightly more, overall, than aritfact #5,which is being graded on a 15-point scale. Summing the raw scores would give too much weight to artifact #6. So well needto scale each of the raw scores, so that their relative weights are respected, then add the scaled scores together.The total relative weight of all graded artifacts in this example is 100, which means that the total score for each student willrange from 0.0 to 100.0. (It wont always be like this; we dont assume necessarily that all courses have a 100-point scale.) Wecalculate this by Multiplying the percentage of points earned on each graded artifact by its relative weight, then summing theresults. For example, suppose a student received these scores:The calculations would proceed as follows:1. (14 / 15) * 12 = 11.22. (13 / 15) * 12 = 10.43. (15 / 15) * 12 = 12.04. (12 / 15) * 12 = 9.65. (10 / 15) * 12 = 8.06. (40 / 50) * 15 = 12.07. (45 / 50) * 25 = 22.5Summing these together would yield a total of 11.2 + 10.4 + 12.0 + 9.6 + 8.0 + 12.0 + 22.5 = 85.7. So this students total scoreis 85.7 out of a possible 100.Scores that include extra credit (i.e., a raw score higher than the number of points possible on a graded artifact) do not needto be treated differently; they should be plugged into the formula the same way as any other.Negative raw scores are not permitted in the input, as described above, so they dont factor into this formula at all.Determining final course gradesThe final course grade for a student is determined by comparing the total score earned by that student to the cutpoints for anA, B, C, or D.If a students total score is greater than or equal to the A cutpoint, the students final course grade is AOtherwise, if a students total score is greater than or equal to the B cutpoint, the students final course grade is BOtherwise, if a students total score is greater than or equal to the C cutpoint, the students final course grade is COtherwise, if a students total score is greater than or equal to the D cutpoint, the students final course grade is DOtherwise, the Students final course grade is FNote that students whose grade option is P (Pass/NotPass) are handled a bit differently. In their case, determine what theirletter grade would have been (as described above) and then assign them one of these two grades:If the students letter Grade would have been A, B, or C, the students final course grade is P (i.e., passing)If the students letter grade would have been D or F, the students final course grade is NP (i.e., not passing)The outputWhile reading the input, there are specified points at which output will be generated and printed to the standard output (i.e.,std::cout). These are specified, along with the format of that output, below.Student rosterAfter reading the raw scores on all graded artifacts, but before reading the next section of the input, total scores are printed forall students. The format for this output is as follows:The words TOTAL SCORES, alone on a lineFor each student enrolled in the course, the student ID, followed by a space, followed by the students name, followedby a space, followed by the students total scoreExample:TOTAL SCORES123 Alex Thornton 79.1234 Boo Thornton 100345 Jane Student 92456 Joe Student 72.4567 Too-Many Courses 30.8It is not necessary to Format the total score to a particular number of decimal places, though you should not truncate it orround it to an integer. Whatever way the C++ iostream library formats a double value by default is fine here.Course gradesAfter reading each cutpoint set, but before reading the next part of the input, final course grades for that cutpoint set areprinted. For the purposes of this output, cutpoint sets are numbered consecutively starting from 1. The format of this output isas follows:The words CUTPOINT SET n, alone on a line, where n is replaced by the cutpoint set number (1 for the first cutpointset, 2 for the second, and so on)For each student enrolled in the course, the student ID, followed by a space, followed by the students name, followedby a space, followed by the students gradeExample:CUTPOINT SET 1123 Alex Thornton C234 Boo Thornton A345 Jane Student A456 Joe Student P567 Too-Many Courses FOutput timingDo not store all of the output in memory and print it to the standard output only at the end of the program. Instead, you will berequired to write output to the standard output at the points in time specified above.Output formattingYour output should be formatted exactly as specified above, including spacing, capitalization, spelling, and so on. Note that wewill be testing your programs in an automated fashion, so we will need these details to match the requirements precisely inorder for our tests not to fail.A complete example of the exact proper output for the provided sample input file will appear in your project directory in adirectory called outputs, in which youll find a file called sample.out.One more note about output format: As in previous projects, Ive indented the example inputs and outputs in this project writeupto set them apart from the text that surrounds them, but neither inputs nor outputs should be indented (e.g., the first line ofthe output should be TOTAL SCORES, alone on a line and not indented). The only way your output is allowed to differ fromours is in the number of digits after decimal places in students total scores, which is fine, so long as all of your total scores arewithin 0.1% of what we expect in every case (which is more than enough of a buffer to account for inaccuracies introduced bythe use of floating-point types like float or double).A complete example of program executionThe following is a Complete example of program execution from the Linux shell, demonstrating how input and output areinterleaved. Input is shown in a regular font weight; output is shown in bold.715 15 15 15 15 50 5012 12 12 12 12 15 255123 G Alex Thornton234 G Boo Thornton345 G Jane Student456 P Joe Student567 G Too-Many Courses5345 14 14 14 14 14 45 45123 13 10 8 14 12 50 37456 12 9 15 13 11 38 26234 15 15 15 15 15 50 50567 8 4 0 10 0 24 12TOTAL SCORES123 Alex Thornton 79.1234 Boo Thornton 100345 Jane Student 92456 Joe Student 72.4567 Too-Many Courses 30.8390.0 80.0 70.0 60.0CUTPOINT SET 1123 Alex Thornton C234 Boo Thornton A345 Jane Student A456 Joe Student P567 Too-Many Courses F85.0 75.0 65.0 55.0CUTPOINT SET 2123 Alex Thornton B234 Boo Thornton A345 Jane Student A456 Joe Student P567 Too-Many Courses F80.0 70.0 60.0 50.0CUTPOINT SET 3123 Alex Thornton B234 Boo Thornton A345 Jane Student A456 Joe Student P567 Too-Many Courses FSome rules and limitationsBecause were beginning our exploration of C++ by building our knowledge from some of its lowest-level abstractions, thereare some fairly strict limitations on what features of the language youll be permitted to use in this project. Those limitations willlift quickly as we move forward this quarter, so dont be concerned that youll always be put into a tiny box, but this project hassome very particular goals. If you have prior experience with C++, you may find that there are other techniques that youdprefer to use and its quite Possible that youre right that theyd be better techniques, in general but youll need to stickwith whats allowed this time, because there are particular learning objectives here.Here are the rules and limitations governing your work on this project.Other than iostream, sstream, and string which youll need for processing input and generating output you arenot permitted to include any C or C++ standard library headers in your program. Aside from standard input/output(using, for example, std::cin, std::cout, and std::endl), the std::string class, and stringstreams (std::istringstreamand std::ostringstream), the standard library is off-limits (e.g., you cannot use collections like std::vector).Use arrays to store and Manipulate data within your program. Note, too, that you wont know the correct sizes for thesearrays at compile time (because the sizes are specified in the programs input), so you will find that you need to usedynamically-allocated arrays extensively.You are permitted to use structs (in the C sense, i.e., implicitly public member variables with no member functions,constructors, destructors, etc.), but classes are off-limits until the next project, as our exploration of object-orientedtechniques still lies ahead of us.Even though this is what you might call a batch mode program (i.e., it reads input, processes it, generates output, andthen ends), you are still required to explicitly delete any memory that you dynamically allocate using new before theprogram ends. This is a Habit that is vital to build in C++, so this will always be a requirement in this course. (While thesymptoms of leaking memory are often invisible, well use tools in this course to make them visible; more about thatbelow.)From a design perspective, you are again required to break large functions into smaller ones (where each has a single,straightforward responsibility), and to arrange your functions into multiple source files (where each source file encompasses aset of strongly related functions). Any source file that needs to export things (e.g., functions) to other source files should alsoinclude its own separate header file.Redirection (or, How to avoid re-typing the input every time you run your program)When you use the run script to execute your program and, generally, by default in Linux the standard input and standardoutput are connected to the shell window where you executed the program. The programs input is typed into that shellwindow; the programs output is written to that shell window.However, you can also use a technique called redirection to connect the standard input and/or standard output to otherdevices most importantly for us, to files! instead of the default. For example, the contents of an existing file may beredirected into the standard Input, so that your program will read its input from the file instead of from the shell window;similarly, the standard output can be redirected into a file, meaning that all of the output printed to std::cout will be saved intothat file, rather than being displayed in the shell window.The typical mechanism for redirection is to use the and operators on the command line, like this:SomeProgramYouWantToRun FileContainingStdInput.txt FileToStoreStdOutput.txtYou dont have to use both; you can use only (in which case the standard input is read from a file, but the standard output iswritten to the shell window) or only (in which case the standard input is read from the shell window, but the standard outputis written to a file). Its up to you.Using redirection to avoid re-typing test inputThis can be a handy technique to use in your testing, to avoid the problem of having to re-type the programs input every timeyou run it. If you used the project2 project template and you should have! when creating your project, you should see adirectory called inputs in your project directory; in the inputs directory, you should see a file sample.in, which contains thesample input from this project write-up. If you want to run your program using the same input, issue this command (from yourproject directory):./run inputs/sample.inThe effect is that the contents of the sample.in file in the inputs directory will be redirected into your programs standardinput, in lieu of you having to type it. You might also want to write other test files for yourself in that same inputs directory,then use a similar technique to redirect them into the standard input of your program. You can avoid a lot of re-typing this way!A note about output timingNote that the redirection technique will not give you an accurate view of whether your program is printing the right output atthe right times, as specified in the requirements above, but it will tell you whether your program is generating the correctanswer. You can enter the input manually sometimes when you want to test the timing of the output.Using Valgrind (Memcheck) to check your memory usageThe ICS 45C VM includes a program called Valgrind, which is used for detecting a variety of difficult-to-find problems in C andC++ programs. It Consists of a set of tools, each of which detects a certain kind of problem. For our work here, well beinterested in a tool in Valgrind called Memcheck, which watches a program while it runs and carefully tracks the way it usesmemory, looking for a variety of mistakes that might otherwise be silent bugs and makes them visible.A detailed look at Memcheck can be found in the Illuminating the Dark Corners notes; I suggest that you take a look at thoseand use Memcheck to work through issues in this project (and subsequent ones) while you work.Running your program using MemcheckThe usual run script, which you use to run your program after building it, has an option that lets you run the program usingMemcheck. If you run your program with this command:./run –memcheckthen Memcheck will observe your program as it runs and report its findings. Youd type in the input as usual and would see theoutput appear as usual, but Memchecks preamble will be displayed when your program starts, its final report will be displayedwhen your program ends, and you may see additional warnings while the program runs.Note, too, that you can combine this with redirection:./run –memcheck inputs/sample.inif you want to run the program with Memcheck but avoid typing the input by hand.We will be running your program using Memcheck as part of the grading process, and expect it to generate a clean report(i.e., no memory leaks and no memory-related issues while the program runs, other than the things that we intentionallysuppressed) to receive full credit, so youd be well-served to use Memcheck periodically as you work, and to fix issues as theyarise.DeliverablesAfter using the gather script in your project directory to gather up your C++ source and header files into a singleproject2.tar.gz file, submit that file (and only that file!) to Checkmate.Follow this link for a discussion of how to submit your project via Checkmate. Be aware that Ill be holding you to all of therules specified in that document, including the one that says that youre responsible for submitting the version of the projectthat you want graded. We wont regrade a project simply because you submitted the wrong version accidentally. (Its not a badidea to look at the contents of Your tarball on your host operating system before submitting it.)Can I submit after the deadline?Yes, it is possible, subject to the late work policy for this course which is described in the section titled Late work at this link.Clarifications about Memcheck and supppression of reporting added by Alex Thornton, Fall 2016.Additional clarifications and requirement tweaks by Alex Thornton, Fall 2015.Some tweaks to Requirements and some additional clarifications by Alex Thornton, Fall 2014.A few clarifications added by Alex Thornton, Winter 2014.Requirements tweaked and reorganized for ICS 45C VM by Alex Thornton, Fall 2013.Originally written by Alex Thornton, Fall 2012.如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。